Linking & Loading [PDF]

done by hardware; program must be translated into machine instructions, in main memory; example: compilation, linking, a

4 downloads 23 Views 342KB Size

Recommend Stories


[PDF] Adult Learning: Linking Theory and Practice
Keep your face always toward the sunshine - and shadows will fall behind you. Walt Whitman

Linking Students
Sorrow prepares you for joy. It violently sweeps everything out of your house, so that new joy can find

Linking Verbs
Silence is the language of God, all else is poor translation. Rumi

Cross-Linking
Learning never exhausts the mind. Leonardo da Vinci

Loading Shovel
There are only two mistakes one can make along the road to truth; not going all the way, and not starting.

vacuum loading
Suffering is a gift. In it is hidden mercy. Rumi

Loading Systems
We must be willing to let go of the life we have planned, so as to have the life that is waiting for

vehicle loading
Courage doesn't always roar. Sometimes courage is the quiet voice at the end of the day saying, "I will

Pre-Op-CHO-Loading-Guidance_FINAL-FOR-DISTRIBUTION_20160610.pdf, PDF, 181KB
Your task is not to seek for love, but merely to seek and find all the barriers within yourself that

river linking project
What we think, what we become. Buddha

Idea Transcript


up ­

COP4610: Operating Systems & Concurrent Programming

Linking & Loading

Context: Programming Language Implementation Direct Execution done by hardware program must be translated into machine instructions, in main memory example: compilation, linking, and loading of C program Interpretation done by software program is never translated all the way to machine instructions example: interpretation of shell scripts by a shell program example: interpretation of Java byte code by a JVM ultimately depends on a directly executed intepreter program There are various strategies for implementing programming languages. One important division is between direct execution and interpretation. The operating system provides the support for direct execution. Interpreters can be built on that. Compilation, Assembly, Linking and Loading

Before a program can be executed, it must be translated from the programming language in which it was written (source code) to the machine instructions of the hardware that is to execute it, and the executable program must be loaded into main memory. The first phase of the process is translation from source code to machine code. This is done by a compiler or assembler. Of course, the compilation process itself generally is broken into phases. Of these a C programmer needs to be aware of at least three of the phases, because they may detect different kinds of errors. The C preprocessor handles the directives that begin with "#", such as #define, #include, and #ifdef. It expands the #includes and the macro calls. The output is still C source code, but without the preprecessor directives and macro calls. If you use the -E option with gcc, only the preprocessing phase is performed, and the expanded source code is put out. On most Unix systems, the preprocessor can also be invoked using the name cpp. The central part of the compiler (which itself has several internal phases, translates the source code to assembly language. If you use the -S options with gcc, processing stops at the end of this phase, and the assembly language code is put out. The assembler translates the assembly code to machine code, in the form of an object module. An object module is not an entire program. It is a translation of whatever is fed to the compiler (including preprocessor, compiler and assembler). If the compiler is fed just one function subprogram, the object modules contains just the machine code for that one function subprogram. It the gcc compiler is given assembly code as input, it will invoke just the assembly phase. (Using this and the -S option earlier, a person can hand-optimize the translation.) In Unix systems, the assembler usually can also be invoked using the name as. Compilation, Linking and Loading

In order to make a complete program, various separately compiled (and assembled) modules must be combined. This is done by the linker. Finally, the linked program is loaded into memory by the loader. In a Unix operating system, a process invokes the loader by calling one of the exec functions. The loader reads the load module from the specified file into memory, performing any necessary dynamic linkage (see further below) with libraries, and the kernel causes the process that called exec to start executing the new program. The linker is also known as the "linkage editor", because it modifies (edits) the code to link the modules together. In reality, this process is more complicated. In order to be able to share and reuse copies of common code, the system supports object libraries. The archiver (called "ar" in Unix) combines individual object files together into a library. The library is organized with an index, that allows the linker to find individual subprograms quickly. Libraries statically linked dynamically linked shareable Libraries have evolved from a static model to a very dynamic model. The types of libraries correspond to the types of linkers and loaders that operate on them. We will cover each type of library in the context of the corresponding type of linking and/or loading. Static Linker Functions combine object modules into a single load module linkage = replacement of symbolic addresses (relative to other module origins) by absolute addresses if used with an absolute loader by offsets relative to the new load module origin if used with a relocating loader relocation = replacement of addresses relative to local module origin by absolute addresses if used with an absolute loader by offsets relative to the new load module origin if used with a relocating loader The linker does these two main things. The details depend on whether it is preparing a relocatable module or an absolute load module. Example of Static Linkage & Link-Time Relocation: Source Code f.c:

main.c:

int f (int x) { if (x

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.