}
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)
// 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
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)
}
}
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
})
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)