Search code examples
elfsysvlinux-standard-base

LSB 5 forbids having SHT_DYNSYM and SHT_SYMTAB sections both at the same time?


I'm reading up on ELF files from both System V ABI and Linux Standard Base specs. In regard to symbol table sections System V says

Currently, an object file may have only one section of each type, but this restriction may be relaxed in the future. Typically, SHT_SYMTAB provides symbols for link editing, though it may also be used for dynamic linking. As a complete symbol table, it may contain many symbols unnecessary for dynamic linking. Consequently, an object file may also contain a SHT_DYNSYM section, which holds a minimal set of dynamic linking symbols, to save space.

While LSB seems to disallow it explicitly

Currently, an object file may have either a section of SHT_SYMTAB type or a section of SHT_DYNSYM type, but not both. This restriction may be relaxed in the future. Typically, SHT_SYMTAB provides symbols for link editing, though it may also be used for dynamic linking. As a complete symbol table, it may contain many symbols unnecessary for dynamic linking.

So, the parts I've marked in bold directly contradict each other. At the same time, the parts I've italicised are verbatim copy of each other, which makes me suspect that LSB might have made an error (i.e. the bold part) while copying from System V?

Hence my question, which one is correct? Can an object file have both sections at the same time under linux?


Solution

  • The text you referenced appears to be from here.

    It also appears to be totally bogus: it is exceptionally common for an ELF (shared) object to have both SHT_SYMTAB and SHT_DYNSYM sections at the same time. Example:

    echo "int foo() { return 42; }" | gcc -xc - -fPIC -shared -o foo.so
    readelf -WS foo.so | egrep 'SYMTAB|DYNSYM'
    
      [ 3] .dynsym           DYNSYM          0000000000000288 000288 000090 18   A  4   1  8
      [21] .symtab           SYMTAB          0000000000000000 003028 000258 18     22  20  8