1

I'm learning ELF, and was given a task to create a custom READELF program in C 32bit linux.

As part of my task, I created pointers to the '.symtab' and the '.strtab' tables, so I could print each symbol name. However, when comparing my output to the original READELF output, I noticed that I'm missing the "@..." part after some of the symbol names.

Where can I find this data?

Yonatan
  • 23
  • 7
  • 1
    Are you asking how to *generate* the symbol from a Linux ELF program written in C (because you have the [tag:c] and [tag:linux] tags), or about the ELF file format? Using GNU C tools, you use the [symver](https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html) function attribute to specify the symbol version; with GNU assembler (as), you use the .symver directive. As to the ELF file format, look at the .gnu.version section (of type SHT_GNU_versym); see [man 5 elf](https://www.man7.org/linux/man-pages/man5/elf.5.html). – Glärbo May 24 '21 at 11:26
  • I think you are asking about how what symbol properties `readelf` is representing with the `@GLIB_XXX` appended to some of the symbol names. That would be symbol *versions*. – John Bollinger May 24 '21 at 11:59
  • @Glärbo - I set up a pointer to the versym table like so: Elf32_Half *versym_table = (Elf32_Half *)((int)header + shdr[versymTableIndex].sh_offset). But given a symbol index, how can I extract its version from te versym table? – Yonatan May 24 '21 at 12:06
  • I haven't written my own ELF file parser, but I do believe the details you need are described in the Linux Standard Base version 1.2, Chapter 6. [Symbol Versioning](https://refspecs.linuxfoundation.org/LSB_1.2.0/gLSB/symversion.html). – Glärbo May 24 '21 at 16:18
  • @Glärbo - I appreciate your help, but I'm still having trouble printing the version name. From the link you attached to your comment, I gathered that I need to access the string table associated with the .gnu.version_d table. However, I couldn't find the relevant offset in the .gnu.version_d table that points to the relevant entry in that string table. – Yonatan May 25 '21 at 10:29
  • @Johnny: the vd_aux field in the .gnu.version_d table entry gives the offset to the Elf32_Verdaux table for that particular entry (and it has vd_cnt entries, because a symbol *can* have multiple versions). In the Elf32_Verdaux table, the vda_name fields in each entry are the offset to the version or dependency name string in the section header, in bytes. Have you considered making a simple single versioned dynamic symbol object file, and tracing it by hand first? – Glärbo May 25 '21 at 10:42

0 Answers0