Commit 64985505 authored by Alex Brainman's avatar Alex Brainman

cmd/link: introduce peFile.ctorsSect and use it in peFile.emitRelocations

Change-Id: I65058c150a19aa4e3083fd8754d08ea23721844b
Reviewed-on: https://go-review.googlesource.com/59420Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 3558c16d
...@@ -472,6 +472,7 @@ type peFile struct { ...@@ -472,6 +472,7 @@ type peFile struct {
textSect *peSection textSect *peSection
dataSect *peSection dataSect *peSection
bssSect *peSection bssSect *peSection
ctorsSect *peSection
nextSectOffset uint32 nextSectOffset uint32
nextFileOffset uint32 nextFileOffset uint32
} }
...@@ -549,12 +550,12 @@ func (f *peFile) addInitArray(ctxt *Link) *peSection { ...@@ -549,12 +550,12 @@ func (f *peFile) addInitArray(ctxt *Link) *peSection {
} }
// emitRelocations emits relocation entries for go.o in external linking. // emitRelocations emits relocation entries for go.o in external linking.
func (f *peFile) emitRelocations(ctxt *Link, text, data, ctors *peSection) { func (f *peFile) emitRelocations(ctxt *Link) {
for coutbuf.Offset()&7 != 0 { for coutbuf.Offset()&7 != 0 {
Cput(0) Cput(0)
} }
text.emitRelocations(func() int { f.textSect.emitRelocations(func() int {
n := perelocsect(ctxt, Segtext.Sections[0], ctxt.Textp, Segtext.Vaddr) n := perelocsect(ctxt, Segtext.Sections[0], ctxt.Textp, Segtext.Vaddr)
for _, sect := range Segtext.Sections[1:] { for _, sect := range Segtext.Sections[1:] {
n += perelocsect(ctxt, sect, datap, Segtext.Vaddr) n += perelocsect(ctxt, sect, datap, Segtext.Vaddr)
...@@ -562,7 +563,7 @@ func (f *peFile) emitRelocations(ctxt *Link, text, data, ctors *peSection) { ...@@ -562,7 +563,7 @@ func (f *peFile) emitRelocations(ctxt *Link, text, data, ctors *peSection) {
return n return n
}) })
data.emitRelocations(func() int { f.dataSect.emitRelocations(func() int {
var n int var n int
for _, sect := range Segdata.Sections { for _, sect := range Segdata.Sections {
n += perelocsect(ctxt, sect, datap, Segdata.Vaddr) n += perelocsect(ctxt, sect, datap, Segdata.Vaddr)
...@@ -583,7 +584,7 @@ dwarfLoop: ...@@ -583,7 +584,7 @@ dwarfLoop:
Errorf(nil, "emitRelocations: could not find %q section", sect.Name) Errorf(nil, "emitRelocations: could not find %q section", sect.Name)
} }
ctors.emitRelocations(func() int { f.ctorsSect.emitRelocations(func() int {
dottext := ctxt.Syms.Lookup(".text", 0) dottext := ctxt.Syms.Lookup(".text", 0)
Lputl(0) Lputl(0)
Lputl(uint32(dottext.Dynid)) Lputl(uint32(dottext.Dynid))
...@@ -1223,7 +1224,6 @@ func Asmbpe(ctxt *Link) { ...@@ -1223,7 +1224,6 @@ func Asmbpe(ctxt *Link) {
pefile.textSect = t pefile.textSect = t
var d *peSection var d *peSection
var c *peSection
if Linkmode != LinkExternal { if Linkmode != LinkExternal {
d = pefile.addSection(".data", int(Segdata.Length), int(Segdata.Filelen)) d = pefile.addSection(".data", int(Segdata.Length), int(Segdata.Filelen))
d.Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE d.Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE
...@@ -1246,7 +1246,7 @@ func Asmbpe(ctxt *Link) { ...@@ -1246,7 +1246,7 @@ func Asmbpe(ctxt *Link) {
} }
if Linkmode == LinkExternal { if Linkmode == LinkExternal {
c = pefile.addInitArray(ctxt) pefile.ctorsSect = pefile.addInitArray(ctxt)
} }
Cseek(int64(pefile.nextFileOffset)) Cseek(int64(pefile.nextFileOffset))
...@@ -1257,7 +1257,7 @@ func Asmbpe(ctxt *Link) { ...@@ -1257,7 +1257,7 @@ func Asmbpe(ctxt *Link) {
addpesymtable(ctxt) addpesymtable(ctxt)
addpersrc(ctxt) addpersrc(ctxt)
if Linkmode == LinkExternal { if Linkmode == LinkExternal {
pefile.emitRelocations(ctxt, t, d, c) pefile.emitRelocations(ctxt)
} }
fh.NumberOfSections = uint16(len(pefile.sections)) fh.NumberOfSections = uint16(len(pefile.sections))
......
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