Open In App

Introduction of Object Code in Compiler Design

Let assume that, you have a c program, then you give the C program to compiler and compiler will produce the output in assembly code. Now, that assembly language code will give to the assembler and assembler is going to produce you some code. That is known as Object Code

In the context of compiler design, object code is the intermediate code that is generated by the compiler after the syntax analysis, semantic analysis, and optimization stages. Object code is essentially the machine-readable version of the source code, which can be executed directly by the computer’s CPU.



  1. Object code is typically stored in a binary file format, which is specific to the target architecture and operating system. The object code file contains both the executable code and data, as well as information about the program’s symbols and their memory locations.
  2. Object code is generated by the compiler in multiple steps. First, the source code is transformed into an intermediate representation, such as an abstract syntax tree or a three-address code. Then, the intermediate code is optimized to improve the efficiency and speed of the final executable code. Finally, the optimized intermediate code is translated into the target architecture’s machine code, using the appropriate instruction set and addressing modes.
  3. Object code can be linked with other object files to produce a complete executable program. The linking process involves resolving any unresolved external references, such as function calls or global variables, and generating a final executable file that can be run on the target system.

In summary, object code is the machine-readable code that is generated by the compiler, and it serves as an intermediate step between the source code and the final executable code. Object code files are specific to the target architecture and operating system and are typically stored in a binary file format.

But, when you compile a program, then you are not going to use both compiler and assembler. You just take the program and give it to the compiler and compiler will give you the directly executable code. The compiler is actually combined inside the assembler along with loader and linker.So all the module kept together in the compiler software itself. So when you calling gcc, you are actually not just calling the compiler, you are calling the compiler, then assembler, then linker and loader. Once you call the compiler, then your object code is going to present in Hard-disk. This object code contains various part –



Symbol table –

 

Features :

Machine-readable format: Object code is in a format that can be executed directly by the processor without the need for further translation.

Architecture-specific: Object code is specific to a particular processor architecture, so it must be recompiled for other architectures.

Linking: Object code can be linked together with other object files and libraries to create a complete executable program.

Debugging information: Object code can include debugging information, such as line numbers and variable names, to aid in debugging the program.

Relocation information: Object code includes information about the addresses of symbols in the code, allowing the linker to adjust the addresses when the code is linked with other code.

Code optimization: Object code can be optimized by the compiler to improve performance, reduce code size, or both.

Assembly code: Object code can be disassembled into assembly code, which can be useful for understanding how the program works or for reverse engineering.

Advantages:

  1. Efficiency: Object code is optimized for the specific target platform, which can result in more efficient code than would be possible with a high-level language.
  2. Portability: Object code is typically platform-specific, but it can still be portable across different systems that use the same platform. This allows developers to write code once and compile it for multiple target systems.
  3. Debugging: Object code can be easier to debug than source code, as it provides a low-level view of the program’s execution. Developers can use object code to trace the execution of the program and identify errors or issues that may be present.
  4. Protection: Object code can be protected through the use of obfuscation techniques, making it harder for others to reverse engineer the code or steal intellectual property.
  5. Security: Object code is more secure than source code because it is not readable by humans, making it more difficult for attackers to reverse engineer the code.
  6. Interoperability: Object code can be easily linked with other object files to create a complete executable program.

Disadvantages:

  1. Platform-specific: Object code is specific to a particular platform, which means that it may not be compatible with other systems. This can limit the portability of the code and make it harder to deploy across multiple systems.
  2. Limited readability: Object code is a low-level language that is harder to read and understand than source code. This can make it more difficult for developers to maintain and debug the code.
  3. Limited control: Object code is generated by the compiler, and developers have limited control over the resulting code. This can limit the ability to optimize the code or tailor it to specific requirements.
  4. Compatibility issues: Object code can sometimes be incompatible with other components of the system, which can cause errors or performance issues.
  5. Code size: Object code is typically larger than source code because it contains additional information, such as symbols and relocation information.
  6. Licensing: Object code may be subject to licensing restrictions that limit its use and distribution.

Debugging information –

Article Tags :