c - getting dynamic symbol table information from elf -
i'm trying dynamic & static symbol table information elf.
that's code wrote:
void symbols(){ int i; elf32_ehdr *header; /* point header structure */ header = (elf32_ehdr *) map_start; elf32_shdr *shdr = (elf32_shdr *)(map_start + header->e_shoff); int shnum = header->e_shnum; const char * str_p =null; elf32_shdr *sh_strtab = &shdr[header->e_shstrndx]; const char *const sh_strtab_p = map_start + sh_strtab->sh_offset; int j; int k; (i = 0; < shnum; ++i) { if ((shdr[i].sh_type == sht_symtab)||(shdr[i].sh_type==sht_dynsym)){ str_p =(char *) shdr[shdr[i].sh_link].sh_offset; elf32_sym *symboler =(elf32_sym *)(map_start + shdr[i].sh_offset); for(j=0;j<(shdr[i].sh_size/shdr[i].sh_entsize);j++){ printf("%u ", symboler->st_size); printf("%x ", symboler->st_value); printf("%u ", symboler->st_shndx); printf("%s\n",(char *) ((int)map_start+ (int)str_p + symboler->st_name)); symboler++; } } } }
the problem dynamic symbol table, example:
0 0 0 0 0 0 __gmon_start__ 0 0 0 __libc_start_main 0 0 0 fopen 0 0 0 fgetc 0 0 0 printf 0 0 0 atoi 4 80485dc 15 _io_stdin_used
when i'm using readelf i'm getting name:
0: 00000000 0 notype local default und 1: 00000000 0 notype weak default und __gmon_start__ 2: 00000000 0 func global default und __libc_start_main@glibc_2.0 (2) 3: 00000000 0 func global default und fopen@glibc_2.1 (3) 4: 00000000 0 func global default und fgetc@glibc_2.0 (2) 5: 00000000 0 func global default und printf@glibc_2.0 (2) 6: 00000000 0 func global default und atoi@glibc_2.0 (2) 7: 080485dc 4 object global default 15 _io_stdin_used
why atoi
in version , atoi@glibc_2.0 (2)
in readelf? how fix this?
readelf
displays information symbol version besides name.
symbol versioning explained here.
symbol versioning - simple explanation
symbol versioning allows library define exported symbols through use of map file. allows 1 library provide multiple versions of same symbol. in past, without symbol versioning, accomplished bumping shared library version (libfoo.so.1, libfoo.so.2, etc.). 1 library version can provide multiple versions of same symbol.
for more details, see this page.
Comments
Post a Comment