]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: introduce and use peSection.pad
authorAlex Brainman <alex.brainman@gmail.com>
Mon, 5 Jun 2017 05:40:32 +0000 (15:40 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Mon, 21 Aug 2017 02:06:06 +0000 (02:06 +0000)
Change-Id: I068e9bb6e692b5eff193ddb46af3f04785f98518
Reviewed-on: https://go-review.googlesource.com/56316
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/link/internal/ld/pe.go

index 71fc7a19f9eca6c3e1f943531ea4dda4a025b2d8..6384711f6d6628330c90b90c1e3bb1bbbcaec49b 100644 (file)
@@ -428,6 +428,13 @@ func (sect *peSection) checkSegment(seg *Segment) {
        }
 }
 
+// pad adds zeros to the section sect. It writes as many bytes
+// as necessary to make section sect.SizeOfRawData bytes long.
+// It assumes that n bytes are already written to the file.
+func (sect *peSection) pad(n uint32) {
+       strnput("", int(sect.SizeOfRawData-n))
+}
+
 // write writes COFF section sect into the output file.
 func (sect *peSection) write() error {
        h := pe.SectionHeader32{
@@ -727,7 +734,7 @@ func addimports(ctxt *Link, datsect *peSection) {
        isect := pefile.addSection(".idata", int(n), int(n))
        isect.Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE
        isect.checkOffset(startoff)
-       strnput("", int(uint64(isect.SizeOfRawData)-n))
+       isect.pad(uint32(n))
        endoff := coutbuf.Offset()
 
        // write FirstThunks (allocated in .data section)
@@ -861,7 +868,7 @@ func addexports(ctxt *Link) {
        for i := 0; i < nexport; i++ {
                strnput(dexport[i].Extname, len(dexport[i].Extname)+1)
        }
-       strnput("", int(sect.SizeOfRawData-uint32(size)))
+       sect.pad(uint32(size))
 }
 
 // perelocsect relocates symbols from first in section sect, and returns
@@ -1124,7 +1131,7 @@ func addpesymtable(ctxt *Link) {
        // write COFF string table
        pefile.stringTable.write()
        if Linkmode != LinkExternal {
-               strnput("", int(h.SizeOfRawData-uint32(size)))
+               h.pad(uint32(size))
        }
 }
 
@@ -1163,7 +1170,7 @@ func addpersrc(ctxt *Link) {
        }
 
        Cwrite(rsrcsym.P)
-       strnput("", int(int64(h.SizeOfRawData)-rsrcsym.Size))
+       h.pad(uint32(rsrcsym.Size))
 
        // update data directory
        dd[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress = h.VirtualAddress