I'm currently doing a nm like program, to print the symbols of an ELF file with their addresses and their type.

The typical output is something like :

$ nm ./my_exec      
0000000000003d28 d _DYNAMIC
0000000000003f28 d _GLOBAL_OFFSET_TABLE_
0000000000002000 R _IO_stdin_used
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable

The first column is the symbol address, the second is the symbol type and the third, the symbol name.

The man indicates the meaning for each character, upper-case is a global symbol, lower-case is local symbol etc...

But I don't understand how it choose which character to use.

I'm using the Gelf library and I didn't see a field from where I could determine the character.

1 Answer 1


nm chooses the character mostly based on the section in which the symbol appears. ELF is specified in the System V ABI; pages 4-22 and following describe the symbol table, which include two fields, st_info and st_shndx, and these determine the character shown by nm.

The symbol binding (ELF32_ST_BIND(st_info)) determines whether the symbol is local (lowercase in nm), global (uppercase), or weak (v, w). sh_shndx points to the section containing the symbol, and many of nm’s characters reflect this, either as an explicit section (b, d...), or as a value with special meaning (e.g. u for SHN_UNDEF, undefined symbols).

So you won’t find a single value which directly corresponds to the character shown by nm, but the above should give you enough information to interpret the values described in the ABI specification.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .