CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 –Linkers.

Slides:



Advertisements
Similar presentations
Loaders Dr. Monther Aldwairi 10/21/2007 Dr. Monther Aldwairi.
Advertisements

1 Loaders and Linkers Chapter 3 System Software An introduction to systems programming Leland L. Beck.
1 Loaders and Linkers Chapter 3 System Software An introduction to systems programming Leland L. Beck.
Chapter 3 Loaders and Linkers
Linkage Editors Difference between a linkage editor and a linking loader: Linking loader performs all linking and relocation operations, including automatic.
3. Loaders & Linkers1 Chapter III: Loaders and Linkers Chapter goal: r To realize how a source program be loaded into memory m Loading m Relocation m Linking.
Chapter 3 Loaders and Linkers
COP 3402 Systems Programming Dr. Ali Orooji School of EECS University of Central Florida.
Chapter 3 Loaders and Linkers. Purpose and Function Places object program in memory Linking – Combines 2 or more obj programs Relocation – Allows loading.
Loaders and Linkers CS 230 이준원. 2 Overview assembler –generates an object code in a predefined format »COFF (common object file format) »ELF (executable.
SYSTEM PROGRAMMING & SYSTEM ADMINISTRATION
Machine Independent Assembler Features
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Loaders and Linkers Object Program contains the information:
Chapter 3 System Software
Machine-Independent Loader Features
Chap 3 Loaders and Linkers. Object program contains translated instructions and data values from the source program. Loading, which brings the object.
1 Machine-Independent Features Automatic Library Search automatically incorporate routines from a subprogram library Loading Options.
CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University.
CS2422 Assembly Language & System Programming January 2, 2007.
Assembler – Assembler Design Options. One-Pass Assemblers (1/2) Main problem  Forward references Data items Labels on instructions Solution  Data items:
Loader- Machine Independent Loader Features
CS2422 Assembly Language & System Programming December 22, 2005.
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
An introduction to systems programming
1 Chapter 3 Loaders and Linkers Source Program Assembler Object Code Loader Executable Code Linker.
Loader- Machine Dependent Loader Features
Machine-Independent Assembler Features
Assembler – Machine Independent Features. Literals Design idea  Let programmers to be able to write the value of a constant operand as a part of the.
CS2422 Assembly Language & System Programming December 14, 2006.
A Simple Two-Pass Assembler
Chapter 1 Computer architecture Languages: machine, assembly, high
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Machine-Independent Assembler Features Literals, Symbol-Defining Statements, Expressions, Program Blocks, Control Sections and Program Linking.
2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.
L ECTURE -9 Topics : Compiler Interpreter Loader Linker. Types of Software..
Loader and Linker.
Linking Loader untuk SIC/XE Machine. Lebih Lanjut mengenai Absolute Loader Shortcoming of an absolute loader –Programmer needs to specify the actual address.
UNIT III LOADERS AND LINKERS. This Unit gives you… Basic Loader Functions Machine-Dependent Loader Features Machine-Independent Loader Feature Loader.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 – Loaders.
Loaders and Linkers T 李俊葦. 1. Loader Accepts the object programs , prepares these programs for execution by the computer , and indicates the execution.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 4 - Assembler 1.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 9 - Assembler 4.
CC410: System Programming
Lecture 3 Translation.
Machine dependent Assembler Features
Computer Science 210 Computer Organization
CC410: System Programming
System Programming and administration
Separate Assembly allows a program to be built from modules rather than a single source file assembler linker source file.
Assembler Design Options
Computer Science 210 Computer Organization
Loaders and Linkers CSCI/CMPE 3334 David Egle.
Loaders and Linkers: Features
Machine Independent Features
Loaders and Linkers.
Memory Management Tasks
A Simple Two-Pass Assembler
Optional Assembler Features 2
System Programming by Leland L. Beck Chapter 2
Machine Independent Assembler Features
Loaders and Linkers.
Chapter 1 Computer architecture Languages: machine, assembly, high
Machine Independent Assembler Features
An introduction to systems programming
UNIT III LOADERS AND LINKERS
Chapter 3 Loaders and Linkers
Presentation transcript:

CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 –Linkers

2 Learning Objectives Understand Linker Functions Differentiate between Machine Dependant and Independent Functions 2 Source Program Assembler Object Code Loader Executable Code Linker

Program Linking »In Section showed a program made up of three controls sections. –Assembled together or assembled independently? »Goal Resolve the problems with EXTREF and EXTDEF from different control sections »Linking –1. User, 2. Assembler, 3. Linking loader »Example –Program in Fig.3.8 and object code in Fig.3.9 –Use modification records for both relocation and linking address constant external reference

Program Linking Example

Program Linking »Consider the three programs in Fig. 3.8 and 3.9. –Each of which consists of a single control section. –A list of items, LISTA---ENDA, LISTB---ENDB, LISTC--- ENDC. –Note that each program contains exactly the same set of references to these external symbols. –Instruction operands (REF1, REF2, REF3). –The values of data words (REF4 through REF8). –Not involved in the relocation and linking are omitted.

6

7

8

9

10

11

Program Linking »REF1, LDA LISTA 03201D –In the PROGA, REF1 is simply a reference to a label. –In the PROGB and PROGC, REF1 is a reference to an external symbols. –Need to use extended format, Modification record. »REF2 and REF3. LDTLISTB LDX#ENDA-LISTA

Program Linking »REF4 through REF8, –WORD ENDA-LISTA+LISTC »Figure 3.10(a) and 3.10(b) –Shows these three programs as they might appear in memory after loading and linking. –PROGA , PROGB , PROGC 0040E2. –REF4 through REF8 in the same value. –For the references that are instruction operands, the calculated values after loading do not always appear to be equal. –Target address, REF

14

15

16

Algorithm and Data Structure for a Linking Loader »A linking loader usually makes two passes –Pass 1 assigns addresses to all external symbols. –Pass 2 performs the actual loading, relocation, and linking. –The main data structure is ESTAB (hashing table).

Algorithm and Data Structure for a Linking Loader »A linking loader usually makes two passes –ESTAB is used to store the name and address of each external symbol in the set of control sections being loaded. –Two variables PROGADDR and CSADDR. –PROGADDR is the beginning address in memory where the linked program is to be loaded. –CSADDR contains the starting address assigned to the control section currently being scanned by the loader.

Algorithm and Data Structure for a Linking Loader »The linking loader algorithm, Fig 3.11(a) & (b). –In Pass 1, concerned only Header and Defined records. –CSADDR+CSLTH = the next CSADDR. –A load map is generated. –In Pass 2, as each Text record is read, the object code is moved to the specified address (plus the current value of CSADDR). –When a Modification record is encountered, the symbol whose value is to be used for modification is looked up in ESTAB. –This value is then added to or subtracted from the indicated location in memory.

21

22

Machine-Independent Loader Features Automatic Library Search »Many linking loaders can automatically incorporate routines form a subprogram library into the program being loaded. –A standard system library –Other libraries may be specified by control statements or by parameters to the loader »Also called automatic library call in some systems

3.3.1 Automatic Library Search Implementation »Linking loaders that support automatic library search must keep track of external symbols that are referred to, but not defined, in the primary input to the loader –At the end of Pass 1, the symbols in ESTAB that remain undefined represented unresolved external references –Then, the loader searches the library or libraries specified for routines that contain the definitions of these symbols –Note that the subroutines fetched from a library in this way may themselves contain external references. It is therefore necessary to repeat the library search process until all reference are resolved. –The process allows the programmer to override the standard subroutines in the library by supplying his or her own routines

»The libraries to be searched by the loader ordinarily contain assembled or compiled versions of the subroutines (i.e., object programs) –For efficient searching Directory –Some operating systems can keep the directory for commonly used libraries permanently in memory »The same technique applies equally well to the resolution of external references to data items

Loader Options »Many loaders allow the user to specify options that modify the standard processing. –Special command language –Separate input file to loader –Embedded in the primary input stream –In source program INCLUDEprogram-name(library-name) DELETEcsect-name CHANGEname1, name2 Examples of command language: LIBRARYMYLIB NOCALLSTDEV, PLOT, CORREL Examples: INCLUDEREAD(UTLIB) INCLUDEWRITE(UTLIB) DELETE RDREC, WRREC CHANGERDREC, READ CHANGEWRREC, WRITE

3.4 Loader Design Options »3.4.1 Linkage Editor –Perform linking prior to load time »3.4.2 Dynamic linking –Linking function is performed at execution time »3.4.3 Bootstrap loader –Be used to run stand-alone programs independent of the operating system or the system loader

Linkage Editors »A linking loaders performs –All linking and relocation operations –Automatic library search –Loads the linked program directly into memory for execution »A linkage editor –Produces a linked version of program including automatic library search if specified. This program often called a load module or an executable image), which is written to a file or library for later execution –A simple relocating loader can be used to load the linked version of program into memory The loading can be accomplished in one pass with no external symbol table required

29 »The essential difference between a linkage editor and a linking loader

Linkage Editors –All items that need to be modified at load time have values that are relative to the start of the linked program. –If a program is to be executed many times without being reassembled, the use of a LE substantially reduces the overhead required. –LE can perform many useful functions besides simply preparing an OP for execution.

31 The linkage editor can be used to replace the subroutines in the linked version Linkage editors can also be used to build packages of subroutines or other control sections that are generally used together

Dynamic Linking »Linking loaders perform these same operations at load time. »Linkage editors perform linking operations before the program is loaded for execution. »Dynamic Linking postpones the linking function until execution time

Dynamic Linking »Dynamic linking (dynamic loading, load on call) –Postpones the linking function until execution time. –A subroutine is loaded and linked to the rest of the program when it is first needed. –Dynamic linking is often used to allow several executing program to share one copy of a subroutine or library. Run-time library (C language), dynamic link library In object-oriented system, it allows the implementation of the object and its methods to be determined at the time the program is run A single copy of the routines in this library could be loaded into the memory of the computer.

Dynamic Linking »Dynamic linking provides the ability to load the routines only when (and if) they are needed. –For example, that a program contains subroutines that correct or clearly diagnose error in the input data during execution. –If such error are rare, the correction and diagnostic routines may not be used at all during most execution of the program. –However, if the program were completely linked before execution, these subroutines need to be loaded and linked every time.

Dynamic Linking »Dynamic linking avoids the necessity of loading the entire library for each execution. »Fig illustrates a method in which routines that are to be dynamically loaded must be called via an operating system (OS) service request.

36

37

Dynamic Linking »The program makes a load-on-call service request to OS. The parameter of this request is the symbolic name of the routine to be loaded. »OS examines its internal tables to determine whether or not the routine is already loaded. If necessary, the routine is loaded form the specified user or system libraries. »Control id then passed form OS to the routine being called. »When the called subroutine completes its processing, OS then returns control to the program that issued the request. »If a subroutine is still in memory, a second call to it may not require another load operation.

Bootstrap Loaders »Given an idle computer with no program in memory, how do we get things started? –With the machine empty and idle, there is no need for program relocation Some early computers required the operator to enter into memory the object code for an absolute loader, using switches on the computer console One some computer, an absolute loader program is permanently resident in a ROM A built-in hardware function that reads a fixed-length record form some device into memory at a fixed location, then transfer the control to the address in memory to execute. That fixed length record can direct the reading of others if required.