What is a symbol table?

C++CSymbol Table

C++ Problem Overview


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

C++ Solutions


Solution 1 - C++

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

Solution 2 - C++

Briefly, it is the mapping of the name you assign a variable to its address in memory, including metadata like type, scope, and size. It is used by the compiler.

That's in general, not just C[++]*. Technically, it doesn't always include direct memory address. It depends on what language, platform, etc. the compiler is targeting.

Solution 3 - C++

In Linux, you can use command:

> nm [object file]

to list the symbol table of that object file. From this printout, you may then decipher the in-use linker symbols from their mangled names.

Solution 4 - C++

The symbol table is the list of "symbols" in a program/unit. Symbols are most often the names of variables or functions. The symbol table can be used to determine where in memory variables or functions will be located.

Solution 5 - C++

Check out the Symbol Table wikipedia entry.

Solution 6 - C++

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.

Solution 7 - C++

From the "Computer Systems A Programmer’s Perspective" book, Ch 7 Linking. "Symbols and Symbol Tables":

> Symbol table is information about functions and global variables that > are defined and referenced in the program

And important note (form the same chapter):

> It is important to realize that local linker symbols are not the same > as local program variables. The symbol table does not contain any > symbols that correspond to local nonstatic program variables. These > are managed at run time on the stack and are not of interest to the > linker

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionjdt141View Question on Stackoverflow
Solution 1 - C++Ben CombeeView Answer on Stackoverflow
Solution 2 - C++Steve LandeyView Answer on Stackoverflow
Solution 3 - C++user188276View Answer on Stackoverflow
Solution 4 - C++Joe SchneiderView Answer on Stackoverflow
Solution 5 - C++Allan WindView Answer on Stackoverflow
Solution 6 - C++rashedcsView Answer on Stackoverflow
Solution 7 - C++andreyk2 HohlovView Answer on Stackoverflow