Symbol


컴파일러는 함수와 변수명들을 심벌이라는 일종의 기호를 이용해 각 이름들을 처리하고, 바이너리 코드와 데이터를 각 심벌의 관계로 기록한다.

예를 들어 함수 심벌은 각 함수명과 시작 주소, 전체 크기에 대한 정보로 연결된다. 심벌은 보통 링커에 의해 목적 파일들을 결합할 때 활용된다.

In the development process of a program, we often use names to refer toa objects in our code, such as functions or variables that are used all throughout the program. This information is what is known as the program’s symbolic information. Symbolic references in machine code get translated into offsets and addresses on the compilation process.

Symbolic information is exported in order to improve the interpretation of the generated machine code.

A wide range of tools interact with symbols to enforce their functionality. One example of these tools are LinkersLinkers usually interact with a Symbol Table in order to match/reference/modify a given symbol inside an ELF object at linktime. Without Symbols, Linkers would not work, since they won’t know which relocations must take place, and therefore would not have a mechanism to match a given symbolic reference to its corresponding value.

Another example of tools that heavily depend on symbolic information are Debuggers. Without Symbols, the process of Debugging can become considerably harder or even worthless, especially for projects with massive code bases such as the Linux Kernel. Debugging without symbols implies that one has no ability to identify functions or variables by name among other impediments. This would considerably reduce the features afforded by debuggers.

Untitled

C Compilation Process


Untitled

However, in C and C++ names mean something different. If you have a variable named x that contains the value Y, and you use the name "x" in your C program, you are actually referring to the contents of variable x. If "x" is used on the right-hand side of an expression, the compiler fetches the value Y. To realize this variable, the compiler generates a linker symbol named x with the value &x. Even though the C/C++ variable and the linker symbol have the same name, they don't represent the same thing. In C, x is a variable name with the address &x and content Y. For linker symbols, x is an address, and that address contains the value Y.

컴파일