maven25
maven25

Reputation: 261

What is symbol in the context of Software library and framework development

I have read many documents like "finding correct symbols at runtime" etc. I have researched a bit, but never found a satisfactory answer for what exactly "symbol" refers to. My assumption is that symbols are nothing but the classes, methods, global variables defined in the source code. But why are they called symbols when we are talking from the perspective of libraries and frameworks?

Upvotes: 3

Views: 738

Answers (1)

Matti Virkkunen
Matti Virkkunen

Reputation: 65116

At the simplest level symbols are metadata in compiled code (binaries) that contain information about functions and global data (global variables and readonly data) in the file. Usually a symbol contains a name, address and size. A linker (either a static linker at compile time or a dynamic one at runtime when using DLLs) will use this information to find each function and data object by their name to perform linking.

In low-level languages such as C the customary file formats for machine code (such as ELF) do not contain much more information about functions besides their names and addresses. Other information (parameter count, types, even the calling convention) about the function is stored in separate header files, which must be used together with the correct library versions or very bad things will happen. Things such as C++ classes do not really even exist in compiled code - they get broken down into functions and vtables.

Debugging information may also sometimes be called "symbols" because it's closely related. Symbols also help with debugging by enabling a debugger to find out what function it stopped in or caused an error by comparing the addresses. Debug symbols are extra information about symbols, besides just their name and address, that help a debugger interpret each thing in the code.

In the Microsoft world debug information usually comes in a separate "PDB" file which are sometimes called the "debug symbols", even though they contain more information than traditional symbols. These files would also come with symbols for internal functions and variables, which wouldn't be in the main symbol table because other things don't need to know about them. The reason is to keep the main code file small, and only supply the debugging information when needed (most people don't want to run a debugger).

Upvotes: 4

Related Questions