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.

Steps Involved in Compilation
The process of generating object code involves several stages:
- Source Code: The programmer writes the program in a high-level programming language (like C, Java, Python, etc.).
- Lexical Analysis: The compiler performs lexical analysis to break the source code into tokens (keywords, operators, identifiers, etc.).
- Syntax and Semantic Analysis: Compiler checks the structure (syntax) and meaning (semantics) of the code, ensuring that it follows the rules of the language and is logically correct.
- Intermediate Code Generation: The compiler may create an intermediate code that is not machine-specific, providing a way to optimize or analyze the program further. This is often a platform-independent representation.
- Code Generation (Object Code): Finally, the compiler translates the intermediate code into object code, which is machine-level code specific to the target machine architecture but still not fully executable.
Structure of Object Code
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).
Advantages
- Machine Readable: Object code is in binary format and can be processed by the system, but it is not directly executable until it is linked with other object files and libraries to form an executable.
- Architecture Specific: It is designed for a particular processor architecture and must be recompiled for different systems.
- Supports Linking: Multiple object files and libraries can be combined by a linker to form a complete executable program.
- Relocation Support: It contains relocation and symbol information that allows addresses to be adjusted when programs are loaded into memory.
- Optimization and Efficiency: The compiler can optimize object code to improve performance and reduce code size.
- Debugging and Security: It may include debugging information and is harder for humans to read, which helps in debugging while also protecting the source code.
Disadvantages
- Platform Specific: Works only on a particular system architecture and may not run on other platforms.
- Low Readability: Hard for humans to read and understand compared to high-level source code.
- Limited Developer Control: Developers have little control over the final machine instructions generated by the compiler.
- Compatibility Issues: May not always work smoothly with other system components or libraries.
- Larger Size: Contains additional information such as symbols and relocation data, which can increase file size.