Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a symbol table?

Can someone describe what a symbol table is within the context of C and C++?

like image 757
jdt141 Avatar asked Sep 16 '08 03:09

jdt141


People also ask

What do you mean by symbol table?

Symbol table is an important data structure created and maintained by compilers in order to store information about the occurrence of various entities such as variable names, function names, objects, classes, interfaces, etc. Symbol table is used by both the analysis and the synthesis parts of a compiler.

What goes into a symbol table?

Items stored in Symbol table: Variable names and constants. Procedure and function names. Literal constants and strings.

What is a symbol table in Java?

Symbol Table is a data structure that supports an effective and efficient way of storing data about various names occurring in the source code. These names are used in the source code to identify the different program elements, like a variable, constants, procedures, and the labels of statements.


1 Answers

There are two common and related meaning of symbol tables here.

First, there's the symbol table in your object files. Usually, a C or C++ compiler compiles a single source file into an object file with a .obj or .o extension. This contains a collection of executable code and data that the linker can process into a working application or shared library. The object file has a data structure called a symbol table in it that maps the different items in the object file to names that the linker can understand. If you call a function from your code, the compiler doesn't put the final address of the routine in the object file. Instead, it puts a placeholder value into the code and adds a note that tells the linker to look up the reference in the various symbol tables from all the object files it's processing and stick the final location there.

Second, there's also the symbol table in a shared library or DLL. This is produced by the linker and serves to name all the functions and data items that are visible to users of the library. This allows the system to do run-time linking, resolving open references to those names to the location where the library is loaded in memory.

If you want to learn more, I suggest John Levine's excellent book "Linkers and Loaders".link text

like image 61
Ben Combee Avatar answered Sep 23 '22 01:09

Ben Combee