Page 1 of 1

Length of ELF dynamic symbol table

Posted: Wed Dec 07, 2011 9:27 pm
by NickJohnson
Hi,

I'm implementing dynamic linking, and I'm having trouble with lookups in the dynamic symbol table. I can't figure out how to determine the number of entries in the table, so I can't prevent myself from running off the end of the table if a symbol is not found in a shared object. The DYNAMIC segment doesn't seem to have any sort of "SYMSZ" or equivalent entry, and I can't look up the size of .dynsym because the object is already loaded into memory (and I assume is no longer guaranteed to have that information; I also wouldn't want to, because it's annoyingly complex to do.) There also doesn't seem to be any sort of terminating entry according to the specification.

How do I determine the length of the table?

Re: Length of ELF dynamic symbol table

Posted: Thu Dec 08, 2011 9:38 am
by NickJohnson
I thought that the section headers were not guaranteed to exist in the loaded image of the shared library, only the segment headers. Isn't that the whole point of the DYNAMIC segment? The segment headers, unlike the section headers, are inadequate for determining the length of the symbol table at runtime, since they only divide the image by memory protection type (R/E vs. R/W).

Edit: I realize that I didn't explicitly say that I was doing lookups on a loaded image of the shared object. I am, and on closer inspection of various offsets, the section headers are most definitely not part of the loaded image.

Re: Length of ELF dynamic symbol table [SOLVED]

Posted: Thu Dec 08, 2011 6:36 pm
by NickJohnson
It seems you are forced to use the hash table for lookups (which is just fine, I suppose); it is in fact impossible to determine the length of the symbol table at runtime (without some sort of unreasonably complex/unreliable hack).