![]() |
VOOZH | about |
Object Code is the machine-level code produced by a compiler after translating the source program. It is a low-level binary representation that the computer can understand but is not yet directly executable.
For example, if a programmer writes a program in C language, the compiler first translates it into assembly language, and then the assembler converts the assembly code into object code. This object code is later combined with other object files and libraries by a linker to produce the final executable program.
Thus, object code acts as an intermediate step between compilation and execution.
The process of generating object code involves several stages:
Object code is a binary file that contains machine instructions, but it's not directly executable yet. The object code is typically in a format that can be understood by the computerโs linker (a separate tool that helps to create an executable file). The main elements of object code include:
Header : The header will say what are the various parts present in this object code and then point that parts. So header will say where the text segment is going to start and a pointer to it and where the data segment going to start and it say where the relocation information and symbol information there.
Text segment : This section contains the actual machine instructions generated by the compiler.
Data Sections: Object code may contain sections for data (variables, constants, etc.), including initialized data and uninitialized data (commonly called .data and .bss sections).
Relocation Information: Object code may include information on how addresses should be adjusted during the linking process. Itโs used to modify addresses of variables and functions when combining multiple object files into a single executable.
Let us assume you have instruction 1, instruction 2, instruction 3, instruction 4,....
Now if you say somewhere Goto L4 (Even if you don't write Goto statement in the high-level language, the output of the compiler will write it), then that code will be converted into object code and L4 will be replaced by Goto 4.
Now Goto 4 for the level L4 is going to work fine, as long as the program is going to be loaded starting at address no 0. But in most cases, the initial part of the RAM is going to be dedicated to the operating system. Even if it is not dedicated to the operating system.
Then might be some other process that will already be running at address no 0. So, when you are going to load the program into memory, means if the program has to be loaded in the main memory, it might be loaded anywhere. Let us say 1000 is the new starting address, then all the addresses have to be changed, that is known as Relocation.
Symbol Table: The object code contains a symbol table that keeps track of all the variables, functions, and other symbols used in the program. This table is essential for linking because it helps the linker resolve references to functions or variables that are defined elsewhere (in other object files or libraries).
Debugging Information: Sometimes, object code also contains debugging information, allowing developers to debug the program after compilation (e.g., file names, line numbers, variable names).