本文整理匯總了C++中ELF32_ST_BIND函數的典型用法代碼示例。如果您正苦於以下問題:C++ ELF32_ST_BIND函數的具體用法?C++ ELF32_ST_BIND怎麽用?C++ ELF32_ST_BIND使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ELF32_ST_BIND函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: DLSYM_lookup_symtab
static BOOL DLSYM_lookup_symtab(const char *sym_name, struct Elf32_Sym *symtab,
Elf32_Word symnum, Elf32_Addr *sym_value,
BOOL require_local_binding)
{
Elf32_Addr sym_idx;
for (sym_idx = 0; sym_idx < symnum; sym_idx++)
{
#if LOADER_DEBUG
if (debugging_on)
DLIF_trace("DLSYM_lookup_symtab %s\n",
(char *)symtab[sym_idx].st_name);
#endif
if ((symtab[sym_idx].st_shndx != SHN_UNDEF) &&
((require_local_binding &&
(ELF32_ST_BIND(symtab[sym_idx].st_info) == STB_LOCAL)) ||
(!require_local_binding &&
(ELF32_ST_BIND(symtab[sym_idx].st_info) != STB_LOCAL))) &&
!strcmp(sym_name,(char*)(symtab[sym_idx].st_name)))
{
if (sym_value) *sym_value = symtab[sym_idx].st_value;
return TRUE;
}
}
if (sym_value) *sym_value = 0;
return FALSE;
}
示例2: dump_SHT_SYMTAB_section
void dump_SHT_SYMTAB_section(void* data, size_t length, int i) {
Elf32_Ehdr* ehdr = (Elf32_Ehdr*)data;
Elf32_Shdr* shdrs = (Elf32_Shdr*)((char*)data + ehdr->e_shoff);
Elf32_Sym* symbols = (Elf32_Sym*)((char*)data + shdrs[i].sh_offset);
int shnum = ehdr->e_shnum;
int shentsize = ehdr->e_shentsize;
int entnum;
unsigned char st_info;
char info[3]; /* local/global/weak, data/function/section/file */
int j;
assert(sizeof(Elf32_Shdr) == ehdr->e_shentsize &&
sizeof(Elf32_Sym) == shdrs[i].sh_entsize);
entnum = shdrs[i].sh_size / shdrs[i].sh_entsize;
assert(entnum > 0);
info[2] = '\0';
printf("entnum=%d\n", entnum);
puts(" [ Nr] value size info other shndx name");
for (j = 0; j < entnum; ++j) {
st_info = symbols[j].st_info;
if (ELF32_ST_BIND(st_info) == STB_LOCAL)
info[0] = 'l';
else if (ELF32_ST_BIND(st_info) == STB_GLOBAL)
info[0] = 'g';
else if (ELF32_ST_BIND(st_info) == STB_WEAK)
info[0] = 'w';
else
info[0] = '?';
if (ELF32_ST_TYPE(st_info) == STT_OBJECT)
info[1] = 'd';
else if (ELF32_ST_TYPE(st_info) == STT_FUNC)
info[1] = 'F';
else if (ELF32_ST_TYPE(st_info) == STT_SECTION)
info[1] = 's';
else if (ELF32_ST_TYPE(st_info) == STT_FILE)
info[1] = 'f';
else if (ELF32_ST_TYPE(st_info) == STT_NOTYPE)
info[1] = ' ';
else
info[1] = '?';
printf(" [%3d] %6d %4d [%2s] %2d %6d %-12s\n",
j,
symbols[j].st_value,
symbols[j].st_size,
info,
symbols[j].st_other,
symbols[j].st_shndx,
(symbols[j].st_name == 0) ? "<UNNAMED>" :
get_str(data, shdrs[i].sh_link, symbols[j].st_name));
}
}
示例3: switch
/**
* Get the binding of a symbol.
* @param infos Information about the symbol.
* @return Binding as a string.
*/
const char *get_binding(const gel_sym_info_t *infos) {
static char buf[32];
switch(ELF32_ST_BIND(infos->info)) {
case STB_LOCAL: return "local";
case STB_GLOBAL: return "global";
case STB_WEAK: return "weak";
default:
sprintf(buf, "%d", ELF32_ST_BIND(infos->info));
return buf;
}
}
示例4: add_global
int add_global( char *name, Elf32_Sym *sym, object *parent )
{
DEBUG(( stderr, "add_global(%s, %p, %p): ", name, sym, parent ));
global *g = root_global;
while( g )
{
if( strcmp( name, g->name ) == 0 ) break;
g = g->next;
}
if( !g )
{
// such global does not yet exists, add to list
g = new global;
g->next = root_global;
root_global = g;
g->name = name;
g->sym = sym;
g->parent = parent;
DEBUG(( stderr, "created global definition of '%s' at %p [weak: %d, value: %d]\n", name, g, ELF32_ST_BIND(sym->st_info) == STB_WEAK, sym->st_value ));
}
else
{
if( ELF32_ST_BIND(g->sym->st_info) == ELF32_ST_BIND(sym->st_info) ) // equal binding
{
if( ELF32_ST_BIND(sym->st_info) == STB_WEAK )
{
DEBUG(( stderr, "duplicate weak symbol, discarding\n" ));
return 0;
}
if( g->sym->st_value == sym->st_value )
{
warning( "global symbol '%s' is redefined in '%s'", name, parent->filename );
return 0;
}
error( "global symbol '%s' defined in '%s' conflicts with global symbol already defined in '%s'", name, parent->filename, g->parent->filename );
return 1;
}
if( ELF32_ST_BIND(sym->st_info) == STB_GLOBAL )
{
g->sym = sym;
g->parent = parent;
DEBUG(( stderr, "replacing old weak definition of '%s' at %p\n", name, g ));
}
}
return 0;
}
示例5: relocate_section_rel
static int
relocate_section_rel(Elf32_Sym *sym_table, Elf32_Rel *rel,
char *target_sect, int nr_reloc, char *strtab)
{
Elf32_Sym *sym;
Elf32_Addr sym_val;
int i;
for (i = 0; i < nr_reloc; i++) {
sym = &sym_table[ELF32_R_SYM(rel->r_info)];
ELFDBG(("%s\n", strtab + sym->st_name));
if (sym->st_shndx != STN_UNDEF) {
sym_val = (Elf32_Addr)sect_addr[sym->st_shndx]
+ sym->st_value;
if (relocate_rel(rel, sym_val, target_sect) != 0)
return -1;
} else if (ELF32_ST_BIND(sym->st_info) != STB_WEAK) {
DPRINTF(("Undefined symbol for rel[%x] sym=%lx\n",
i, (long)sym));
return -1;
} else {
DPRINTF(("Undefined weak symbol for rel[%x]\n", i));
}
rel++;
}
return 0;
}
示例6: pmelf_getsym32
int
pmelf_getsym32(Elf_Stream s, Elf32_Sym *psym)
{
if ( 1 != SREAD(psym, sizeof(*psym), 1, s) ) {
return -1;
}
if ( s->needswap ) {
#ifdef PMELF_CONFIG_NO_SWAPSUPPORT
return -2;
#else
elf_swap32( &psym->st_name);
elf_swap32( &psym->st_value);
elf_swap32( &psym->st_size);
elf_swap16( &psym->st_shndx);
#endif
}
#ifdef PARANOIA_ON
{
int x;
if ( (x = ELF32_ST_TYPE( psym->st_info )) > STT_MAXSUP ) {
PMELF_PRINTF( pmelf_err, PMELF_PRE"pmelf_getsym - paranoia: unsupported type %i\n", x);
return -1;
}
if ( (x = ELF32_ST_BIND( psym->st_info )) > STB_MAXSUP ) {
PMELF_PRINTF( pmelf_err, PMELF_PRE"pmelf_getsym - paranoia: unsupported binding %i\n", x);
return -1;
}
}
#endif
return 0;
}
示例7: gliss_loader_sym
/**
* Get information about a symbol.
* @param loader Current loader.
* @param sym Symbol index.
* @param data Dat structure to store information in.
*/
void gliss_loader_sym(gliss_loader_t *loader, int sym, gliss_loader_sym_t *data) {
assert(sym < gliss_loader_count_syms(loader));
Elf32_Sym *s;
/* get the descriptor */
assert(sym < gliss_loader_count_syms(loader));
s = &loader->Tables.sym_tbl[sym];
/* get name */
data->name = loader->Tables.symstr_tbl + loader->Tables.sym_tbl[sym].st_name;
/* get value and section */
data->value = s->st_value;
data->sect = s->st_shndx;
data->size = s->st_size;
/* get the binding */
switch(ELF32_ST_BIND(s->st_info)) {
case STB_LOCAL: data->bind = GLISS_LOADER_LOCAL; break;
case STB_GLOBAL: data->bind = GLISS_LOADER_GLOBAL; break;
case STB_WEAK: data->bind = GLISS_LOADER_WEAK; break;
default: data->bind = GLISS_LOADER_NO_BINDING; break;
}
/* get the type */
switch(ELF32_ST_TYPE(s->st_info)) {
case STT_FUNC: data->type = GLISS_LOADER_SYM_CODE; break;
case STT_OBJECT: data->type = GLISS_LOADER_SYM_DATA; break;
default: data->type = GLISS_LOADER_SYM_NO_TYPE; break;
}
}
示例8: gelf_getsym
GElf_Sym *
gelf_getsym(Elf_Data *d, int ndx, GElf_Sym *dst)
{
int ec;
Elf *e;
Elf_Scn *scn;
Elf32_Sym *sym32;
Elf64_Sym *sym64;
size_t msz;
uint32_t sh_type;
if (d == NULL || ndx < 0 || dst == NULL ||
(scn = d->d_scn) == NULL ||
(e = scn->s_elf) == NULL) {
LIBELF_SET_ERROR(ARGUMENT, 0);
return (NULL);
}
ec = e->e_class;
assert(ec == ELFCLASS32 || ec == ELFCLASS64);
if (ec == ELFCLASS32)
sh_type = scn->s_shdr.s_shdr32.sh_type;
else
sh_type = scn->s_shdr.s_shdr64.sh_type;
if (_libelf_xlate_shtype(sh_type) != ELF_T_SYM) {
LIBELF_SET_ERROR(ARGUMENT, 0);
return (NULL);
}
msz = _libelf_msize(ELF_T_SYM, ec, e->e_version);
assert(msz > 0);
if (msz * ndx >= d->d_size) {
LIBELF_SET_ERROR(ARGUMENT, 0);
return (NULL);
}
if (ec == ELFCLASS32) {
sym32 = (Elf32_Sym *) d->d_buf + ndx;
dst->st_name = sym32->st_name;
dst->st_value = (Elf64_Addr) sym32->st_value;
dst->st_size = (Elf64_Xword) sym32->st_size;
dst->st_info = ELF64_ST_INFO(ELF32_ST_BIND(sym32->st_info),
ELF32_ST_TYPE(sym32->st_info));
dst->st_other = sym32->st_other;
dst->st_shndx = sym32->st_shndx;
} else {
sym64 = (Elf64_Sym *) d->d_buf + ndx;
*dst = *sym64;
}
return (dst);
}
示例9: dt_module_syminit32
static uint_t
dt_module_syminit32(dt_module_t *dmp)
{
const Elf32_Sym *sym = dmp->dm_symtab.cts_data;
const char *base = dmp->dm_strtab.cts_data;
size_t ss_size = dmp->dm_strtab.cts_size;
uint_t i, n = dmp->dm_nsymelems;
uint_t asrsv = 0;
for (i = 0; i < n; i++, sym++) {
const char *name = base + sym->st_name;
uchar_t type = ELF32_ST_TYPE(sym->st_info);
if (type >= STT_NUM || type == STT_SECTION)
continue; /* skip sections and unknown types */
if (sym->st_name == 0 || sym->st_name >= ss_size)
continue; /* skip null or invalid names */
if (sym->st_value != 0 &&
(ELF32_ST_BIND(sym->st_info) != STB_LOCAL || sym->st_size))
asrsv++; /* reserve space in the address map */
dt_module_symhash_insert(dmp, name, i);
}
return (asrsv);
}
示例10: _dl_do_reloc
static int _dl_do_reloc(struct elf_resolve *tpnt, struct dyn_elf *scope,
Elf32_Rela *rpnt, Elf32_Sym *symtab, char *strtab)
{
int reloc_type;
int symtab_index;
char *symname;
unsigned long *reloc_addr;
unsigned long symbol_addr;
#if defined(__SUPPORT_LD_DEBUG__)
unsigned long old_val;
#endif
reloc_addr = (unsigned long *)(tpnt->loadaddr + rpnt->r_offset);
reloc_type = ELF32_R_TYPE(rpnt->r_info);
symtab_index = ELF32_R_SYM(rpnt->r_info);
symbol_addr = 0;
symname = strtab + symtab[symtab_index].st_name;
if (symtab_index) {
symbol_addr = (unsigned long)
_dl_find_hash(strtab + symtab[symtab_index].st_name,
tpnt->symbol_scope, tpnt,
elf_machine_type_class(reloc_type));
/* Allow undefined references to weak symbols */
if (!symbol_addr &&
ELF32_ST_BIND(symtab[symtab_index].st_info) != STB_WEAK) {
_dl_dprintf(2, "%s: can't resolve symbol '%s'\n",
_dl_progname, symname);
return 0;
}
}
#if defined(__SUPPORT_LD_DEBUG__)
old_val = *reloc_addr;
#endif
switch (reloc_type) {
case R_AVR32_NONE:
break;
case R_AVR32_GLOB_DAT:
case R_AVR32_JMP_SLOT:
*reloc_addr = symbol_addr + rpnt->r_addend;
break;
case R_AVR32_RELATIVE:
*reloc_addr = (unsigned long)tpnt->loadaddr
+ rpnt->r_addend;
break;
default:
return -1;
}
#if defined(__SUPPORT_LD_DEBUG__)
if (_dl_debug_reloc && _dl_debug_detail)
_dl_dprintf(_dl_debug_file, "\tpatched: %x ==> %x @ %x\n",
old_val, *reloc_addr);
#endif
return 0;
}
示例11: print_symbol_info
/*
* ======== print_symbol_info ========
*/
static void print_symbol_info(struct Elf32_Sym *sym)
{
DEBUG_PRINT("Name-Offset = 0x%.8x Value = 0x%.8x Size = 0x%.8x "
"Bind = %d Type = %d Visibility = %d Index = %d\n",
sym->st_name, sym->st_value, sym->st_size,
ELF32_ST_BIND(sym->st_info), ELF32_ST_TYPE(sym->st_info),
sym->st_other, sym->st_shndx);
}
示例12: elf_resolve_symbol
// this function first tries to see if the first image and it's already resolved symbol is okay, otherwise
// it tries to link against the shared_image
// XXX gross hack and needs to be done better
int elf_resolve_symbol(struct elf_image_info *image, struct Elf32_Sym *sym, struct elf_image_info *shared_image, const char *sym_prepend,addr_t *sym_addr)
{
struct Elf32_Sym *sym2;
char new_symname[512];
switch(sym->st_shndx) {
case SHN_UNDEF:
// patch the symbol name
strlcpy(new_symname, sym_prepend, sizeof(new_symname));
strlcat(new_symname, SYMNAME(image, sym), sizeof(new_symname));
// it's undefined, must be outside this image, try the other image
sym2 = elf_find_symbol(shared_image, new_symname);
if(!sym2) {
dprintf("elf_resolve_symbol: could not resolve symbol '%s'\n", new_symname);
return ERR_ELF_RESOLVING_SYMBOL;
}
// make sure they're the same type
if(ELF32_ST_TYPE(sym->st_info) != ELF32_ST_TYPE(sym2->st_info)) {
dprintf("elf_resolve_symbol: found symbol '%s' in shared image but wrong type\n", new_symname);
return ERR_ELF_RESOLVING_SYMBOL;
}
if(ELF32_ST_BIND(sym2->st_info) != STB_GLOBAL && ELF32_ST_BIND(sym2->st_info) != STB_WEAK) {
dprintf("elf_resolve_symbol: found symbol '%s' but not exported\n", new_symname);
return ERR_ELF_RESOLVING_SYMBOL;
}
*sym_addr = sym2->st_value + shared_image->regions[0].delta;
return NO_ERROR;
case SHN_ABS:
*sym_addr = sym->st_value;
return NO_ERROR;
case SHN_COMMON:
// XXX finish this
dprintf("elf_resolve_symbol: COMMON symbol, finish me!\n");
return ERR_NOT_IMPLEMENTED;
default:
// standard symbol
*sym_addr = sym->st_value + image->regions[0].delta;
return NO_ERROR;
}
}
示例13: DLSYM_canonical_lookup
BOOL DLSYM_canonical_lookup(DLOAD_HANDLE handle, int sym_index,
DLIMP_Dynamic_Module *dyn_module,
Elf32_Addr *sym_value)
{
/*------------------------------------------------------------------------*/
/* Lookup the symbol table to get the symbol characteristics. */
/*------------------------------------------------------------------------*/
struct Elf32_Sym *sym = &dyn_module->symtab[sym_index];
int32_t st_bind = ELF32_ST_BIND(sym->st_info);
int32_t st_vis = ELF32_ST_VISIBILITY(sym->st_other);
BOOL is_def = (sym->st_shndx != SHN_UNDEF &&
(sym->st_shndx < SHN_LORESERVE ||
sym->st_shndx == SHN_ABS ||
sym->st_shndx == SHN_COMMON ||
sym->st_shndx == SHN_XINDEX));
const char *sym_name = (char *)sym->st_name;
#if LOADER_DEBUG
if (debugging_on)
DLIF_trace("DLSYM_canonical_lookup: %d, %s\n", sym_index, sym_name);
#endif
/*------------------------------------------------------------------------*/
/* Local symbols and symbol definitions that cannot be pre-empted */
/* are resolved by the definition in the same module. */
/*------------------------------------------------------------------------*/
if (st_bind == STB_LOCAL || st_vis != STV_DEFAULT)
{
/*---------------------------------------------------------------------*/
/* If it is a local symbol or non-local that cannot be preempted, */
/* the definition should be found in the same module. If we don't */
/* find the definition it is an error. */
/*---------------------------------------------------------------------*/
if (!is_def)
{
DLIF_error(DLET_SYMBOL,
"Local/non-imported symbol %s definition is not found "
"in module %s!\n", sym_name, dyn_module->name);
return FALSE;
}
else
{
if (sym_value) *sym_value = sym->st_value;
return TRUE;
}
}
/*------------------------------------------------------------------------*/
/* Else we have either pre-emptable defintion or undef symbol. We need */
/* to do global look up. */
/*------------------------------------------------------------------------*/
else
{
return DLSYM_global_lookup(handle, sym_name, dyn_module->loaded_module,
sym_value);
}
}
示例14: elf_db_search_symbol
db_sym_t
elf_db_search_symbol (db_symtab_t *stab,
db_addr_t off,
db_strategy_t strategy,
db_expr_t *diffp) /* in/out */
{
struct db_symtab_elf *self = (struct db_symtab_elf *) stab;
unsigned long diff = *diffp;
Elf32_Sym *s, *symp = NULL;
for (s = self->start; s < self->end; s++) {
if (s->st_name == 0)
continue;
if (strategy == DB_STGY_XTRN && (ELF32_ST_BIND(s->st_info) != STB_GLOBAL))
continue;
if (off >= s->st_value) {
if (ELF32_ST_TYPE(s->st_info) == STT_FUNC)
continue;
if (off - s->st_value < diff) {
diff = off - s->st_value;
symp = s;
if (diff == 0 && (ELF32_ST_BIND(s->st_info) == STB_GLOBAL))
break;
} else if (off - s->st_value == diff) {
if (symp == NULL)
symp = s;
else if ((ELF32_ST_BIND(symp->st_info) != STB_GLOBAL)
&& (ELF32_ST_BIND(s->st_info) == STB_GLOBAL))
symp = s; /* pick the external symbol */
}
}
}
if (symp == NULL)
*diffp = off;
else
*diffp = diff;
return (db_sym_t) symp;
}
示例15: elf_search_section_sym
static
int elf_search_section_sym(WadFrame *f, char *secname, char *strname) {
int nsymtab;
int nstrtab;
int symtab_size;
Elf32_Sym *sym;
int nsym;
char *str;
int i;
unsigned long vaddr, base;
char *name;
char *localfile = 0;
vaddr = (unsigned long) f->pc;
base = (unsigned long) f->segment->base;
nsymtab = wad_elf_section_byname(f->object,secname);
if (nsymtab < 0) return 0;
nstrtab = wad_elf_section_byname(f->object,strname);
if (nstrtab < 0) return 0;
symtab_size = wad_elf_section_size(f->object,nsymtab);
sym = (Elf32_Sym *) wad_elf_section_data(f->object,nsymtab);
str = (char *) wad_elf_section_data(f->object,nstrtab);
nsym = (symtab_size/sizeof(Elf32_Sym));
for (i = 0; i < nsym; i++) {
name = str + sym[i].st_name;
/* Look for filename in case the symbol maps to a local symbol */
if (ELF32_ST_TYPE(sym[i].st_info) == STT_FILE) {
localfile = name;
}
if (wad_debug_mode & DEBUG_SYMBOL_SEARCH) {
wad_printf("%x(%x): %s %x + %x, %x, %x\n", base, vaddr, name, sym[i].st_value, sym[i].st_size, sym[i].st_info, sym[i].st_shndx);
}
if (((base + sym[i].st_value) <= vaddr) && (vaddr <= (base+sym[i].st_value + sym[i].st_size))) {
#ifdef WAD_LINUX
/* If the section index is 0, the symbol is undefined */
if (sym[i].st_shndx == 0) continue;
#endif
f->sym_name = name;
f->sym_nlen = strlen(name);
f->sym_base = base + sym[i].st_value;
f->sym_size = sym[i].st_size;
if (ELF32_ST_BIND(sym[i].st_info) == STB_LOCAL) {
f->sym_file = localfile;
f->sym_bind = SYM_LOCAL;
} else {
f->sym_bind = SYM_GLOBAL;
}
return 1;
}
}
return 0;
}