Reputation: 945
Create a main.cpp
like this:
int main() {
int a = 1;
int b = 2;
int c = a + b;
int d = c % b;
int e = c + d;
return e;
}
Compile it:
clang++ -g -O0 main.cpp
Then try to see the symbol table:
dsymutil -s a.out
Output looks like this:
----------------------------------------------------------------------
Symbol table for: 'a.out' (arm64)
----------------------------------------------------------------------
Index n_strx n_type n_sect n_desc n_value
======== -------- ------------------ ------ ------ ----------------
[ 0] 00000001 64 (N_SO ) 01 0000 0000000000000000
[ 1] 0000001c 64 (N_SO ) 00 0000 0000000000000000 '/Users/<username>/tmp/'
[ 2] 0000002f 64 (N_SO ) 00 0000 0000000000000000 'main.cpp'
[ 3] 00000038 66 (N_OSO ) 00 0001 0000000065ef7009 '/private/var/folders/75/7ln8mr3j3md23mts9rq7jmcw0000gn/T/main-bf85b7.o'
[ 4] 00000001 2e (N_BNSYM ) 01 0000 0000000100003f4c
[ 5] 00000016 24 (N_FUN ) 01 0000 0000000100003f4c '_main'
[ 6] 00000001 24 (N_FUN ) 00 0000 000000000000005c
[ 7] 00000001 4e (N_ENSYM ) 01 0000 0000000100003f4c
[ 8] 00000001 64 (N_SO ) 01 0000 0000000000000000
[ 9] 00000002 0f ( SECT EXT) 01 0010 0000000100000000 '__mh_execute_header'
[ 10] 00000016 0f ( SECT EXT) 01 0000 0000000100003f4c '_main'
None of the variables are in the symbol table. I wonder why.
Thought about these:
-O0
flag which means no optimization.So I'm out of guesses. Also tried to search stackoverflow for similar questions, didn't see any on the first page of search results. Sorry if this is a dupe.
Upvotes: 1
Views: 181
Reputation: 275190
Symbol names exist for the purpose of linking one library or compilation unit to another. Local variables are not visible over library or compilation unit boundaries. So they never get anywhere close to the symbol table.
Global variables, function names, and some utility stuff like thread local initialization or virtual function table initialization are possible things to end up in symbol tables. Even then it will depend on details of your execution environment.
For debugging purposes, debug information detailing the type and name of stack offsets inside functions can be generated: but that isn't part of the symbol table.
Upvotes: 3