Length of ELF dynamic symbol table

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Length of ELF dynamic symbol table

Post 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?
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Length of ELF dynamic symbol table

Post 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.
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Length of ELF dynamic symbol table [SOLVED]

Post 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).
Post Reply