Hi,
Can anybody give me some reference about the ".symtab" section of the ELF file.
I've read the "Tool interface standard specification 1.2" but there is very poor information about that section there.
I'm doing a code generator and I need to know how exactly that section work.
Thanks,
On Wed, 28 Mar 2007, Robe wrote:
> Can anybody give me some reference about the ".symtab" section of the
> ELF file.
>
> I've read the "Tool interface standard specification 1.2" but there is
> very poor information about that section there.
Hmm, what's unclear in there? It does specify the ELF format quite
clearly. If that is not enough, then perhaps reading source code will
help: see /usr/include/elf.h and for instance the sources of readelf (in
binutils), or libelf.
In short: the .symtab section is simply an array of these structs (for
32bit ELF):
typedef struct
{
Elf32_Word st_name; /* Symbol name (string tbl index) */
Elf32_Addr st_value; /* Symbol value */
Elf32_Word st_size; /* Symbol size */
unsigned char st_info; /* Symbol type and binding */
unsigned char st_other; /* Symbol visibility */
Elf32_Section st_shndx; /* Section index */
} Elf32_Sym;
i.e. it's contents make only sense when connected with another section
(.symstr, the strings for all those symbols). Where that connected
section is will be noted in the section header of the .symbtab section
(the sh_link member).
Ciao,
Michael.
> Can anybody give me some reference about the ".symtab" section of the
> ELF file.
>
> I've read the "Tool interface standard specification 1.2" but there is
> very poor information about that section there.
FYI.
We have a some information in the Solaris Linker and Libraries Manual.
Much of this is cut-and-paste from the original SYSV ABI, but there's
some addition "defacto" conventions mentioned.
Look for "Symbol Table Section" and "Symbol Table Layout and
Conventions" in:
http://docs.sun.com/app/docs/doc/817-1984/6mhm7pl28?a=view
Although I'd have to claim this represents the layout and conventions
that Solaris follows, I believe most of the information is generic
to all ELF users.
--
Rod.
> Hmm, what's unclear in there? It does specify the ELF format quite
> clearly. If that is not enough, then perhaps reading source code will
> help: see /usr/include/elf.h and for instance the sources of readelf (in
> binutils), or libelf.
I'm not talking about the understanding of the code of the libelf. I'm
talking about the meaning of each section for the operating system.
That's what I need to know.
> In short: the .symtab section is simply an array of these structs (for
> 32bit ELF):
>
> typedef struct
> {
> Elf32_Word st_name; /* Symbol name (string tbl index) */
> Elf32_Addr st_value; /* Symbol value */
> Elf32_Word st_size; /* Symbol size */
> unsigned char st_info; /* Symbol type and binding */
> unsigned char st_other; /* Symbol visibility */
> Elf32_Section st_shndx; /* Section index */
>
> } Elf32_Sym;
That's right! in fact that's what the TIS says in the documentation.
> i.e. it's contents make only sense when connected with another section
> (.symstr, the strings for all those symbols). Where that connected
> section is will be noted in the section header of the .symbtab section
> (the sh_link member).
Here was my problem. I forgot to update the sh_link member of
the .symtab's section.
Thanks a lot,
Robe.
On Thu, 29 Mar 2007, Robe wrote:
> > Hmm, what's unclear in there? It does specify the ELF format quite
> > clearly. If that is not enough, then perhaps reading source code will
> > help: see /usr/include/elf.h and for instance the sources of readelf
> > (in binutils), or libelf.
>
> I'm not talking about the understanding of the code of the libelf. I'm
> talking about the meaning of each section for the operating system.
Um, I guess I don't see the difference between meaning for operating
system and meaning for anything else. The meaning is defined in context
of the ELF file format, which itself is documented (via TIS and code).
That's why I asked for clarification what your question really was.
> > i.e. it's contents make only sense when connected with another section
> > (.symstr, the strings for all those symbols). Where that connected
> > section is will be noted in the section header of the .symbtab section
> > (the sh_link member).
>
> Here was my problem. I forgot to update the sh_link member of the
> .symtab's section.
That is documented in TIS too (sorry only text reference, so the figure
number might be off):
<cite>
+ Figure 1-13: sh_link and sh_info Interpretation
sh_type sh_link sh_info
======= ======= =======
SHT_DYNAMIC The section header index of 0
the string table used by
entries in the section.
SHT_HASH The section header index of 0
the symbol table to which the
hash table applies.
SHT_REL, The section header index of The section header index of
SHT_RELA the associated symbol table. the section to which the
relocation applies.
SHT_SYMTAB, The section header index of One greater than the symbol
SHT_DYNSYM the associated string table. table index of the last local
symbol (binding STB_LOCAL).
other SHN_UNDEF 0
</cite>
Ciao,
Michael.