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

index 18248e0943b118b28785654e598f9072bf617909..960fdd1d55be8d7c4dd864cbd3d915b884c64814 100644 (file)
@@ -407,6 +407,14 @@ type peSection struct {
        Characteristics      uint32
 }
 
+// checkOffset verifies COFF section sect offset in the file.
+func (sect *peSection) checkOffset(off int64) {
+       if off != int64(sect.PointerToRawData) {
+               Errorf(nil, "%s.PointerToRawData = %#x, want %#x", sect.name, uint64(int64(sect.PointerToRawData)), uint64(off))
+               errorexit()
+       }
+}
+
 // write writes COFF section sect into the output file.
 func (sect *peSection) write() error {
        h := pe.SectionHeader32{
@@ -472,13 +480,6 @@ func (f *peFile) addDWARFSection(name string, size int) *peSection {
 
 var pefile peFile
 
-func chksectoff(ctxt *Link, h *peSection, off int64) {
-       if off != int64(h.PointerToRawData) {
-               Errorf(nil, "%s.PointerToRawData = %#x, want %#x", h.name, uint64(int64(h.PointerToRawData)), uint64(off))
-               errorexit()
-       }
-}
-
 func chksectseg(ctxt *Link, h *peSection, s *Segment) {
        if s.Vaddr-PEBASE != uint64(h.VirtualAddress) {
                Errorf(nil, "%s.VirtualAddress = %#x, want %#x", h.name, uint64(int64(h.VirtualAddress)), uint64(int64(s.Vaddr-PEBASE)))
@@ -724,7 +725,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
-       chksectoff(ctxt, isect, startoff)
+       isect.checkOffset(startoff)
        strnput("", int(uint64(isect.SizeOfRawData)-n))
        endoff := coutbuf.Offset()
 
@@ -812,7 +813,7 @@ func addexports(ctxt *Link) {
 
        sect := pefile.addSection(".edata", size, size)
        sect.Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
-       chksectoff(ctxt, sect, coutbuf.Offset())
+       sect.checkOffset(coutbuf.Offset())
        va := int(sect.VirtualAddress)
        dd[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress = uint32(va)
        dd[IMAGE_DIRECTORY_ENTRY_EXPORT].Size = sect.VirtualSize
@@ -1114,7 +1115,7 @@ func addpesymtable(ctxt *Link) {
                // will also include it in the exe, and that will confuse windows.
                h = pefile.addSection(".symtab", size, size)
                h.Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE
-               chksectoff(ctxt, h, symtabStartPos)
+               h.checkOffset(symtabStartPos)
        }
        fh.PointerToSymbolTable = uint32(symtabStartPos)
        fh.NumberOfSymbols = uint32(symcnt)
@@ -1141,7 +1142,7 @@ func addpersrc(ctxt *Link) {
 
        h := pefile.addSection(".rsrc", int(rsrcsym.Size), int(rsrcsym.Size))
        h.Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_CNT_INITIALIZED_DATA
-       chksectoff(ctxt, h, coutbuf.Offset())
+       h.checkOffset(coutbuf.Offset())
 
        // relocation
        var p []byte
@@ -1191,7 +1192,7 @@ func addinitarray(ctxt *Link) (c *peSection) {
        c.SizeOfRawData = uint32(size)
 
        Cseek(int64(c.PointerToRawData))
-       chksectoff(ctxt, c, coutbuf.Offset())
+       c.checkOffset(coutbuf.Offset())
        init_entry := ctxt.Syms.Lookup(*flagEntrySymbol, 0)
        addr := uint64(init_entry.Value) - init_entry.Sect.Vaddr