本文整理汇总了C++中ELF_ST_BIND函数的典型用法代码示例。如果您正苦于以下问题:C++ ELF_ST_BIND函数的具体用法?C++ ELF_ST_BIND怎么用?C++ ELF_ST_BIND使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ELF_ST_BIND函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compute_unresolved_hash
static void compute_unresolved_hash(struct elf_info *elf)
{
Elf_Sym *sym;
ksym_hash_t *hash_values = elf->undef_hash.start;
if (!hash_values)
/* .undef.hash section is not present */
return;
for (sym = elf->symtab_start; sym < elf->symtab_stop; sym++) {
if (sym->st_shndx == SHN_UNDEF) {
/* undefined symbol */
if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL &&
ELF_ST_BIND(sym->st_info) != STB_WEAK)
continue;
else {
/* GLOBAL or WEAK undefined symbols */
*hash_values = gnu_hash((unsigned char *)
(elf->strtab + sym->st_name));
/*
* The hash_values array stored into the
* .undef.hash section that is ordered as the
* undefined symbols of the .symtab
*/
hash_values++;
}
}
}
}
示例2: elf_sym_to_nlist
/*
* Convert an Elf_Sym into an nlist structure. This fills in only the
* n_value and n_type members.
*/
static void
elf_sym_to_nlist(struct nlist *nl, Elf_Sym *s, Elf_Shdr *shdr, int shnum)
{
nl->n_value = s->st_value;
switch (s->st_shndx) {
case SHN_UNDEF:
case SHN_COMMON:
nl->n_type = N_UNDF;
break;
case SHN_ABS:
nl->n_type = ELF_ST_TYPE(s->st_info) == STT_FILE ?
N_FN : N_ABS;
break;
default:
if (s->st_shndx >= shnum)
nl->n_type = N_UNDF;
else {
Elf_Shdr *sh = shdr + s->st_shndx;
nl->n_type = sh->sh_type == SHT_PROGBITS ?
(sh->sh_flags & SHF_WRITE ? N_DATA : N_TEXT) :
(sh->sh_type == SHT_NOBITS ? N_BSS : N_UNDF);
}
break;
}
if (ELF_ST_BIND(s->st_info) == STB_GLOBAL ||
ELF_ST_BIND(s->st_info) == STB_WEAK)
nl->n_type |= N_EXT;
}
示例3: link_elf_reloc_local
static void
link_elf_reloc_local(linker_file_t lf)
{
elf_file_t ef = (elf_file_t)lf;
const Elf_Rel *rellim;
const Elf_Rel *rel;
const Elf_Rela *relalim;
const Elf_Rela *rela;
const Elf_Sym *sym;
Elf_Addr base;
int i;
Elf_Size symidx;
link_elf_fix_link_set(ef);
/* Perform relocations without addend if there are any: */
for (i = 0; i < ef->nreltab; i++) {
rel = ef->reltab[i].rel;
if (rel == NULL)
panic("lost a reltab!");
rellim = rel + ef->reltab[i].nrel;
base = findbase(ef, ef->reltab[i].sec);
if (base == 0)
panic("lost base for reltab");
for ( ; rel < rellim; rel++) {
symidx = ELF_R_SYM(rel->r_info);
if (symidx >= ef->ddbsymcnt)
continue;
sym = ef->ddbsymtab + symidx;
/* Only do local relocs */
if (ELF_ST_BIND(sym->st_info) != STB_LOCAL)
continue;
elf_reloc_local(lf, base, rel, ELF_RELOC_REL,
elf_obj_lookup);
}
}
/* Perform relocations with addend if there are any: */
for (i = 0; i < ef->nrelatab; i++) {
rela = ef->relatab[i].rela;
if (rela == NULL)
panic("lost a relatab!");
relalim = rela + ef->relatab[i].nrela;
base = findbase(ef, ef->relatab[i].sec);
if (base == 0)
panic("lost base for relatab");
for ( ; rela < relalim; rela++) {
symidx = ELF_R_SYM(rela->r_info);
if (symidx >= ef->ddbsymcnt)
continue;
sym = ef->ddbsymtab + symidx;
/* Only do local relocs */
if (ELF_ST_BIND(sym->st_info) != STB_LOCAL)
continue;
elf_reloc_local(lf, base, rela, ELF_RELOC_RELA,
elf_obj_lookup);
}
}
}
示例4: wantsym
static bool
wantsym(const Elf_Sym *sym, const char *strtab)
{
int type;
int bind;
type = ELF_ST_TYPE(sym->st_info);
bind = ELF_ST_BIND(sym->st_info);
if (type != STT_FUNC || (aflag && bind == STB_LOCAL))
#if 0
||
(uflag && strchr(strtab + sym->st_name, '.') != NULL))
#endif
return 0;
#ifdef __arm__
/* ignore what gas calls "mapping symbols" */
{
const char *c = strtab + sym->st_name;
if (c[0] == '$')
return 0;
}
#endif
return 1;
}
示例5: get_sym
Elf32_Sym *mips_elf_find_address(struct mips_cpu *pcpu, Elf32_Addr addr)
{
Elf32_Shdr *shsymtab = pcpu->shsymtab;
unsigned n = shsymtab->sh_size / shsymtab->sh_entsize;
Elf32_Addr min = (unsigned)-1;
Elf32_Sym *ret = NULL;
unsigned i;
if((shsymtab->sh_offset + shsymtab->sh_size > pcpu->elfsz)
|| (addr >= pcpu->memsz))
return NULL;
for(i = 0; i < n; i++) {
Elf32_Sym *sym = get_sym(pcpu->elf, pcpu->elfsz, shsymtab, i);
if(!sym)
return NULL;
if((ELF_ST_BIND(sym->st_info) != STB_GLOBAL) ||
(ELF_ST_TYPE(sym->st_info) >= STT_SECTION))
continue;
if(sym->st_value <= addr) {
Elf32_Addr diff = addr - sym->st_value;
if(diff < min) {
min = diff;
ret = sym;
if(diff == 0)
break;
}
}
}
return ret;
}
示例6: sym7
int sym7(void)
{
if(ELF_ST_TYPE(orcSYM->st_info) != STT_FILE)
return 0;
if(mode & REL)
if(rand() % 2)
return 0;
unsigned char st_info = orcSYM->st_info;
Elf_Section st_shndx;
if(rand() % 2)
do
st_info = ELF_ST_INFO(rand() & 0x0f, STT_FILE);
while(ELF_ST_BIND(st_info) == STB_LOCAL);
if(rand() % 4 < 3){
while((st_shndx = rand() % orcHDR->e_shnum))
if(st_shndx != SHN_ABS)
break;
} else
while((st_shndx = getElf_Section()))
if(st_shndx != SHN_ABS)
break;
orcSYM->st_info = st_info;
orcSYM->st_shndx = st_shndx;
fprintf(logfp, "(SYM[%d]->st_info = 0x%.2x,", entry, orcSYM->st_info);
fprintf(logfp, " st_shndx = 0x%x)", orcSYM->st_shndx);
return 1;
}
示例7: generic_get_symbol
bool
generic_get_symbol( Elf_Xword index,
std::string& name, Elf64_Addr& value,
Elf_Xword& size,
unsigned char& bind, unsigned char& type,
Elf_Half& section_index,
unsigned char& other ) const
{
bool ret = false;
if ( index < get_symbols_num() ) {
const T* pSym = reinterpret_cast<const T*>(
symbol_section->get_data() +
index * symbol_section->get_entry_size() );
const endianess_convertor& convertor = elf_file.get_convertor();
section* string_section = elf_file.sections[get_string_table_index()];
string_section_accessor str_reader( string_section );
const char* pStr = str_reader.get_string( convertor( pSym->st_name ) );
if ( 0 != pStr ) {
name = pStr;
}
value = convertor( pSym->st_value );
size = convertor( pSym->st_size );
bind = ELF_ST_BIND( pSym->st_info );
type = ELF_ST_TYPE( pSym->st_info );
section_index = convertor( pSym->st_shndx );
other = pSym->st_other;
ret = true;
}
return ret;
}
示例8: elf_obj_lookup
/*
* Symbol lookup function that can be used when the symbol index is known (ie
* in relocations). It uses the symbol index instead of doing a fully fledged
* hash table based lookup when such is valid. For example for local symbols.
* This is not only more efficient, it's also more correct. It's not always
* the case that the symbol can be found through the hash table.
*/
static Elf_Addr
elf_obj_lookup(linker_file_t lf, Elf_Size symidx, int deps)
{
elf_file_t ef = (elf_file_t)lf;
Elf_Sym *sym;
const char *symbol;
Elf_Addr ret;
/* Don't even try to lookup the symbol if the index is bogus. */
if (symidx >= ef->ddbsymcnt)
return (0);
sym = ef->ddbsymtab + symidx;
/* Quick answer if there is a definition included. */
if (sym->st_shndx != SHN_UNDEF)
return (sym->st_value);
/* If we get here, then it is undefined and needs a lookup. */
switch (ELF_ST_BIND(sym->st_info)) {
case STB_LOCAL:
/* Local, but undefined? huh? */
return (0);
case STB_GLOBAL:
/* Relative to Data or Function name */
symbol = ef->ddbstrtab + sym->st_name;
/* Force a lookup failure if the symbol name is bogus. */
if (*symbol == 0)
return (0);
ret = ((Elf_Addr)linker_file_lookup_symbol(lf, symbol, deps));
/*
* Cache global lookups during module relocation. The failure
* case is particularly expensive for callers, who must scan
* through the entire globals table doing strcmp(). Cache to
* avoid doing such work repeatedly.
*
* After relocation is complete, undefined globals will be
* restored to SHN_UNDEF in elf_obj_cleanup_globals_cache(),
* above.
*/
if (ret != 0) {
sym->st_shndx = SHN_FBSD_CACHED;
sym->st_value = ret;
}
return (ret);
case STB_WEAK:
printf("link_elf_obj: Weak symbols not supported\n");
return (0);
default:
return (0);
}
}
示例9: kobj_sym_lookup
/*
* kobj_sym_lookup:
*
* Symbol lookup function to be used when the symbol index
* is known (ie during relocation).
*/
uintptr_t
kobj_sym_lookup(kobj_t ko, uintptr_t symidx)
{
const Elf_Sym *sym;
const char *symbol;
int error;
u_long addr;
/* Don't even try to lookup the symbol if the index is bogus. */
if (symidx >= ko->ko_symcnt)
return 0;
sym = ko->ko_symtab + symidx;
/* Quick answer if there is a definition included. */
if (sym->st_shndx != SHN_UNDEF) {
return sym->st_value;
}
/* If we get here, then it is undefined and needs a lookup. */
switch (ELF_ST_BIND(sym->st_info)) {
case STB_LOCAL:
/* Local, but undefined? huh? */
kobj_error("local symbol undefined");
return 0;
case STB_GLOBAL:
/* Relative to Data or Function name */
symbol = ko->ko_strtab + sym->st_name;
/* Force a lookup failure if the symbol name is bogus. */
if (*symbol == 0) {
kobj_error("bad symbol name");
return 0;
}
/*
* Don't need to lock, as it is known that the symbol
* tables aren't going to change (we hold module_lock).
*/
error = ksyms_getval(NULL, symbol, &addr, KSYMS_ANY);
if (error != 0) {
kobj_error("symbol `%s' not found", symbol);
return (uintptr_t)0;
}
return (uintptr_t)addr;
case STB_WEAK:
kobj_error("weak symbols not supported\n");
return 0;
default:
return 0;
}
}
示例10: parse_elf_symbols
static void parse_elf_symbols(uintptr_t mem, size_t size, Phdr_t *load,
struct vdso_symtable *t, uintptr_t dynsymbol_names,
Hash_t *hash, Dyn_t *dyn_symtab)
{
const char *vdso_symbols[VDSO_SYMBOL_MAX] = {
ARCH_VDSO_SYMBOLS
};
const size_t vdso_symbol_length = sizeof(t->symbols[0].name);
Hash_t nbucket, nchain;
Hash_t *bucket, *chain;
unsigned int i, j, k;
uintptr_t addr;
nbucket = hash[0];
nchain = hash[1];
bucket = &hash[2];
chain = &hash[nbucket + 2];
pr_debug("nbucket %lx nchain %lx bucket %lx chain %lx\n",
(long)nbucket, (long)nchain, (unsigned long)bucket, (unsigned long)chain);
for (i = 0; i < VDSO_SYMBOL_MAX; i++) {
const char * symbol = vdso_symbols[i];
k = elf_hash((const unsigned char *)symbol);
for (j = bucket[k % nbucket]; j < nchain && chain[j] != STN_UNDEF; j = chain[j]) {
addr = mem + dyn_symtab->d_un.d_ptr - load->p_vaddr;
Sym_t *sym;
char *name;
addr += sizeof(Sym_t)*j;
if (__ptr_struct_oob(addr, sizeof(Sym_t), mem, size))
continue;
sym = (void *)addr;
if (ELF_ST_TYPE(sym->st_info) != STT_FUNC &&
ELF_ST_BIND(sym->st_info) != STB_GLOBAL)
continue;
addr = dynsymbol_names + sym->st_name;
if (__ptr_struct_oob(addr, vdso_symbol_length, mem, size))
continue;
name = (void *)addr;
if (std_strncmp(name, symbol, vdso_symbol_length))
continue;
memcpy(t->symbols[i].name, name, vdso_symbol_length);
t->symbols[i].offset = (unsigned long)sym->st_value - load->p_vaddr;
break;
}
}
}
示例11: simplify_symbols
static int simplify_symbols(struct secthdr *sechdrs,
unsigned int symindex,
const char *strtab,
unsigned int versindex,
unsigned int pcpuindex, struct module *mod)
{
struct symtab_s *sym = (void *)sechdrs[symindex].sh_addr;
unsigned long secbase;
unsigned int i, n = sechdrs[symindex].sh_size / sizeof(struct symtab_s);
int ret = 0;
const struct kernel_symbol *ksym;
for (i = 1; i < n; i++) {
switch (sym[i].st_shndx) {
case SHN_COMMON:
/* We compiled with -fno-common. These are not supposed to happen. */
kprintf("simplify_symbols: Common symbol: %s\n",
strtab + sym[i].st_name);
kprintf("%s: please compile with -fno-common\n",
mod->name);
ret = -1;
break;
case SHN_ABS:
/* Don't need to do anything */
kprintf("simplify_symbols: Absolute symbol: 0x%08lx\n",
(long)sym[i].st_value);
break;
case SHN_UNDEF:
ksym =
resolve_symbol(sechdrs, versindex,
strtab + sym[i].st_name, mod);
/* Ok if resolved. */
if (ksym) {
sym[i].st_value = ksym->value;
break;
}
/* Ok if weak. */
if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK)
break;
kprintf("simplify_symbols: Unknown symbol %s\n",
strtab + sym[i].st_name);
ret = -1;
break;
default:
if (sym[i].st_shndx == pcpuindex)
secbase = (unsigned long)mod->percpu;
else
secbase = sechdrs[sym[i].st_shndx].sh_addr;
sym[i].st_value += secbase;
break;
}
}
return ret;
}
示例12: wantsym
static bool
wantsym(const Elf_Sym *sym, const char *strtab)
{
int type;
int bind;
type = ELF_ST_TYPE(sym->st_info);
bind = ELF_ST_BIND(sym->st_info);
if (type != STT_FUNC ||
(aflag && bind == STB_LOCAL) ||
(uflag && strchr(strtab + sym->st_name, '.') != NULL))
return 0;
return 1;
}
示例13:
static Elf_Sym *kexec_purgatory_find_symbol(struct purgatory_info *pi,
const char *name)
{
Elf_Sym *syms;
Elf_Shdr *sechdrs;
Elf_Ehdr *ehdr;
int i, k;
const char *strtab;
if (!pi->sechdrs || !pi->ehdr)
return NULL;
sechdrs = pi->sechdrs;
ehdr = pi->ehdr;
for (i = 0; i < ehdr->e_shnum; i++) {
if (sechdrs[i].sh_type != SHT_SYMTAB)
continue;
if (sechdrs[i].sh_link >= ehdr->e_shnum)
/* Invalid strtab section number */
continue;
strtab = (char *)sechdrs[sechdrs[i].sh_link].sh_offset;
syms = (Elf_Sym *)sechdrs[i].sh_offset;
/* Go through symbols for a match */
for (k = 0; k < sechdrs[i].sh_size/sizeof(Elf_Sym); k++) {
if (ELF_ST_BIND(syms[k].st_info) != STB_GLOBAL)
continue;
if (strcmp(strtab + syms[k].st_name, name) != 0)
continue;
if (syms[k].st_shndx == SHN_UNDEF ||
syms[k].st_shndx >= ehdr->e_shnum) {
pr_debug("Symbol: %s has bad section index %d.\n",
name, syms[k].st_shndx);
return NULL;
}
/* Found the symbol we are looking for */
return &syms[k];
}
}
return NULL;
}
示例14: dlsym
void* dlsym(void* handle, const char* symbol) {
ScopedPthreadMutexLocker locker(&g_dl_mutex);
#if !defined(__LP64__)
if (handle == NULL) {
__bionic_format_dlerror("dlsym library handle is null", NULL);
return NULL;
}
#endif
if (symbol == NULL) {
__bionic_format_dlerror("dlsym symbol name is null", NULL);
return NULL;
}
soinfo* found = NULL;
ElfW(Sym)* sym = NULL;
if (handle == RTLD_DEFAULT) {
sym = dlsym_linear_lookup(symbol, &found, NULL);
} else if (handle == RTLD_NEXT) {
void* caller_addr = __builtin_return_address(0);
soinfo* si = find_containing_library(caller_addr);
sym = NULL;
if (si && si->next) {
sym = dlsym_linear_lookup(symbol, &found, si->next);
}
} else {
found = reinterpret_cast<soinfo*>(handle);
sym = dlsym_handle_lookup(found, symbol);
}
if (sym != NULL) {
unsigned bind = ELF_ST_BIND(sym->st_info);
if ((bind == STB_GLOBAL || bind == STB_WEAK) && sym->st_shndx != 0) {
return reinterpret_cast<void*>(sym->st_value + found->load_bias);
}
__bionic_format_dlerror("symbol found but not global", symbol);
return NULL;
} else {
__bionic_format_dlerror("undefined symbol", symbol);
return NULL;
}
}
示例15: kobj_checkdup
/*
* kobj_checkdup:
*
* Scan symbol table for duplicates.
*/
static int
kobj_checkdup(kobj_t ko)
{
unsigned long rval;
Elf_Sym *sym, *ms;
const char *name;
bool dup;
dup = false;
for (ms = (sym = ko->ko_symtab) + ko->ko_symcnt; sym < ms; sym++) {
/* Check validity of the symbol. */
if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL ||
sym->st_name == 0)
continue;
/* Check if the symbol already exists */
name = ko->ko_strtab + sym->st_name;
if (ksyms_getval(NULL, name, &rval, KSYMS_EXTERN) != 0) {
continue;
}
/* Check (and complain) about differing values */
if (sym->st_value == rval || sym->st_shndx == SHN_UNDEF) {
continue;
}
if (strcmp(name, "_bss_start") == 0 ||
strcmp(name, "__bss_start") == 0 ||
strcmp(name, "_bss_end__") == 0 ||
strcmp(name, "__bss_end__") == 0 ||
strcmp(name, "_edata") == 0 ||
strcmp(name, "_end") == 0 ||
strcmp(name, "__end") == 0 ||
strcmp(name, "__end__") == 0 ||
strncmp(name, "__start_link_set_", 17) == 0 ||
strncmp(name, "__stop_link_set_", 16)) {
continue;
}
kobj_error("global symbol `%s' redefined\n", name);
dup = true;
}
return dup ? EEXIST : 0;
}