Welcome to graduate2professional.blogspot.com

Tuesday, July 7, 2009

Role of Linker and Loader.

A compiler can be viewed as a program that accepts a source code (such as a Java program) and generates machine code for some computer architecture.

Soon after The compiler generates machine code, it is written in an object file.

An object file contains:

–Code (for methods, etc.)
–Variables (e.g., values for global variables)
–Debugging information
–References to code and data that appear elsewhere (e.g., printf)
–Tables for organizing the above.

This file is not executable since it may refer to external symbols (such as system calls).The operating system provides the following utilities to execute the code:

1.linking: A linker takes several object files and libraries as input and produces one executable object file. It retrieves from the input files (and puts them together in the executable object file) the code of all the referenced functions/procedures and it resolves all external references to real addresses. The libraries include the operating sytem libraries, the language-specific libraries, and, maybe, user-created libraries.

"Linking is simply the process of placing the address of a called function into the calling function's code. This is a fundamental software concept."

2.loading: A loader loads an executable object file into memory, initializes the registers, heap, data, etc and starts the execution of the program.

Linkers vs. Loaders:

Linkers and loaders perform various related but conceptually different tasks:

Program Loading: This refers to copying a program image from hard disk to the main memory in order to put the program in a ready-to-run state. In some cases, program loading also might involve allocating storage space or mapping virtual addresses to disk pages.

Relocation:
Compilers and assemblers generate the object code for each input module with a starting address of zero. Relocation is the process of assigning load addresses to different parts of the program by merging all sections of the same type into one section. The code and data section also are adjusted so they point to the correct runtime addresses.

Symbol Resolution: A program is made up of multiple subprograms; reference of one subprogram to another is made through symbols. A linker's job is to resolve the reference by noting the symbol's location and patching the caller's object code.

No comments:

Post a Comment