From 64985505b001862b22368ef88746641a0d95cace Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Mon, 28 Aug 2017 13:18:03 +1000 Subject: [PATCH] cmd/link: introduce peFile.ctorsSect and use it in peFile.emitRelocations Change-Id: I65058c150a19aa4e3083fd8754d08ea23721844b Reviewed-on: https://go-review.googlesource.com/59420 Reviewed-by: Ian Lance Taylor --- src/cmd/link/internal/ld/pe.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cmd/link/internal/ld/pe.go b/src/cmd/link/internal/ld/pe.go index b92885333b..743efb07f2 100644 --- a/src/cmd/link/internal/ld/pe.go +++ b/src/cmd/link/internal/ld/pe.go @@ -472,6 +472,7 @@ type peFile struct { textSect *peSection dataSect *peSection bssSect *peSection + ctorsSect *peSection nextSectOffset uint32 nextFileOffset uint32 } @@ -549,12 +550,12 @@ func (f *peFile) addInitArray(ctxt *Link) *peSection { } // 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 { Cput(0) } - text.emitRelocations(func() int { + f.textSect.emitRelocations(func() int { n := perelocsect(ctxt, Segtext.Sections[0], ctxt.Textp, Segtext.Vaddr) for _, sect := range Segtext.Sections[1:] { n += perelocsect(ctxt, sect, datap, Segtext.Vaddr) @@ -562,7 +563,7 @@ func (f *peFile) emitRelocations(ctxt *Link, text, data, ctors *peSection) { return n }) - data.emitRelocations(func() int { + f.dataSect.emitRelocations(func() int { var n int for _, sect := range Segdata.Sections { n += perelocsect(ctxt, sect, datap, Segdata.Vaddr) @@ -583,7 +584,7 @@ dwarfLoop: 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) Lputl(0) Lputl(uint32(dottext.Dynid)) @@ -1223,7 +1224,6 @@ func Asmbpe(ctxt *Link) { pefile.textSect = t var d *peSection - var c *peSection if Linkmode != LinkExternal { 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 @@ -1246,7 +1246,7 @@ func Asmbpe(ctxt *Link) { } if Linkmode == LinkExternal { - c = pefile.addInitArray(ctxt) + pefile.ctorsSect = pefile.addInitArray(ctxt) } Cseek(int64(pefile.nextFileOffset)) @@ -1257,7 +1257,7 @@ func Asmbpe(ctxt *Link) { addpesymtable(ctxt) addpersrc(ctxt) if Linkmode == LinkExternal { - pefile.emitRelocations(ctxt, t, d, c) + pefile.emitRelocations(ctxt) } fh.NumberOfSections = uint16(len(pefile.sections)) -- 2.51.0