From 97246527e8cb814f65b04a35c0c3d6c88398633d Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Mon, 5 Jun 2017 15:51:26 +1000 Subject: [PATCH] cmd/link: introduce and use peFile.textSect, dataSect and bssSect Change-Id: I6a1d33a759deaa4788bafb1c288d9b0e2fe3b026 Reviewed-on: https://go-review.googlesource.com/56317 Reviewed-by: Ian Lance Taylor --- src/cmd/link/internal/ld/pe.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/cmd/link/internal/ld/pe.go b/src/cmd/link/internal/ld/pe.go index 6384711f6d..9a632f74b6 100644 --- a/src/cmd/link/internal/ld/pe.go +++ b/src/cmd/link/internal/ld/pe.go @@ -328,12 +328,6 @@ var nextsectoff int var nextfileoff int -var textsect int - -var datasect int - -var bsssect int - var fh IMAGE_FILE_HEADER var oh IMAGE_OPTIONAL_HEADER @@ -456,6 +450,9 @@ func (sect *peSection) write() error { type peFile struct { sections []*peSection stringTable peStringTable + textSect *peSection + dataSect *peSection + bssSect *peSection } // addSection adds section to the COFF file f. @@ -1066,14 +1063,14 @@ func writePESymTableRecords(ctxt *Link) int { // it still belongs to the .data section, not the .bss section. if uint64(s.Value) >= Segdata.Vaddr+Segdata.Filelen && s.Type != SDATA && Linkmode == LinkExternal { value = int64(uint64(s.Value) - Segdata.Vaddr - Segdata.Filelen) - sect = bsssect + sect = pefile.bssSect.index } else { value = int64(uint64(s.Value) - Segdata.Vaddr) - sect = datasect + sect = pefile.dataSect.index } } else if s.Sect != nil && s.Sect.Seg == &Segtext { value = int64(uint64(s.Value) - Segtext.Vaddr) - sect = textsect + sect = pefile.textSect.index } else if type_ == UndefinedSym { typ = IMAGE_SYM_DTYPE_FUNCTION } else { @@ -1232,7 +1229,7 @@ func Asmbpe(ctxt *Link) { t.Characteristics |= IMAGE_SCN_ALIGN_32BYTES } t.checkSegment(&Segtext) - textsect = pensect + pefile.textSect = t var d *peSection var c *peSection @@ -1240,17 +1237,17 @@ func Asmbpe(ctxt *Link) { 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.checkSegment(&Segdata) - datasect = pensect + pefile.dataSect = d } else { d = pefile.addSection(".data", int(Segdata.Filelen), int(Segdata.Filelen)) d.Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_ALIGN_32BYTES d.checkSegment(&Segdata) - datasect = pensect + pefile.dataSect = d b := pefile.addSection(".bss", int(Segdata.Length-Segdata.Filelen), 0) b.Characteristics = IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_ALIGN_32BYTES b.PointerToRawData = 0 - bsssect = pensect + pefile.bssSect = b } if !*FlagS {