]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: write dwarf relocations
authorAlex Brainman <alex.brainman@gmail.com>
Wed, 8 Feb 2017 01:30:30 +0000 (12:30 +1100)
committerAlex Brainman <alex.brainman@gmail.com>
Wed, 1 Mar 2017 04:49:29 +0000 (04:49 +0000)
For #10776.

Change-Id: I11dd441d8e5d6316889ffa8418df8b58c57c677d
Reviewed-on: https://go-review.googlesource.com/36982
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/link/internal/amd64/asm.go
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/pe.go
src/cmd/link/internal/x86/asm.go

index 60bd45cd30b667fd289c1aaf9480aa152636c791..c1d8339f4b6c4f157f1e920faf5270650de3b312 100644 (file)
@@ -500,6 +500,9 @@ func pereloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
        default:
                return false
 
+       case obj.R_DWARFREF:
+               v = ld.IMAGE_REL_AMD64_SECREL
+
        case obj.R_ADDR:
                if r.Siz == 8 {
                        v = ld.IMAGE_REL_AMD64_ADDR64
index 582a68ea0820441d87b5da7631e968f03e019e1b..2ce193570fa0ea10583f2cbe2acb7c4e32e10da7 100644 (file)
@@ -575,7 +575,14 @@ func relocsym(ctxt *Link, s *Symbol) {
                        }
                        if Linkmode == LinkExternal {
                                r.Done = 0
-                               r.Type = obj.R_ADDR
+                               // PE code emits IMAGE_REL_I386_SECREL and IMAGE_REL_AMD64_SECREL
+                               // for R_DWARFREF relocations, while R_ADDR is replaced with
+                               // IMAGE_REL_I386_DIR32, IMAGE_REL_AMD64_ADDR64 and IMAGE_REL_AMD64_ADDR32.
+                               // Do not replace R_DWARFREF with R_ADDR for windows -
+                               // let PE code emit correct relocations.
+                               if Headtype != obj.Hwindows && Headtype != obj.Hwindowsgui {
+                                       r.Type = obj.R_ADDR
+                               }
 
                                r.Xsym = ctxt.Syms.ROLookup(r.Sym.Sect.Name, 0)
                                r.Xadd = r.Add + Symaddr(r.Sym) - int64(r.Sym.Sect.Vaddr)
index f1d51caa90609bdcd966b55c2f404ad3049de725..77c86fecbd86ff6edc11a4382fdccc7d19119e11 100644 (file)
@@ -801,7 +801,7 @@ func addexports(ctxt *Link) {
 
 // perelocsect relocates symbols from first in section sect, and returns
 // the total number of relocations emitted.
-func perelocsect(ctxt *Link, sect *Section, syms []*Symbol) int {
+func perelocsect(ctxt *Link, sect *Section, syms []*Symbol, base uint64) int {
        // If main section has no bits, nothing to relocate.
        if sect.Vaddr >= sect.Seg.Vaddr+sect.Seg.Filelen {
                return 0
@@ -841,7 +841,7 @@ func perelocsect(ctxt *Link, sect *Section, syms []*Symbol) int {
                        if r.Xsym.Dynid < 0 {
                                Errorf(sym, "reloc %d to non-coff symbol %s (outer=%s) %d", r.Type, r.Sym.Name, r.Xsym.Name, r.Sym.Type)
                        }
-                       if !Thearch.PEreloc1(sym, r, int64(uint64(sym.Value+int64(r.Off))-sect.Seg.Vaddr)) {
+                       if !Thearch.PEreloc1(sym, r, int64(uint64(sym.Value+int64(r.Off))-base)) {
                                Errorf(sym, "unsupported obj reloc %d/%d to %s", r.Type, r.Siz, r.Sym.Name)
                        }
 
@@ -887,9 +887,9 @@ func peemitreloc(ctxt *Link, text, data, ctors *IMAGE_SECTION_HEADER) {
        }
 
        peemitsectreloc(text, func() int {
-               n := perelocsect(ctxt, Segtext.Sect, ctxt.Textp)
+               n := perelocsect(ctxt, Segtext.Sect, ctxt.Textp, Segtext.Vaddr)
                for sect := Segtext.Sect.Next; sect != nil; sect = sect.Next {
-                       n += perelocsect(ctxt, sect, datap)
+                       n += perelocsect(ctxt, sect, datap, Segtext.Vaddr)
                }
                return n
        })
@@ -897,11 +897,24 @@ func peemitreloc(ctxt *Link, text, data, ctors *IMAGE_SECTION_HEADER) {
        peemitsectreloc(data, func() int {
                var n int
                for sect := Segdata.Sect; sect != nil; sect = sect.Next {
-                       n += perelocsect(ctxt, sect, datap)
+                       n += perelocsect(ctxt, sect, datap, Segdata.Vaddr)
                }
                return n
        })
 
+dwarfLoop:
+       for sect := Segdwarf.Sect; sect != nil; sect = sect.Next {
+               for i, name := range shNames {
+                       if sect.Name == name {
+                               peemitsectreloc(&sh[i], func() int {
+                                       return perelocsect(ctxt, sect, dwarfp, sect.Vaddr)
+                               })
+                               continue dwarfLoop
+                       }
+               }
+               Errorf(nil, "peemitsectreloc: could not find %q section", sect.Name)
+       }
+
        peemitsectreloc(ctors, func() int {
                dottext := ctxt.Syms.Lookup(".text", 0)
                Lputl(0)
index af702c29d0759ba9b750f3cc28f8f14b3f4ea5a7..e49b07c368311dc3890e9e791c2095c50d31d391 100644 (file)
@@ -482,6 +482,9 @@ func pereloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
        default:
                return false
 
+       case obj.R_DWARFREF:
+               v = ld.IMAGE_REL_I386_SECREL
+
        case obj.R_ADDR:
                v = ld.IMAGE_REL_I386_DIR32