Commit aada4903 authored by Alex Brainman's avatar Alex Brainman

cmd/link: write dwarf relocations

For #10776.

Change-Id: I11dd441d8e5d6316889ffa8418df8b58c57c677d
Reviewed-on: https://go-review.googlesource.com/36982Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 15442178
......@@ -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
......
......@@ -575,7 +575,14 @@ func relocsym(ctxt *Link, s *Symbol) {
}
if Linkmode == LinkExternal {
r.Done = 0
// 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)
......
......@@ -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)
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment