This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: incomplete symtabs via dl_iterate_phdr?
Daniel Jacobowitz wrote:
> On Tue, Jan 02, 2007 at 04:54:59PM +0100, Thomas KÃhne wrote:
>> I am trying to find all global symbols of a programm at runtime
>> from within that very programm. If I use dl_iterate_phdr
>> and search the DT_SYMTAB sections the result is incomplete.
>>
>> source:
>> http://svn.dsource.org/projects/flectioned/trunk/elf2.c
>>
>> That way only 55 symbols are found in libc while
>> "nm --extern-only --defined-only libc.a" returns 2455 symbols.
>>
>> Is there any way to get a list of all defined symbols, their names
>> and addresses at runtime?
>
> nm is looking at the static symbol table, not the global symbol table.
> Compare to nm -D. If you're only getting 55, though, you've got
> something else wrong... assuming you're using a dynamic libc.so.
>
> Why are you using sym->st_value as a loop termination condition?
> That is definitely wrong. I don't believe the size of the symtab
> is available, but you're going to stop at the first undefined symbol.
You are right. I've fix the terminating condition to
symbol->st_shndx == STN_UNDEF
The symbol lists for libc and ld seem to be complete.
The symbols from the executable itself (namely search_dynamic,
search_phdr_info, search_symtab and main) however aren't dynamic and
thus not included. Any idea how to get a list of those?
In the old code I parse the information directly from the binary and use
a crude relocation algorithm that will fail if
1) the binary is executable but nor readable or
2) reading /proc/self/maps is forbidden or
3) some security module shuffles base addresses
Thomas