本文整理匯總了Golang中cmd/link/avail/ld.Reloc.Add方法的典型用法代碼示例。如果您正苦於以下問題:Golang Reloc.Add方法的具體用法?Golang Reloc.Add怎麽用?Golang Reloc.Add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cmd/link/avail/ld.Reloc
的用法示例。
在下文中一共展示了Reloc.Add方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: adddynrel
func adddynrel(s *ld.LSym, r *ld.Reloc) {
targ := r.Sym
ld.Ctxt.Cursym = s
switch r.Type {
default:
if r.Type >= 256 {
ld.Diag("unexpected relocation type %d", r.Type)
return
}
// Handle relocations found in ELF object files.
case 256 + ld.R_X86_64_PC32:
if targ.Type == obj.SDYNIMPORT {
ld.Diag("unexpected R_X86_64_PC32 relocation for dynamic symbol %s", targ.Name)
}
if targ.Type == 0 || targ.Type == obj.SXREF {
ld.Diag("unknown symbol %s in pcrel", targ.Name)
}
r.Type = obj.R_PCREL
r.Add += 4
return
case 256 + ld.R_X86_64_PLT32:
r.Type = obj.R_PCREL
r.Add += 4
if targ.Type == obj.SDYNIMPORT {
addpltsym(targ)
r.Sym = ld.Linklookup(ld.Ctxt, ".plt", 0)
r.Add += int64(targ.Plt)
}
return
case 256 + ld.R_X86_64_GOTPCREL, 256 + ld.R_X86_64_GOTPCRELX, 256 + ld.R_X86_64_REX_GOTPCRELX:
if targ.Type != obj.SDYNIMPORT {
// have symbol
if r.Off >= 2 && s.P[r.Off-2] == 0x8b {
// turn MOVQ of GOT entry into LEAQ of symbol itself
s.P[r.Off-2] = 0x8d
r.Type = obj.R_PCREL
r.Add += 4
return
}
}
// fall back to using GOT and hope for the best (CMOV*)
// TODO: just needs relocation, no need to put in .dynsym
addgotsym(targ)
r.Type = obj.R_PCREL
r.Sym = ld.Linklookup(ld.Ctxt, ".got", 0)
r.Add += 4
r.Add += int64(targ.Got)
return
case 256 + ld.R_X86_64_64:
if targ.Type == obj.SDYNIMPORT {
ld.Diag("unexpected R_X86_64_64 relocation for dynamic symbol %s", targ.Name)
}
r.Type = obj.R_ADDR
return
// Handle relocations found in Mach-O object files.
case 512 + ld.MACHO_X86_64_RELOC_UNSIGNED*2 + 0,
512 + ld.MACHO_X86_64_RELOC_SIGNED*2 + 0,
512 + ld.MACHO_X86_64_RELOC_BRANCH*2 + 0:
// TODO: What is the difference between all these?
r.Type = obj.R_ADDR
if targ.Type == obj.SDYNIMPORT {
ld.Diag("unexpected reloc for dynamic symbol %s", targ.Name)
}
return
case 512 + ld.MACHO_X86_64_RELOC_BRANCH*2 + 1:
if targ.Type == obj.SDYNIMPORT {
addpltsym(targ)
r.Sym = ld.Linklookup(ld.Ctxt, ".plt", 0)
r.Add = int64(targ.Plt)
r.Type = obj.R_PCREL
return
}
fallthrough
// fall through
case 512 + ld.MACHO_X86_64_RELOC_UNSIGNED*2 + 1,
512 + ld.MACHO_X86_64_RELOC_SIGNED*2 + 1,
512 + ld.MACHO_X86_64_RELOC_SIGNED_1*2 + 1,
512 + ld.MACHO_X86_64_RELOC_SIGNED_2*2 + 1,
512 + ld.MACHO_X86_64_RELOC_SIGNED_4*2 + 1:
r.Type = obj.R_PCREL
if targ.Type == obj.SDYNIMPORT {
ld.Diag("unexpected pc-relative reloc for dynamic symbol %s", targ.Name)
}
return
case 512 + ld.MACHO_X86_64_RELOC_GOT_LOAD*2 + 1:
//.........這裏部分代碼省略.........