本文整理匯總了C++中ELF_R_TYPE函數的典型用法代碼示例。如果您正苦於以下問題:C++ ELF_R_TYPE函數的具體用法?C++ ELF_R_TYPE怎麽用?C++ ELF_R_TYPE使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ELF_R_TYPE函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: check_rela
static void check_rela(Elf_Rela *rela, struct module *me)
{
struct mod_arch_syminfo *info;
info = me->arch.syminfo + ELF_R_SYM (rela->r_info);
switch (ELF_R_TYPE (rela->r_info)) {
case R_390_GOT12: /* 12 bit GOT offset. */
case R_390_GOT16: /* 16 bit GOT offset. */
case R_390_GOT20: /* 20 bit GOT offset. */
case R_390_GOT32: /* 32 bit GOT offset. */
case R_390_GOT64: /* 64 bit GOT offset. */
case R_390_GOTENT: /* 32 bit PC rel. to GOT entry shifted by 1. */
case R_390_GOTPLT12: /* 12 bit offset to jump slot. */
case R_390_GOTPLT16: /* 16 bit offset to jump slot. */
case R_390_GOTPLT20: /* 20 bit offset to jump slot. */
case R_390_GOTPLT32: /* 32 bit offset to jump slot. */
case R_390_GOTPLT64: /* 64 bit offset to jump slot. */
case R_390_GOTPLTENT: /* 32 bit rel. offset to jump slot >> 1. */
if (info->got_offset == -1UL) {
info->got_offset = me->arch.got_size;
me->arch.got_size += sizeof(void*);
}
break;
case R_390_PLT16DBL: /* 16 bit PC rel. PLT shifted by 1. */
case R_390_PLT32DBL: /* 32 bit PC rel. PLT shifted by 1. */
case R_390_PLT32: /* 32 bit PC relative PLT address. */
case R_390_PLT64: /* 64 bit PC relative PLT address. */
case R_390_PLTOFF16: /* 16 bit offset from GOT to PLT. */
case R_390_PLTOFF32: /* 32 bit offset from GOT to PLT. */
case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
if (info->plt_offset == -1UL) {
info->plt_offset = me->arch.plt_size;
me->arch.plt_size += PLT_ENTRY_SIZE;
}
break;
case R_390_COPY:
case R_390_GLOB_DAT:
case R_390_JMP_SLOT:
case R_390_RELATIVE:
/* Only needed if we want to support loading of
modules linked with -shared. */
break;
}
}
示例2: _rtld_relocate_plt_lazy
int
_rtld_relocate_plt_lazy(const Obj_Entry *obj)
{
if (!obj->relocbase)
return 0;
for (const Elf_Rel *rel = obj->pltrel; rel < obj->pltrellim; rel++) {
Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
assert(ELF_R_TYPE(rel->r_info) == R_TYPE(JUMP_SLOT));
/* Just relocate the GOT slots pointing into the PLT */
*where += (Elf_Addr)obj->relocbase;
rdbg(("fixup !main in %s --> %p", obj->path, (void *)*where));
}
return 0;
}
示例3: reloc_plt
/*
* * Process the PLT relocations.
* */
int
reloc_plt(Obj_Entry *obj)
{
const Elf_Rel *rellim;
const Elf_Rel *rel;
rellim = (const Elf_Rel *)((char *)obj->pltrel +
obj->pltrelsize);
for (rel = obj->pltrel; rel < rellim; rel++) {
Elf_Addr *where;
assert(ELF_R_TYPE(rel->r_info) == R_ARM_JUMP_SLOT);
where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
*where += (Elf_Addr )obj->relocbase;
}
return (0);
}
示例4: do_copy_relocations
/*
* Process the special R_386_COPY relocations in the main program. These
* copy data from a shared object into a region in the main program's BSS
* segment.
*
* Returns 0 on success, -1 on failure.
*/
int
do_copy_relocations(Obj_Entry *dstobj)
{
const Elf_Rel *rellim;
const Elf_Rel *rel;
assert(dstobj->mainprog); /* COPY relocations are invalid elsewhere */
rellim = (const Elf_Rel *) ((caddr_t) dstobj->rel + dstobj->relsize);
for (rel = dstobj->rel; rel < rellim; rel++) {
if (ELF_R_TYPE(rel->r_info) == R_386_COPY) {
void *dstaddr;
const Elf_Sym *dstsym;
const char *name;
unsigned long hash;
size_t size;
const void *srcaddr;
const Elf_Sym *srcsym;
Obj_Entry *srcobj;
dstaddr = (void *) (dstobj->relocbase + rel->r_offset);
dstsym = dstobj->symtab + ELF_R_SYM(rel->r_info);
name = dstobj->strtab + dstsym->st_name;
hash = elf_hash(name);
size = dstsym->st_size;
for (srcobj = dstobj->next; srcobj != NULL; srcobj = srcobj->next)
if ((srcsym = symlook_obj(name, hash, srcobj, false)) != NULL)
break;
if (srcobj == NULL) {
_rtld_error("Undefined symbol \"%s\" referenced from COPY"
" relocation in %s", name, dstobj->path);
return -1;
}
srcaddr = (const void *) (srcobj->relocbase + srcsym->st_value);
memcpy(dstaddr, srcaddr, size);
}
}
return 0;
}
示例5: el_applyrela
el_status el_applyrela(el_ctx *ctx, Elf_RelA *rel)
{
uint64_t *p = (uint64_t*) (rel->r_offset + ctx->base_load_vaddr);
uint32_t type = ELF_R_TYPE(rel->r_info);
uint32_t sym = ELF_R_SYM(rel->r_info);
switch (type) {
case R_AMD64_NONE: break;
case R_AMD64_RELATIVE:
EL_DEBUG("Applying R_AMD64_RELATIVE reloc @%p\n", p);
*p = rel->r_addend + ctx->base_load_vaddr;
break;
default:
EL_DEBUG("Bad relocation %u\n", type);
return EL_BADREL;
}
return EL_OK;
}
示例6: grub_arch_dl_get_tramp_got_size
void
grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
grub_size_t *got)
{
const Elf_Ehdr *e = ehdr;
const Elf_Shdr *s;
unsigned i;
*tramp = 0;
*got = 0;
/* Find a symbol table. */
for (i = 0, s = (const Elf_Shdr *) ((const char *) e + e->e_shoff);
i < e->e_shnum;
i++, s = (const Elf_Shdr *) ((const char *) s + e->e_shentsize))
if (s->sh_type == SHT_SYMTAB)
break;
if (i == e->e_shnum)
return;
for (i = 0, s = (const Elf_Shdr *) ((const char *) e + e->e_shoff);
i < e->e_shnum;
i++, s = (const Elf_Shdr *) ((const char *) s + e->e_shentsize))
if (s->sh_type == SHT_RELA)
{
const Elf_Rela *rel, *max;
for (rel = (const Elf_Rela *) ((const char *) e + s->sh_offset),
max = rel + s->sh_size / s->sh_entsize;
rel < max;
rel++)
if (ELF_R_TYPE (rel->r_info) == GRUB_ELF_R_PPC_REL24)
(*tramp)++;
}
return;
}
示例7: undo_reloc
/* ARGSUSED3 */
void
undo_reloc(void *vrel, uchar_t *oaddr, uchar_t *iaddr, Reloc *reloc)
{
Rela *rel = vrel;
const Rel_entry *rep;
Xword rtype = ELF_R_TYPE(rel->r_info, M_MACH);
ulong_t *_oaddr;
ulong_t *_iaddr;
switch (rtype) {
case R_SPARC_NONE:
break;
case R_SPARC_COPY:
(void) memset((void *)oaddr, 0, (size_t)reloc->r_size);
break;
case R_SPARC_JMP_SLOT:
/* LINTED */
_oaddr = (unsigned long *)oaddr;
/* LINTED */
_iaddr = (unsigned long *)iaddr;
if (_iaddr) {
*_oaddr++ = *_iaddr++;
*_oaddr++ = *_iaddr++;
*_oaddr = *_iaddr;
} else {
*_oaddr++ = 0;
*_oaddr++ = 0;
*_oaddr = 0;
}
break;
default:
rep = &reloc_table[rtype];
if (iaddr)
(void) memcpy(oaddr, iaddr, rep->re_fsize);
else
(void) memset(oaddr, 0, rep->re_fsize);
}
}
示例8: inc_reloc
/* ARGSUSED3 */
void
inc_reloc(void *vnrel, void *vorel, Reloc *reloc, uchar_t *oaddr,
uchar_t *iaddr)
{
Rela *nrel = vnrel;
Rela *orel = vorel;
if (ELF_R_TYPE(nrel->r_info, M_MACH) == R_AMD64_JUMP_SLOT) {
/* LINTED */
ulong_t *_oaddr = (ulong_t *)oaddr;
/* LINTED */
ulong_t *_iaddr = (ulong_t *)iaddr;
if (_iaddr)
*_oaddr = *_iaddr + reloc->r_value;
else
*_oaddr = reloc->r_value;
}
*nrel = *orel;
nrel->r_offset += reloc->r_value;
}
示例9: reloc_iresolve
int
reloc_iresolve(Obj_Entry *obj, struct Struct_RtldLockState *lockstate)
{
const Elf_Rela *relalim;
const Elf_Rela *rela;
Elf_Addr *where, target, *ptr;
if (!obj->irelative)
return (0);
relalim = (const Elf_Rela *)((const char *)obj->pltrela + obj->pltrelasize);
for (rela = obj->pltrela; rela < relalim; rela++) {
if (ELF_R_TYPE(rela->r_info) == R_AARCH64_IRELATIVE) {
ptr = (Elf_Addr *)(obj->relocbase + rela->r_addend);
where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
lock_release(rtld_bind_lock, lockstate);
target = call_ifunc_resolver(ptr);
wlock_acquire(rtld_bind_lock, lockstate);
*where = target;
}
}
obj->irelative = false;
return (0);
}
示例10: _rtld_relocate_plt_object
static int
_rtld_relocate_plt_object(const Obj_Entry *obj, const Elf_Rel *rel,
Elf_Addr *tp)
{
Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
Elf_Addr new_value;
const Elf_Sym *def;
const Obj_Entry *defobj;
unsigned long info = rel->r_info;
assert(ELF_R_TYPE(info) == R_TYPE(JUMP_SLOT));
def = _rtld_find_plt_symdef(ELF_R_SYM(info), obj, &defobj, tp != NULL);
if (__predict_false(def == NULL))
return -1;
if (__predict_false(def == &_rtld_sym_zero))
return 0;
if (ELF_ST_TYPE(def->st_info) == STT_GNU_IFUNC) {
if (tp == NULL)
return 0;
new_value = _rtld_resolve_ifunc(defobj, def);
} else {
new_value = (Elf_Addr)(defobj->relocbase + def->st_value);
}
/* Set the Thumb bit, if needed. */
if (ELF_ST_TYPE(def->st_info) == STT_ARM_TFUNC)
new_value |= 1;
rdbg(("bind now/fixup in %s --> old=%p new=%p",
defobj->strtab + def->st_name, (void *)*where, (void *)new_value));
if (*where != new_value)
*where = new_value;
if (tp)
*tp = new_value;
return 0;
}
示例11: reloc_jmpslots
/*
* LD_BIND_NOW was set - force relocation for all jump slots
*/
int
reloc_jmpslots(Obj_Entry *obj, int flags, RtldLockState *lockstate)
{
const Obj_Entry *defobj;
const Elf_Rela *relalim;
const Elf_Rela *rela;
const Elf_Sym *def;
if (obj->jmpslots_done)
return (0);
relalim = (const Elf_Rela *)((const char *)obj->pltrela +
obj->pltrelasize);
for (rela = obj->pltrela; rela < relalim; rela++) {
Elf_Addr *where, target;
where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
switch(ELF_R_TYPE(rela->r_info)) {
case R_AARCH64_JUMP_SLOT:
def = find_symdef(ELF_R_SYM(rela->r_info), obj,
&defobj, SYMLOOK_IN_PLT | flags, NULL, lockstate);
if (def == NULL)
return (-1);
if (ELF_ST_TYPE(def->st_info) == STT_GNU_IFUNC) {
obj->gnu_ifunc = true;
continue;
}
target = (Elf_Addr)(defobj->relocbase + def->st_value);
reloc_jmpslot(where, target, defobj, obj,
(const Elf_Rel *)rela);
break;
}
}
obj->jmpslots_done = true;
return (0);
}
示例12: reloc_iresolve
int
reloc_iresolve(Obj_Entry *obj, RtldLockState *lockstate)
{
const Elf_Rel *rellim;
const Elf_Rel *rel;
Elf_Addr *where, target;
if (!obj->irelative)
return (0);
rellim = (const Elf_Rel *)((char *)obj->pltrel + obj->pltrelsize);
for (rel = obj->pltrel; rel < rellim; rel++) {
switch (ELF_R_TYPE(rel->r_info)) {
case R_386_IRELATIVE:
where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
lock_release(rtld_bind_lock, lockstate);
target = call_ifunc_resolver(obj->relocbase + *where);
wlock_acquire(rtld_bind_lock, lockstate);
*where = target;
break;
}
}
obj->irelative = false;
return (0);
}
示例13: ELF_R_TYPE
bool ElfRelocations::ApplyRelaReloc(const ELF::Rela* rela,
const ElfSymbols* symbols,
SymbolResolver* resolver,
Error* error) {
const ELF::Word rel_type = ELF_R_TYPE(rela->r_info);
const ELF::Word rel_symbol = ELF_R_SYM(rela->r_info);
ELF::Addr sym_addr = 0;
ELF::Addr reloc = static_cast<ELF::Addr>(rela->r_offset + load_bias_);
RLOG(" reloc=%p offset=%p type=%d symbol=%d\n",
reloc,
rela->r_offset,
rel_type,
rel_symbol);
if (rel_type == 0)
return true;
bool resolved = false;
// If this is a symbolic relocation, compute the symbol's address.
if (__builtin_expect(rel_symbol != 0, 0)) {
if (!ResolveSymbol(rel_type,
rel_symbol,
symbols,
resolver,
reloc,
&sym_addr,
error)) {
return false;
}
resolved = true;
}
return ApplyResolvedRelaReloc(rela, sym_addr, resolved, error);
}
示例14: elf_reloc
//.........這裏部分代碼省略.........
relbgn = (ulong_t)(REL(lmp));
relend = relbgn + (ulong_t)(RELSZ(lmp));
if (pltbgn) {
if (!relbgn || (relbgn > pltbgn))
relbgn = pltbgn;
if (!relbgn || (relend < pltend))
relend = pltend;
}
}
if (!relbgn || (relbgn == relend)) {
DBG_CALL(Dbg_reloc_run(lmp, 0, plt, DBG_REL_NONE));
return (1);
}
DBG_CALL(Dbg_reloc_run(lmp, M_REL_SHT_TYPE, plt, DBG_REL_START));
/*
* If we're processing a dynamic executable in lazy mode there is no
* need to scan the .rel.plt table, however if we're processing a shared
* object in lazy mode the .got addresses associated to each .plt must
* be relocated to reflect the location of the shared object.
*/
if (pltbgn && ((MODE(lmp) & RTLD_NOW) == 0) &&
(FLAGS(lmp) & FLG_RT_FIXED))
noplt = 1;
sip = SYMINFO(lmp);
/*
* Loop through relocations.
*/
while (relbgn < relend) {
mmapobj_result_t *mpp;
uint_t sb_flags = 0;
rtype = ELF_R_TYPE(((Rel *)relbgn)->r_info, M_MACH);
/*
* If this is a RELATIVE relocation in a shared object (the
* common case), and if we are not debugging, then jump into a
* tighter relocation loop (elf_reloc_relative).
*/
if ((rtype == R_386_RELATIVE) &&
((FLAGS(lmp) & FLG_RT_FIXED) == 0) && (DBG_ENABLED == 0)) {
if (relacount) {
relbgn = elf_reloc_relative_count(relbgn,
relacount, relsiz, basebgn, lmp,
textrel, 0);
relacount = 0;
} else {
relbgn = elf_reloc_relative(relbgn, relend,
relsiz, basebgn, lmp, textrel, 0);
}
if (relbgn >= relend)
break;
rtype = ELF_R_TYPE(((Rel *)relbgn)->r_info, M_MACH);
}
roffset = ((Rel *)relbgn)->r_offset;
/*
* If this is a shared object, add the base address to offset.
*/
if (!(FLAGS(lmp) & FLG_RT_FIXED)) {
/*
* If we're processing lazy bindings, we have to step
* through the plt entries and add the base address
* to the corresponding got entry.
示例15: reloc_non_plt
/* Process the non-PLT relocations. */
int
reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags,
RtldLockState *lockstate)
{
const Elf_Rela *relalim;
const Elf_Rela *rela;
SymCache *cache;
const Elf_Sym *def;
const Obj_Entry *defobj;
Elf_Addr *where, symval;
Elf32_Addr *where32;
int r;
r = -1;
/*
* The dynamic loader may be called from a thread, we have
* limited amounts of stack available so we cannot use alloca().
*/
if (obj != obj_rtld) {
cache = calloc(obj->dynsymcount, sizeof(SymCache));
/* No need to check for NULL here */
} else
cache = NULL;
relalim = (const Elf_Rela *)((caddr_t)obj->rela + obj->relasize);
for (rela = obj->rela; rela < relalim; rela++) {
/*
* First, resolve symbol for relocations which
* reference symbols.
*/
switch (ELF_R_TYPE(rela->r_info)) {
case R_X86_64_64:
case R_X86_64_PC32:
case R_X86_64_GLOB_DAT:
case R_X86_64_TPOFF64:
case R_X86_64_TPOFF32:
case R_X86_64_DTPMOD64:
case R_X86_64_DTPOFF64:
case R_X86_64_DTPOFF32:
def = find_symdef(ELF_R_SYM(rela->r_info), obj,
&defobj, flags, cache, lockstate);
if (def == NULL)
goto done;
/*
* If symbol is IFUNC, only perform relocation
* when caller allowed it by passing
* SYMLOOK_IFUNC flag. Skip the relocations
* otherwise.
*
* Also error out in case IFUNC relocations
* are specified for TLS, which cannot be
* usefully interpreted.
*/
if (ELF_ST_TYPE(def->st_info) == STT_GNU_IFUNC) {
switch (ELF_R_TYPE(rela->r_info)) {
case R_X86_64_64:
case R_X86_64_PC32:
case R_X86_64_GLOB_DAT:
if ((flags & SYMLOOK_IFUNC) == 0) {
obj->non_plt_gnu_ifunc = true;
continue;
}
symval = (Elf_Addr)rtld_resolve_ifunc(
defobj, def);
break;
case R_X86_64_TPOFF64:
case R_X86_64_TPOFF32:
case R_X86_64_DTPMOD64:
case R_X86_64_DTPOFF64:
case R_X86_64_DTPOFF32:
_rtld_error("%s: IFUNC for TLS reloc",
obj->path);
goto done;
}
} else {
if ((flags & SYMLOOK_IFUNC) != 0)
continue;
symval = (Elf_Addr)defobj->relocbase +
def->st_value;
}
break;
default:
if ((flags & SYMLOOK_IFUNC) != 0)
continue;
break;
}
where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
where32 = (Elf32_Addr *)where;
switch (ELF_R_TYPE(rela->r_info)) {
case R_X86_64_NONE:
break;
case R_X86_64_64:
*where = symval + rela->r_addend;
break;
case R_X86_64_PC32:
/*
* I don't think the dynamic linker should
* ever see this type of relocation. But the
//.........這裏部分代碼省略.........