Commit fe1ccc5b authored by Alex Brainman's avatar Alex Brainman

cmd/link: introduce and use peFile.writeSymbolTableAndStringTable

Change-Id: I506f5e146f3b5bf359d6932a85ac5572d3a3f103
Reviewed-on: https://go-review.googlesource.com/59426Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 2034297b
...@@ -754,6 +754,35 @@ func (f *peFile) writeSymbols(ctxt *Link) { ...@@ -754,6 +754,35 @@ func (f *peFile) writeSymbols(ctxt *Link) {
genasmsym(ctxt, put) genasmsym(ctxt, put)
} }
// writeSymbolTableAndStringTable writes out symbol and string tables for peFile f.
func (f *peFile) writeSymbolTableAndStringTable(ctxt *Link) {
symtabStartPos := coutbuf.Offset()
// write COFF symbol table
if !*FlagS || Linkmode == LinkExternal {
f.writeSymbols(ctxt)
}
// update COFF file header and section table
size := f.stringTable.size() + 18*f.symbolCount
var h *peSection
if Linkmode != LinkExternal {
// We do not really need .symtab for go.o, and if we have one, ld
// will also include it in the exe, and that will confuse windows.
h = f.addSection(".symtab", size, size)
h.Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE
h.checkOffset(symtabStartPos)
}
fh.PointerToSymbolTable = uint32(symtabStartPos)
fh.NumberOfSymbols = uint32(f.symbolCount)
// write COFF string table
f.stringTable.write()
if Linkmode != LinkExternal {
h.pad(uint32(size))
}
}
var pefile peFile var pefile peFile
func Peinit(ctxt *Link) { func Peinit(ctxt *Link) {
...@@ -1138,34 +1167,6 @@ func (ctxt *Link) dope() { ...@@ -1138,34 +1167,6 @@ func (ctxt *Link) dope() {
initdynexport(ctxt) initdynexport(ctxt)
} }
func addpesymtable(ctxt *Link) {
symtabStartPos := coutbuf.Offset()
// write COFF symbol table
if !*FlagS || Linkmode == LinkExternal {
pefile.writeSymbols(ctxt)
}
// update COFF file header and section table
size := pefile.stringTable.size() + 18*pefile.symbolCount
var h *peSection
if Linkmode != LinkExternal {
// We do not really need .symtab for go.o, and if we have one, ld
// will also include it in the exe, and that will confuse windows.
h = pefile.addSection(".symtab", size, size)
h.Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE
h.checkOffset(symtabStartPos)
}
fh.PointerToSymbolTable = uint32(symtabStartPos)
fh.NumberOfSymbols = uint32(pefile.symbolCount)
// write COFF string table
pefile.stringTable.write()
if Linkmode != LinkExternal {
h.pad(uint32(size))
}
}
func setpersrc(ctxt *Link, sym *Symbol) { func setpersrc(ctxt *Link, sym *Symbol) {
if rsrcsym != nil { if rsrcsym != nil {
Errorf(sym, "too many .rsrc sections") Errorf(sym, "too many .rsrc sections")
...@@ -1260,7 +1261,7 @@ func Asmbpe(ctxt *Link) { ...@@ -1260,7 +1261,7 @@ func Asmbpe(ctxt *Link) {
addimports(ctxt, d) addimports(ctxt, d)
addexports(ctxt) addexports(ctxt)
} }
addpesymtable(ctxt) pefile.writeSymbolTableAndStringTable(ctxt)
addpersrc(ctxt) addpersrc(ctxt)
if Linkmode == LinkExternal { if Linkmode == LinkExternal {
pefile.emitRelocations(ctxt) pefile.emitRelocations(ctxt)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment