本文整理匯總了Golang中cmd/link/internal/ld.ELF64_R_INFO函數的典型用法代碼示例。如果您正苦於以下問題:Golang ELF64_R_INFO函數的具體用法?Golang ELF64_R_INFO怎麽用?Golang ELF64_R_INFO使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ELF64_R_INFO函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: addpltsym
func addpltsym(ctxt *ld.Link, s *ld.Symbol) {
if s.Plt >= 0 {
return
}
ld.Adddynsym(ctxt, s)
if ld.Iself {
plt := ld.Linklookup(ctxt, ".plt", 0)
rela := ld.Linklookup(ctxt, ".rela.plt", 0)
if plt.Size == 0 {
elfsetupplt()
}
// Create the glink resolver if necessary
glink := ensureglinkresolver()
// Write symbol resolver stub (just a branch to the
// glink resolver stub)
r := ld.Addrel(glink)
r.Sym = glink
r.Off = int32(glink.Size)
r.Siz = 4
r.Type = obj.R_CALLPOWER
ld.Adduint32(ctxt, glink, 0x48000000) // b .glink
// In the ppc64 ABI, the dynamic linker is responsible
// for writing the entire PLT. We just need to
// reserve 8 bytes for each PLT entry and generate a
// JMP_SLOT dynamic relocation for it.
//
// TODO(austin): ABI v1 is different
s.Plt = int32(plt.Size)
plt.Size += 8
ld.Addaddrplus(ctxt, rela, plt, int64(s.Plt))
ld.Adduint64(ctxt, rela, ld.ELF64_R_INFO(uint32(s.Dynid), ld.R_PPC64_JMP_SLOT))
ld.Adduint64(ctxt, rela, 0)
} else {
ld.Diag("addpltsym: unsupported binary format")
}
}
示例2: addgotsym
func addgotsym(ctxt *ld.Link, s *ld.Symbol) {
if s.Got >= 0 {
return
}
ld.Adddynsym(ctxt, s)
got := ld.Linklookup(ctxt, ".got", 0)
s.Got = int32(got.Size)
ld.Adduint64(ctxt, got, 0)
if ld.Iself {
rela := ld.Linklookup(ctxt, ".rela", 0)
ld.Addaddrplus(ctxt, rela, got, int64(s.Got))
ld.Adduint64(ctxt, rela, ld.ELF64_R_INFO(uint32(s.Dynid), ld.R_390_GLOB_DAT))
ld.Adduint64(ctxt, rela, 0)
} else {
ctxt.Diag("addgotsym: unsupported binary format")
}
}
示例3: addgotsym
func addgotsym(s *ld.LSym) {
if s.Got >= 0 {
return
}
ld.Adddynsym(ld.Ctxt, s)
got := ld.Linklookup(ld.Ctxt, ".got", 0)
s.Got = int32(got.Size)
ld.Adduint64(ld.Ctxt, got, 0)
if ld.Iself {
rela := ld.Linklookup(ld.Ctxt, ".rela", 0)
ld.Addaddrplus(ld.Ctxt, rela, got, int64(s.Got))
ld.Adduint64(ld.Ctxt, rela, ld.ELF64_R_INFO(uint32(s.Dynid), ld.R_X86_64_GLOB_DAT))
ld.Adduint64(ld.Ctxt, rela, 0)
} else if ld.HEADTYPE == obj.Hdarwin {
ld.Adduint32(ld.Ctxt, ld.Linklookup(ld.Ctxt, ".linkedit.got", 0), uint32(s.Dynid))
} else {
ld.Diag("addgotsym: unsupported binary format")
}
}
示例4: addgotsym
func addgotsym(ctxt *ld.Link, s *ld.Symbol) {
if s.Got >= 0 {
return
}
ld.Adddynsym(ctxt, s)
got := ctxt.Syms.Lookup(".got", 0)
s.Got = int32(got.Size)
ld.Adduint64(ctxt, got, 0)
if ld.Iself {
rela := ctxt.Syms.Lookup(".rela", 0)
ld.Addaddrplus(ctxt, rela, got, int64(s.Got))
ld.Adduint64(ctxt, rela, ld.ELF64_R_INFO(uint32(s.Dynid), ld.R_X86_64_GLOB_DAT))
ld.Adduint64(ctxt, rela, 0)
} else if ld.Headtype == obj.Hdarwin {
ld.Adduint32(ctxt, ctxt.Syms.Lookup(".linkedit.got", 0), uint32(s.Dynid))
} else {
ld.Errorf(s, "addgotsym: unsupported binary format")
}
}
示例5: adddynrel
func adddynrel(s *ld.Symbol, 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_PPC64_REL24:
r.Type = obj.R_CALLPOWER
// This is a local call, so the caller isn't setting
// up r12 and r2 is the same for the caller and
// callee. Hence, we need to go to the local entry
// point. (If we don't do this, the callee will try
// to use r12 to compute r2.)
r.Add += int64(r.Sym.Localentry) * 4
if targ.Type == obj.SDYNIMPORT {
// Should have been handled in elfsetupplt
ld.Diag("unexpected R_PPC64_REL24 for dyn import")
}
return
case 256 + ld.R_PPC_REL32:
r.Type = obj.R_PCREL
r.Add += 4
if targ.Type == obj.SDYNIMPORT {
ld.Diag("unexpected R_PPC_REL32 for dyn import")
}
return
case 256 + ld.R_PPC64_ADDR64:
r.Type = obj.R_ADDR
if targ.Type == obj.SDYNIMPORT {
// These happen in .toc sections
ld.Adddynsym(ld.Ctxt, targ)
rela := ld.Linklookup(ld.Ctxt, ".rela", 0)
ld.Addaddrplus(ld.Ctxt, rela, s, int64(r.Off))
ld.Adduint64(ld.Ctxt, rela, ld.ELF64_R_INFO(uint32(targ.Dynid), ld.R_PPC64_ADDR64))
ld.Adduint64(ld.Ctxt, rela, uint64(r.Add))
r.Type = 256 // ignore during relocsym
}
return
case 256 + ld.R_PPC64_TOC16:
r.Type = obj.R_POWER_TOC
r.Variant = ld.RV_POWER_LO | ld.RV_CHECK_OVERFLOW
return
case 256 + ld.R_PPC64_TOC16_LO:
r.Type = obj.R_POWER_TOC
r.Variant = ld.RV_POWER_LO
return
case 256 + ld.R_PPC64_TOC16_HA:
r.Type = obj.R_POWER_TOC
r.Variant = ld.RV_POWER_HA | ld.RV_CHECK_OVERFLOW
return
case 256 + ld.R_PPC64_TOC16_HI:
r.Type = obj.R_POWER_TOC
r.Variant = ld.RV_POWER_HI | ld.RV_CHECK_OVERFLOW
return
case 256 + ld.R_PPC64_TOC16_DS:
r.Type = obj.R_POWER_TOC
r.Variant = ld.RV_POWER_DS | ld.RV_CHECK_OVERFLOW
return
case 256 + ld.R_PPC64_TOC16_LO_DS:
r.Type = obj.R_POWER_TOC
r.Variant = ld.RV_POWER_DS
return
case 256 + ld.R_PPC64_REL16_LO:
r.Type = obj.R_PCREL
r.Variant = ld.RV_POWER_LO
r.Add += 2 // Compensate for relocation size of 2
return
case 256 + ld.R_PPC64_REL16_HI:
r.Type = obj.R_PCREL
r.Variant = ld.RV_POWER_HI | ld.RV_CHECK_OVERFLOW
r.Add += 2
return
case 256 + ld.R_PPC64_REL16_HA:
r.Type = obj.R_PCREL
r.Variant = ld.RV_POWER_HA | ld.RV_CHECK_OVERFLOW
r.Add += 2
//.........這裏部分代碼省略.........
示例6: addpltsym
func addpltsym(s *ld.LSym) {
if s.Plt >= 0 {
return
}
ld.Adddynsym(ld.Ctxt, s)
if ld.Iself {
plt := ld.Linklookup(ld.Ctxt, ".plt", 0)
got := ld.Linklookup(ld.Ctxt, ".got.plt", 0)
rela := ld.Linklookup(ld.Ctxt, ".rela.plt", 0)
if plt.Size == 0 {
elfsetupplt()
}
// jmpq *got+size(IP)
ld.Adduint8(ld.Ctxt, plt, 0xff)
ld.Adduint8(ld.Ctxt, plt, 0x25)
ld.Addpcrelplus(ld.Ctxt, plt, got, got.Size)
// add to got: pointer to current pos in plt
ld.Addaddrplus(ld.Ctxt, got, plt, plt.Size)
// pushq $x
ld.Adduint8(ld.Ctxt, plt, 0x68)
ld.Adduint32(ld.Ctxt, plt, uint32((got.Size-24-8)/8))
// jmpq .plt
ld.Adduint8(ld.Ctxt, plt, 0xe9)
ld.Adduint32(ld.Ctxt, plt, uint32(-(plt.Size + 4)))
// rela
ld.Addaddrplus(ld.Ctxt, rela, got, got.Size-8)
ld.Adduint64(ld.Ctxt, rela, ld.ELF64_R_INFO(uint32(s.Dynid), ld.R_X86_64_JMP_SLOT))
ld.Adduint64(ld.Ctxt, rela, 0)
s.Plt = int32(plt.Size - 16)
} else if ld.HEADTYPE == obj.Hdarwin {
// To do lazy symbol lookup right, we're supposed
// to tell the dynamic loader which library each
// symbol comes from and format the link info
// section just so. I'm too lazy (ha!) to do that
// so for now we'll just use non-lazy pointers,
// which don't need to be told which library to use.
//
// http://networkpx.blogspot.com/2009/09/about-lcdyldinfoonly-command.html
// has details about what we're avoiding.
addgotsym(s)
plt := ld.Linklookup(ld.Ctxt, ".plt", 0)
ld.Adduint32(ld.Ctxt, ld.Linklookup(ld.Ctxt, ".linkedit.plt", 0), uint32(s.Dynid))
// jmpq *got+size(IP)
s.Plt = int32(plt.Size)
ld.Adduint8(ld.Ctxt, plt, 0xff)
ld.Adduint8(ld.Ctxt, plt, 0x25)
ld.Addpcrelplus(ld.Ctxt, plt, ld.Linklookup(ld.Ctxt, ".got", 0), int64(s.Got))
} else {
ld.Diag("addpltsym: unsupported binary format")
}
}
示例7: adddynrel
//.........這裏部分代碼省略.........
// fall through
case 512 + ld.MACHO_X86_64_RELOC_GOT*2 + 1:
if targ.Type != obj.SDYNIMPORT {
ld.Diag("unexpected GOT reloc for non-dynamic symbol %s", targ.Name)
}
addgotsym(targ)
r.Type = obj.R_PCREL
r.Sym = ld.Linklookup(ld.Ctxt, ".got", 0)
r.Add += int64(targ.Got)
return
}
// Handle references to ELF symbols from our own object files.
if targ.Type != obj.SDYNIMPORT {
return
}
switch r.Type {
case obj.R_CALL,
obj.R_PCREL:
if ld.HEADTYPE == obj.Hwindows {
// nothing to do, the relocation will be laid out in pereloc1
return
} else {
// for both ELF and Mach-O
addpltsym(targ)
r.Sym = ld.Linklookup(ld.Ctxt, ".plt", 0)
r.Add = int64(targ.Plt)
return
}
case obj.R_ADDR:
if s.Type == obj.STEXT && ld.Iself {
if ld.HEADTYPE == obj.Hsolaris {
addpltsym(targ)
r.Sym = ld.Linklookup(ld.Ctxt, ".plt", 0)
r.Add += int64(targ.Plt)
return
}
// The code is asking for the address of an external
// function. We provide it with the address of the
// correspondent GOT symbol.
addgotsym(targ)
r.Sym = ld.Linklookup(ld.Ctxt, ".got", 0)
r.Add += int64(targ.Got)
return
}
if s.Type != obj.SDATA {
break
}
if ld.Iself {
ld.Adddynsym(ld.Ctxt, targ)
rela := ld.Linklookup(ld.Ctxt, ".rela", 0)
ld.Addaddrplus(ld.Ctxt, rela, s, int64(r.Off))
if r.Siz == 8 {
ld.Adduint64(ld.Ctxt, rela, ld.ELF64_R_INFO(uint32(targ.Dynid), ld.R_X86_64_64))
} else {
ld.Adduint64(ld.Ctxt, rela, ld.ELF64_R_INFO(uint32(targ.Dynid), ld.R_X86_64_32))
}
ld.Adduint64(ld.Ctxt, rela, uint64(r.Add))
r.Type = 256 // ignore during relocsym
return
}
if ld.HEADTYPE == obj.Hdarwin && s.Size == int64(ld.Thearch.Ptrsize) && r.Off == 0 {
// Mach-O relocations are a royal pain to lay out.
// They use a compact stateful bytecode representation
// that is too much bother to deal with.
// Instead, interpret the C declaration
// void *_Cvar_stderr = &stderr;
// as making _Cvar_stderr the name of a GOT entry
// for stderr. This is separate from the usual GOT entry,
// just in case the C code assigns to the variable,
// and of course it only works for single pointers,
// but we only need to support cgo and that's all it needs.
ld.Adddynsym(ld.Ctxt, targ)
got := ld.Linklookup(ld.Ctxt, ".got", 0)
s.Type = got.Type | obj.SSUB
s.Outer = got
s.Sub = got.Sub
got.Sub = s
s.Value = got.Size
ld.Adduint64(ld.Ctxt, got, 0)
ld.Adduint32(ld.Ctxt, ld.Linklookup(ld.Ctxt, ".linkedit.got", 0), uint32(targ.Dynid))
r.Type = 256 // ignore during relocsym
return
}
if ld.HEADTYPE == obj.Hwindows {
// nothing to do, the relocation will be laid out in pereloc1
return
}
}
ld.Ctxt.Cursym = s
ld.Diag("unsupported relocation for dynamic symbol %s (type=%d stype=%d)", targ.Name, r.Type, targ.Type)
}
示例8: addpltsym
func addpltsym(ctxt *ld.Link, s *ld.Symbol) {
if s.Plt >= 0 {
return
}
ld.Adddynsym(ctxt, s)
if ld.Iself {
plt := ld.Linklookup(ctxt, ".plt", 0)
got := ld.Linklookup(ctxt, ".got", 0)
rela := ld.Linklookup(ctxt, ".rela.plt", 0)
if plt.Size == 0 {
elfsetupplt(ctxt)
}
// larl %r1,_GLOBAL_OFFSET_TABLE_+index
ld.Adduint8(ctxt, plt, 0xc0)
ld.Adduint8(ctxt, plt, 0x10)
ld.Addpcrelplus(ctxt, plt, got, got.Size+6) // need variant?
// add to got: pointer to current pos in plt
ld.Addaddrplus(ctxt, got, plt, plt.Size+8) // weird but correct
// lg %r1,0(%r1)
ld.Adduint8(ctxt, plt, 0xe3)
ld.Adduint8(ctxt, plt, 0x10)
ld.Adduint8(ctxt, plt, 0x10)
ld.Adduint8(ctxt, plt, 0x00)
ld.Adduint8(ctxt, plt, 0x00)
ld.Adduint8(ctxt, plt, 0x04)
// br %r1
ld.Adduint8(ctxt, plt, 0x07)
ld.Adduint8(ctxt, plt, 0xf1)
// basr %r1,%r0
ld.Adduint8(ctxt, plt, 0x0d)
ld.Adduint8(ctxt, plt, 0x10)
// lgf %r1,12(%r1)
ld.Adduint8(ctxt, plt, 0xe3)
ld.Adduint8(ctxt, plt, 0x10)
ld.Adduint8(ctxt, plt, 0x10)
ld.Adduint8(ctxt, plt, 0x0c)
ld.Adduint8(ctxt, plt, 0x00)
ld.Adduint8(ctxt, plt, 0x14)
// jg .plt
ld.Adduint8(ctxt, plt, 0xc0)
ld.Adduint8(ctxt, plt, 0xf4)
ld.Adduint32(ctxt, plt, uint32(-((plt.Size - 2) >> 1))) // roll-your-own relocation
//.plt index
ld.Adduint32(ctxt, plt, uint32(rela.Size)) // rela size before current entry
// rela
ld.Addaddrplus(ctxt, rela, got, got.Size-8)
ld.Adduint64(ctxt, rela, ld.ELF64_R_INFO(uint32(s.Dynid), ld.R_390_JMP_SLOT))
ld.Adduint64(ctxt, rela, 0)
s.Plt = int32(plt.Size - 32)
} else {
ctxt.Diag("addpltsym: unsupported binary format")
}
}
示例9: adddynrel
//.........這裏部分代碼省略.........
addgotsym(ctxt, targ)
r.Sym = ctxt.Syms.Lookup(".got", 0)
r.Add += int64(targ.Got)
return true
}
// Process dynamic relocations for the data sections.
if ld.Buildmode == ld.BuildmodePIE && ld.Linkmode == ld.LinkInternal {
// When internally linking, generate dynamic relocations
// for all typical R_ADDR relocations. The exception
// are those R_ADDR that are created as part of generating
// the dynamic relocations and must be resolved statically.
//
// There are three phases relevant to understanding this:
//
// dodata() // we are here
// address() // symbol address assignment
// reloc() // resolution of static R_ADDR relocs
//
// At this point symbol addresses have not been
// assigned yet (as the final size of the .rela section
// will affect the addresses), and so we cannot write
// the Elf64_Rela.r_offset now. Instead we delay it
// until after the 'address' phase of the linker is
// complete. We do this via Addaddrplus, which creates
// a new R_ADDR relocation which will be resolved in
// the 'reloc' phase.
//
// These synthetic static R_ADDR relocs must be skipped
// now, or else we will be caught in an infinite loop
// of generating synthetic relocs for our synthetic
// relocs.
switch s.Name {
case ".dynsym", ".rela", ".got.plt", ".dynamic":
return false
}
} else {
// Either internally linking a static executable,
// in which case we can resolve these relocations
// statically in the 'reloc' phase, or externally
// linking, in which case the relocation will be
// prepared in the 'reloc' phase and passed to the
// external linker in the 'asmb' phase.
if s.Type != obj.SDATA && s.Type != obj.SRODATA {
break
}
}
if ld.Iself {
// TODO: We generate a R_X86_64_64 relocation for every R_ADDR, even
// though it would be more efficient (for the dynamic linker) if we
// generated R_X86_RELATIVE instead.
ld.Adddynsym(ctxt, targ)
rela := ctxt.Syms.Lookup(".rela", 0)
ld.Addaddrplus(ctxt, rela, s, int64(r.Off))
if r.Siz == 8 {
ld.Adduint64(ctxt, rela, ld.ELF64_R_INFO(uint32(targ.Dynid), ld.R_X86_64_64))
} else {
// TODO: never happens, remove.
ld.Adduint64(ctxt, rela, ld.ELF64_R_INFO(uint32(targ.Dynid), ld.R_X86_64_32))
}
ld.Adduint64(ctxt, rela, uint64(r.Add))
r.Type = 256 // ignore during relocsym
return true
}
if ld.Headtype == obj.Hdarwin && s.Size == int64(ld.SysArch.PtrSize) && r.Off == 0 {
// Mach-O relocations are a royal pain to lay out.
// They use a compact stateful bytecode representation
// that is too much bother to deal with.
// Instead, interpret the C declaration
// void *_Cvar_stderr = &stderr;
// as making _Cvar_stderr the name of a GOT entry
// for stderr. This is separate from the usual GOT entry,
// just in case the C code assigns to the variable,
// and of course it only works for single pointers,
// but we only need to support cgo and that's all it needs.
ld.Adddynsym(ctxt, targ)
got := ctxt.Syms.Lookup(".got", 0)
s.Type = got.Type | obj.SSUB
s.Outer = got
s.Sub = got.Sub
got.Sub = s
s.Value = got.Size
ld.Adduint64(ctxt, got, 0)
ld.Adduint32(ctxt, ctxt.Syms.Lookup(".linkedit.got", 0), uint32(targ.Dynid))
r.Type = 256 // ignore during relocsym
return true
}
if ld.Headtype == obj.Hwindows || ld.Headtype == obj.Hwindowsgui {
// nothing to do, the relocation will be laid out in pereloc1
return true
}
}
return false
}