var rr loader.ExtReloc
needExtReloc := false // will set to true below in case it is needed
if target.IsExternal() {
- rr.Sym = rs
- rr.Type = rt
- rr.Off = off
- rr.Siz = uint8(siz)
- rr.Add = r.Add()
+ rr.Idx = ri
}
// TODO(mundaym): remove this special case - see issue 14218.
case objabi.R_TLS_LE:
if target.IsExternal() && target.IsElf() {
needExtReloc = true
- if rr.Sym == 0 {
- rr.Sym = syms.Tlsg2
+ rr.Xsym = rs
+ if rr.Xsym == 0 {
+ rr.Xsym = syms.Tlsg2
}
- rr.Xsym = rr.Sym
- rr.Xadd = rr.Add
+ rr.Xadd = r.Add()
o = 0
if !target.IsAMD64() {
- o = rr.Add
+ o = r.Add()
}
break
}
case objabi.R_TLS_IE:
if target.IsExternal() && target.IsElf() {
needExtReloc = true
- if rr.Sym == 0 {
- rr.Sym = syms.Tlsg2
+ rr.Xsym = rs
+ if rr.Xsym == 0 {
+ rr.Xsym = syms.Tlsg2
}
- rr.Xsym = rr.Sym
- rr.Xadd = rr.Add
+ rr.Xadd = r.Add()
o = 0
if !target.IsAMD64() {
- o = rr.Add
+ o = r.Add()
}
break
}
// set up addend for eventual relocation via outer symbol.
rs := rs
rs, off := foldSubSymbolOffset(ldr, rs)
- rr.Xadd = rr.Add + off
+ rr.Xadd = r.Add() + off
rst := ldr.SymType(rs)
if rst != sym.SHOSTOBJ && rst != sym.SDYNIMPORT && rst != sym.SUNDEFEXT && ldr.SymSect(rs) == nil {
st.err.Errorf(s, "missing section for relocation target %s", ldr.SymName(rs))
} else if target.IsWindows() {
// nothing to do
} else if target.IsAIX() {
- o = ldr.SymValue(rr.Sym) + rr.Add
+ o = ldr.SymValue(rs) + r.Add()
} else {
st.err.Errorf(s, "unhandled pcrel relocation to %s on %v", ldr.SymName(rs), target.HeadType)
}
needExtReloc = false
}
- // PE code emits IMAGE_REL_I386_SECREL and IMAGE_REL_AMD64_SECREL
- // for R_DWARFSECREF relocations, while R_ADDR is replaced with
- // IMAGE_REL_I386_DIR32, IMAGE_REL_AMD64_ADDR64 and IMAGE_REL_AMD64_ADDR32.
- // Do not replace R_DWARFSECREF with R_ADDR for windows -
- // let PE code emit correct relocations.
- if !target.IsWindows() {
- rr.Type = objabi.R_ADDR
- }
-
- rr.Xsym = loader.Sym(ldr.SymSect(rr.Sym).Sym2)
- rr.Xadd = rr.Add + ldr.SymValue(rr.Sym) - int64(ldr.SymSect(rr.Sym).Vaddr)
+ rr.Xsym = loader.Sym(ldr.SymSect(rs).Sym2)
+ rr.Xadd = r.Add() + ldr.SymValue(rs) - int64(ldr.SymSect(rs).Vaddr)
o = rr.Xadd
if target.IsElf() && target.IsAMD64() {
case objabi.R_GOTPCREL:
if target.IsDynlinkingGo() && target.IsDarwin() && rs != 0 && rst != sym.SCONST {
needExtReloc = true
- rr.Xadd = rr.Add
- rr.Xadd -= int64(rr.Siz) // relative to address after the relocated chunk
- rr.Xsym = rr.Sym
+ rr.Xadd = r.Add()
+ rr.Xadd -= int64(siz) // relative to address after the relocated chunk
+ rr.Xsym = rs
o = rr.Xadd
- o += int64(rr.Siz)
+ o += int64(siz)
break
}
fallthrough
needExtReloc = true
rr.Xadd = 0
if target.IsElf() {
- rr.Xadd -= int64(rr.Siz)
+ rr.Xadd -= int64(siz)
}
- rr.Xsym = rr.Sym
+ rr.Xsym = rs
o = 0
break
}
// set up addend for eventual relocation via outer symbol.
rs := rs
rs, off := foldSubSymbolOffset(ldr, rs)
- rr.Xadd = rr.Add + off
- rr.Xadd -= int64(rr.Siz) // relative to address after the relocated chunk
+ rr.Xadd = r.Add() + off
+ rr.Xadd -= int64(siz) // relative to address after the relocated chunk
rst := ldr.SymType(rs)
if rst != sym.SHOSTOBJ && rst != sym.SDYNIMPORT && ldr.SymSect(rs) == nil {
st.err.Errorf(s, "missing section for relocation target %s", ldr.SymName(rs))
o = 0
}
} else if target.IsDarwin() {
- if rr.Type == objabi.R_CALL {
+ if rt == objabi.R_CALL {
if target.IsExternal() && rst == sym.SDYNIMPORT {
if target.IsAMD64() {
// AMD64 dynamic relocations are relative to the end of the relocation.
- o += int64(rr.Siz)
+ o += int64(siz)
}
} else {
if rst != sym.SHOSTOBJ {
o += int64(uint64(ldr.SymValue(rs)) - ldr.SymSect(rs).Vaddr)
}
- o -= int64(rr.Off) // relative to section offset, not symbol
+ o -= int64(off) // relative to section offset, not symbol
}
} else {
- o += int64(rr.Siz)
+ o += int64(siz)
}
} else if target.IsWindows() && target.IsAMD64() { // only amd64 needs PCREL
// PE/COFF's PC32 relocation uses the address after the relocated
// bytes as the base. Compensate by skewing the addend.
- o += int64(rr.Siz)
+ o += int64(siz)
} else {
st.err.Errorf(s, "unhandled pcrel relocation to %s on %v", ldr.SymName(rs), target.HeadType)
}
st.err.Errorf(s, "find XCOFF R_REF with internal linking")
}
needExtReloc = true
- rr.Xsym = rr.Sym
- rr.Xadd = rr.Add
+ rr.Xsym = rs
+ rr.Xadd = r.Add()
// This isn't a real relocation so it must not update
// its offset value.
// ExtReloc contains the payload for an external relocation.
type ExtReloc struct {
- Off int32 // offset to rewrite
- Siz uint8 // number of bytes to rewrite: 0, 1, 2, or 4
- Type objabi.RelocType // the relocation type
- Sym Sym // global index of symbol the reloc addresses
- Add int64 // addend
+ Idx int // index of the original relocation
Xsym Sym
Xadd int64
}
if int(src) >= len(l.extRelocs) {
return
}
- relocs := l.extRelocs[src]
- if len(relocs) == 0 {
+ extRelocs := l.extRelocs[src]
+ if len(extRelocs) == 0 {
return
}
if len(dst.R) != 0 {
panic("bad")
}
- dst.R = make([]sym.Reloc, len(relocs))
+ dst.R = make([]sym.Reloc, len(extRelocs))
+ relocs := l.Relocs(src)
for i := range dst.R {
- sr := &relocs[i]
+ er := &extRelocs[i]
+ sr := relocs.At2(er.Idx)
r := &dst.R[i]
r.InitExt()
- r.Off = sr.Off
- r.Siz = sr.Siz
- r.Type = sr.Type
- r.Sym = l.Syms[sr.Sym]
- r.Add = sr.Add
- r.Xsym = l.Syms[sr.Xsym]
- r.Xadd = sr.Xadd
+ r.Off = sr.Off()
+ r.Siz = sr.Siz()
+ r.Type = sr.Type()
+ r.Sym = l.Syms[l.ResolveABIAlias(sr.Sym())]
+ r.Add = sr.Add()
+ r.Xsym = l.Syms[er.Xsym]
+ r.Xadd = er.Xadd
+ if rv := l.RelocVariant(src, er.Idx); rv != 0 {
+ r.Variant = rv
+ }
}
}