mirror of
https://github.com/golang/go
synced 2024-11-18 15:24:41 -07:00
cmd/link: write dwarf relocations
For #10776. Change-Id: I11dd441d8e5d6316889ffa8418df8b58c57c677d Reviewed-on: https://go-review.googlesource.com/36982 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
15442178c8
commit
aada49038c
@ -500,6 +500,9 @@ func pereloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
|
|||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
case obj.R_DWARFREF:
|
||||||
|
v = ld.IMAGE_REL_AMD64_SECREL
|
||||||
|
|
||||||
case obj.R_ADDR:
|
case obj.R_ADDR:
|
||||||
if r.Siz == 8 {
|
if r.Siz == 8 {
|
||||||
v = ld.IMAGE_REL_AMD64_ADDR64
|
v = ld.IMAGE_REL_AMD64_ADDR64
|
||||||
|
@ -575,7 +575,14 @@ func relocsym(ctxt *Link, s *Symbol) {
|
|||||||
}
|
}
|
||||||
if Linkmode == LinkExternal {
|
if Linkmode == LinkExternal {
|
||||||
r.Done = 0
|
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.Xsym = ctxt.Syms.ROLookup(r.Sym.Sect.Name, 0)
|
||||||
r.Xadd = r.Add + Symaddr(r.Sym) - int64(r.Sym.Sect.Vaddr)
|
r.Xadd = r.Add + Symaddr(r.Sym) - int64(r.Sym.Sect.Vaddr)
|
||||||
|
@ -801,7 +801,7 @@ func addexports(ctxt *Link) {
|
|||||||
|
|
||||||
// perelocsect relocates symbols from first in section sect, and returns
|
// perelocsect relocates symbols from first in section sect, and returns
|
||||||
// the total number of relocations emitted.
|
// 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 main section has no bits, nothing to relocate.
|
||||||
if sect.Vaddr >= sect.Seg.Vaddr+sect.Seg.Filelen {
|
if sect.Vaddr >= sect.Seg.Vaddr+sect.Seg.Filelen {
|
||||||
return 0
|
return 0
|
||||||
@ -841,7 +841,7 @@ func perelocsect(ctxt *Link, sect *Section, syms []*Symbol) int {
|
|||||||
if r.Xsym.Dynid < 0 {
|
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)
|
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)
|
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 {
|
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 {
|
for sect := Segtext.Sect.Next; sect != nil; sect = sect.Next {
|
||||||
n += perelocsect(ctxt, sect, datap)
|
n += perelocsect(ctxt, sect, datap, Segtext.Vaddr)
|
||||||
}
|
}
|
||||||
return n
|
return n
|
||||||
})
|
})
|
||||||
@ -897,11 +897,24 @@ func peemitreloc(ctxt *Link, text, data, ctors *IMAGE_SECTION_HEADER) {
|
|||||||
peemitsectreloc(data, func() int {
|
peemitsectreloc(data, func() int {
|
||||||
var n int
|
var n int
|
||||||
for sect := Segdata.Sect; sect != nil; sect = sect.Next {
|
for sect := Segdata.Sect; sect != nil; sect = sect.Next {
|
||||||
n += perelocsect(ctxt, sect, datap)
|
n += perelocsect(ctxt, sect, datap, Segdata.Vaddr)
|
||||||
}
|
}
|
||||||
return n
|
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 {
|
peemitsectreloc(ctors, func() int {
|
||||||
dottext := ctxt.Syms.Lookup(".text", 0)
|
dottext := ctxt.Syms.Lookup(".text", 0)
|
||||||
Lputl(0)
|
Lputl(0)
|
||||||
|
@ -482,6 +482,9 @@ func pereloc1(s *ld.Symbol, r *ld.Reloc, sectoff int64) bool {
|
|||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
case obj.R_DWARFREF:
|
||||||
|
v = ld.IMAGE_REL_I386_SECREL
|
||||||
|
|
||||||
case obj.R_ADDR:
|
case obj.R_ADDR:
|
||||||
v = ld.IMAGE_REL_I386_DIR32
|
v = ld.IMAGE_REL_I386_DIR32
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user