Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is symbol table and how is it integrated into the executable?

When I tried to debug an executable:

(gdb) break +1
No symbol table is loaded.  Use the "file" command.

What does that mean exactly?

Is the symbol table appended to the executable?

like image 870
user198729 Avatar asked Apr 05 '10 05:04

user198729


People also ask

What is a symbol table in executable?

An object file's symbol table holds information needed to locate and relocate a program's symbolic definitions and symbolic references. A symbol table index is a subscript into this array. Index 0 both designates the first entry in the table and serves as the undefined symbol index.

What is symbol table explain?

In computer science, a symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier (or symbols), constants, procedures and functions in a program's source code is associated with information relating to its declaration or appearance in the source.

What is symbol table in assembler?

The symbol table contains information to locate and relocate symbolic definitions and references. The assembler creates the symbol table section for the object file. It makes an entry in the symbol table for each symbol that is defined or referenced in the input file and is needed during linking.


2 Answers

There are two sets of symbols that gdb uses.

The -g set are debugging symbols, which make things a lot easier as they allow you to see your code and look at variables while debugging.

Another set of symbols is included by default when you compile. These are the linking symbols and live in the ELF (executable linkable format) symbol table. This contains a lot less info than the debug symbols, but contain the most important stuff, such as the addresses of the things in your executable (or library or object file). Without this information gdb won't even know where main is, so (gdb) break main would fail.

If you don't have the debugging symbols ( -g ) then you will still be able to (gdb) break main but you gdb will not have any concept of the lines of code in your source file. When you try to step through the code you will only advance 1 machine instruction at a time, rather than a line at a time.

The strip command is often used to strip off symbols from an executable (or other object file). This is often used if you don't want someone to be able to see the symbols or if you want to save space in the file. Symbol tables can get big. Strip removes both the debug symbols and the linker symbols, but it has several command line switches which can limit what it removes.

If you run the file command on your program one of the things it will tell you is weather or not the executable is has been stripped.

$ gcc my_prog.c -o my_prog
$ file my_prog
my_prog: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
$ strip my_prog
my_prog: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, stripped
$
like image 172
nategoose Avatar answered Sep 23 '22 12:09

nategoose


It's because you didn't compile with debugging turned on. Try gcc -g file.c

like image 31
rkulla Avatar answered Sep 21 '22 12:09

rkulla