]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: introduce and use peFile.nextSectOffset and nextFileOffset
authorAlex Brainman <alex.brainman@gmail.com>
Mon, 5 Jun 2017 06:10:49 +0000 (16:10 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Mon, 21 Aug 2017 02:08:54 +0000 (02:08 +0000)
Change-Id: Iecff99e85e2cca1127dca79747bb0d5362cd4125
Reviewed-on: https://go-review.googlesource.com/56319
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/link/internal/ld/pe.go

index c7788d84af9f37e92738b46c81308cfd639a9c7b..affb76223de78ece2d600e1ba78f587fc280f0c4 100644 (file)
@@ -322,10 +322,6 @@ var PEFILEHEADR int32
 
 var pe64 int
 
-var nextsectoff int
-
-var nextfileoff int
-
 var fh IMAGE_FILE_HEADER
 
 var oh IMAGE_OPTIONAL_HEADER
@@ -446,11 +442,13 @@ func (sect *peSection) write() error {
 
 // peFile is used to build COFF file.
 type peFile struct {
-       sections    []*peSection
-       stringTable peStringTable
-       textSect    *peSection
-       dataSect    *peSection
-       bssSect     *peSection
+       sections       []*peSection
+       stringTable    peStringTable
+       textSect       *peSection
+       dataSect       *peSection
+       bssSect        *peSection
+       nextSectOffset uint32
+       nextFileOffset uint32
 }
 
 // addSection adds section to the COFF file f.
@@ -460,13 +458,13 @@ func (f *peFile) addSection(name string, sectsize int, filesize int) *peSection
                shortName:        name,
                index:            len(f.sections) + 1,
                VirtualSize:      uint32(sectsize),
-               VirtualAddress:   uint32(nextsectoff),
-               PointerToRawData: uint32(nextfileoff),
+               VirtualAddress:   f.nextSectOffset,
+               PointerToRawData: f.nextFileOffset,
        }
-       nextsectoff = int(Rnd(int64(nextsectoff)+int64(sectsize), PESECTALIGN))
+       f.nextSectOffset = uint32(Rnd(int64(f.nextSectOffset)+int64(sectsize), PESECTALIGN))
        if filesize > 0 {
                sect.SizeOfRawData = uint32(Rnd(int64(filesize), PEFILEALIGN))
-               nextfileoff += int(sect.SizeOfRawData)
+               f.nextFileOffset += sect.SizeOfRawData
        }
        f.sections = append(f.sections, sect)
        return sect
@@ -524,8 +522,8 @@ func Peinit(ctxt *Link) {
        } else {
                PESECTHEADR = 0
        }
-       nextsectoff = int(PESECTHEADR)
-       nextfileoff = int(PEFILEHEADR)
+       pefile.nextSectOffset = uint32(PESECTHEADR)
+       pefile.nextFileOffset = uint32(PEFILEHEADR)
 
        if Linkmode == LinkInternal {
                // some mingw libs depend on this symbol, for example, FindPESectionByName
@@ -695,7 +693,7 @@ func addimports(ctxt *Link, datsect *peSection) {
        var m *Imp
        for d := dr; d != nil; d = d.next {
                for m = d.ms; m != nil; m = m.next {
-                       m.off = uint64(nextsectoff) + uint64(coutbuf.Offset()) - uint64(startoff)
+                       m.off = uint64(pefile.nextSectOffset) + uint64(coutbuf.Offset()) - uint64(startoff)
                        Wputl(0) // hint
                        strput(m.s.Extname)
                }
@@ -1255,7 +1253,7 @@ func Asmbpe(ctxt *Link) {
                c = addinitarray(ctxt)
        }
 
-       Cseek(int64(nextfileoff))
+       Cseek(int64(pefile.nextFileOffset))
        if Linkmode != LinkExternal {
                addimports(ctxt, d)
                addexports(ctxt)
@@ -1324,8 +1322,8 @@ func Asmbpe(ctxt *Link) {
        oh.MajorSubsystemVersion = 4
        oh64.MinorSubsystemVersion = 0
        oh.MinorSubsystemVersion = 0
-       oh64.SizeOfImage = uint32(nextsectoff)
-       oh.SizeOfImage = uint32(nextsectoff)
+       oh64.SizeOfImage = pefile.nextSectOffset
+       oh.SizeOfImage = pefile.nextSectOffset
        oh64.SizeOfHeaders = uint32(PEFILEHEADR)
        oh.SizeOfHeaders = uint32(PEFILEHEADR)
        if windowsgui {