Chapter 3 Loaders and 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.
Linking & Loading CS-502 Operating Systems
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.
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.
Chih-Hung Wang Chapter 2: Assembler (Part-1) 參考書目 Leland L. Beck, System Software: An Introduction to Systems Programming (3rd), Addison-Wesley, 1997.
CS2422 Assembly Language & System Programming January 2, 2007.
Loader- Machine Independent Loader Features
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
A Simple Two-Pass Assembler
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Chapter 1 Computer architecture Languages: machine, assembly, high
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
1 Assemblers System Programming by Leland L. Beck Chapter 2.
2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.
Chapter - 3 Loaders & Linkers. Overview of Chapter 3 Basic Loader Functions Design Issues of: An Absolute Loader Simple Bootstrap Loader Machine-Dependent.
Loader and Linker.
CSc 453 Linking and Loading
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.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 10 –Linkers.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 9 - Assembler 4.
Lecture 3 Translation.
DDC 2223 SYSTEM SOFTWARE DDC2223 SYSTEM SOFTWARE.
Machine dependent Assembler Features
System Programming and administration
Chapter 2: System Structures
Linking & Loading.
CS-3013 Operating Systems C-term 2008
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Loaders and Linkers CSCI/CMPE 3334 David Egle.
Loaders and Linkers: Features
Machine Independent Features
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Loaders and Linkers.
Memory Management Tasks
Linking & Loading CS-502 Operating Systems
A Simple Two-Pass Assembler
Optional Assembler Features 2
System Programming by Leland L. Beck Chapter 2
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
Machine Independent Assembler Features
Loaders and Linkers.
Chapter 1 Computer architecture Languages: machine, assembly, high
Linking & Loading CS-502 Operating Systems
Machine Independent Assembler Features
An introduction to systems programming
UNIT III LOADERS AND LINKERS
Presentation transcript:

Chapter 3 Loaders and Linkers

Purpose and Function Places object program in memory Linking Combines 2 or more obj programs Relocation Allows loading at different locations Linkage Editor Provides linking without loading

Kinds of Loaders Absolute Single pass Checks for correct header record Checks for sufficient available memory Moves each text record to proper location Upon seeing END passes control to the pgm

Kinds of loaders (cont.) Bootstrap A special absolute loader ROM Loads the OS

Kinds of loaders (cont.) Relocating Modifies appropriate addresses Loads object program at a variety of locations May perform loading during execution (repeatedly) Allows for multiple programs (multiprocessing) System libraries require relocation

Methods of Relocation Modification records Use absolute addressing and fixed format No modification records required Use same text records with flag (relocation bit) Relocation bits gathered into a mask If relocation bit is 1, add starting address to word

Modification Records H – header H PgmName Startaddr Length 1ch 6ch 6ch 6ch

Modification Records T – text T Startaddr Length records 1ch 6ch 2ch ???ch

Modification Records D – Define – defined here, used elsewhere D Label addr Label addr Label addr …. 1ch 6ch 6ch 6ch 6ch 6ch 6ch

Modification Records R – Refer – used here, defined elsewhere R Label Label Label …. 1ch 6ch 6ch 6ch

Modification Records M – Modification M addr len action 1ch 6ch 2ch +/- label Addr – location to modify Len – number of bytes to modify Action – how to modify

Modification Records E – Ebd E addr 1ch 6ch Addr is the starting execution location

Mask Method of Relocation HCOPY 000000001077A ^ ^ ^ T0000001EFFC1400334810390000362800303000154810613C000300002A0C003900002D ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ FFC 111111111100 all 10 words need modification T 00001E 15 E00 0C0036 481061 080033 4C0000 454F46 000003 000000 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ E00 111000000000 instructions 0,1,2 need load addresses T0000391EFFC0400300000030E0105D30103FD8105D2800303010575480392C105E38103F ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ T0010570A8001000364C0000F1001000 ^ ^ ^ ^ ^ ^ ^ The F1 fouls up alignment, thus a new text record has to be started. FIGURE 3.7

Program Linking Necessary for separate CSECTS External References External Definitions

LOADING Forward references to external symbols common Use 2 pass Pass 1 assigns address to external symbols Provides a load map (info. in symbol table) Pass 2 performs actual loading, relocation, and linking

Data Structures for Loading ESTAB external symbol table Stores Names Addresses CSECT of external symbols PROGADDR – program load address Provided by the OS CSADDR – CSECT addr. of control sect. loaded

Pass 1 All external symbols from define records are stored and have destination addresses Provides load map containing Header records Define records Efficiency can be increased if a reference number is given to each external symbol. Ref number indexes an array removing the need for a hash function.

Efficiency References HPROGA 000000 000063 DLISTA 000040 ENDA 000054 R 02LISTB 03ENDB 04LISTC 05ENDC (refer record) T 000020 0A 03201D 77100004 050014 T 000054 0F 000014 FFFFF6 00003F 000014 FFFFC0 M 000024 05 + 02 <----- 02 references LISTB M 000054 06 + 04 M 000057 06 + 05 M 000057 06 - 04 M 00005A 06 + 05 M 00005A 06 - 04 M 00005A 06 + 01 M 00005D 06 - 03 M 00005D 06 + 02 M 000060 06 + 02 M 000060 06 - 01 E 000020 Fig 3.12 Object program corresponding to Fig3.8 using reference numbers for code modification (PROGA only, PROGB and PROGC aresimilar)

Pass 2 Loads text records Resolves addresses (relocating) Linking of CSECTS Starts execution at address of end record Uses last end record when each CSECT contains an END with an address

Machine Independent Loader Features Include library routines -lm Specify options Load object program

Automatic Library Search Library routines are external references Users can include routines to override library routines Library search is a search of the directory that contains addresses of the routines.

Loader Options Exist as a separate command language OR As part of the compiled/assembled program

Loader Options (cont.) Select alternate source Include program name Delete external symbols or entire CSECTS Change names

Loader Options Example Fig2.15 is COPY using RDREC and WRREC. Suppose new routines READ and WRITE are to replace them, but we want to test READ and WRITE first. Without assembling we could give the loader: INCLUDE READ(UTLIB) INCLUDE WRITE(UTLIB) DELETE RDREC, WRREC CHANGE RDREC, READ CHANGE WRREC, WRITE Now we have the new routines for execution without removing and reassembling the source code.

Loader Options Libraries Specify alternative libraries to be searched. These are searched before system libraries, allowing user versions to replace system versions. LIBRARY MYLIB

Loader Options Libraries Specify that library routines not be included. If, for example, statistics were normally done, but not done in this run. NOCALL STDDEV, PLOT, CORREL allows these references to be unresolved, but the assemble to succeed.

Loader Options Libraries Specify no external references be resolved. Good for programs are linked but not executed immediately. Calls to external references, of course, will error.

Loader Output Output from the loader can vary load map with the level of detail. CSECT only CSECT and addresses, external symbol address and cross reference table showing where each is used.

Loader Design Options Linking loaders – all linking and relocation at load time Linkage editors – perform linking prior to load time Dynamic linking – performed at execution time

Linkage Editors Can replace one function without relinking. Similar to what make does for compiling INCLUDE PLANNER(PROGLIB) DELETE PROJECT (delete from existing planner) INCLUDE PROJECT(NEWLIB) (include new version) REPLACE PLANNER(PROGLIBK)

Linkage Editors (cont.) Can be used to combine several library routines into a package so that they do not need to be recombined each time a program is run that uses those packages. INCLUDE READR(FTNLIB) INCLUDE WRITER(FTNLIB) INCLUE BLOCK(FTNLIB) . SAVE FTNIO(SUBLIB) Result is a much more efficient linking of functions.

Linkage Editors (cont.) Can indicate that external references are not to be resolved by automatic library search Example: suppose 100 programs use I/O routes, if all external references were resolved, there would be 100 copies of the library. Using commands to the linkage editor like those above, the user could specify not to include the library. A linking loader could be used to include the routines at run time. There would be a little more overhead since two linking operations would be done, one for user external references by the linkage editor and one for libraries by the linking loader.

Dynamic Linking Perform the above operations but during load time. For example, a subroutine is loaded and linked to the rest of the program when it is first called. Used to allow several executing programs to share one copy of a subroutine or library. One copy of the function could be provided for all programs executing that use that function.

Dynamic Linking (cont.) Used in Object Oriented Programming Allows the object to be shared by several programs. An implementation of an object can be changed without effecting the program making use of the object.

Dynamic Linking (cont.) Enhanced efficiency (time and space) A subroutine is loaded only if it is needed, maybe an error handler routine would never be loaded if the error was never found.

Dynamic Linking (cont.) Implementation During execution time the loader must be kept and invoked when the function is needed. In this case the loader can be thought of as part of the OS and thus an OS call occurs. The binding is at execution time rather than load time. Delayed binding gives more capabilities at higher cost.

Bootstrap Loaders How is the loader loaded? Machine is idle and empty, thus no need for relocation. Some computers have a permanently resident in read-only memory (ROM) an absolute loader. Upon hardware signal occurring the machine executes this ROM program.