Where symbol names come from?

In ELF files, symbols reside in two sections: .symtab and .dynsym.
On recent versions of Solaris, there is a new section, .SUNW_ldynsym, but for the purpose of this article it is identical to .dynsym, so I'll keep it simple and not talk about it.

Both sections are essentially tables that map name to a value; here we are interested in function names, so that value would be function address. When pstack unwinds the stack (starting from value of $pc and $fp/$sp registers that comes from special NOTE segment of core file), it goes through symbol tables of all files involved and find symbol with closest value.

For example, suppose we have this core file:

$ pstack core core 'core' of 7719: ./a.out fece586c strlen (8050ada, 8047a38, fed91c20, 0) + c fed40814 printf (8050ad8, 0) + a8 08050969 ???????? (0, 8047b30, 8047a84, 80508bd, 1, 8047a90) 080509a2 main (1, 8047a90, 8047a98, fed93e40) + 12 080508bd _start (1, 8047b98, 0, 8047ba0, 8047bdc, 8047be7) + 7d fece586c address belongs to libc.so.1 as can be seen from pmap(1) output:

$ pmap core core 'core' of 7719: ./a.out 08046000 8K rwx-- [ stack ] 08050000 4K r-x-- 08060000 4K rwx-- 08061000 128K rwx-- [ heap ] >>>FECC0000 760K r-x-- /lib/libc.so.1