Loaders and Linkers CSCI/CMPE 3334 David Egle.

Slides:



Advertisements
Similar presentations
Chapter 10 Linking and Loading. Separate assembly creates “.mob” files.
Advertisements

Loaders Dr. Monther Aldwairi 10/21/2007 Dr. Monther Aldwairi.
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.
Machine Independent Assembler Features
Loaders and Linkers Object Program contains the information:
Chapter 3 System Software
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.
Chapter 6: Machine dependent Assembler Features
CPE2 3 KU Program Linking System Software Emergency Resolution Lecture #1.
CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University.
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
CS2422 Assembly Language & System Programming December 26, 2006.
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.
A Simple Two-Pass Assembler
Assemblers.
Chapter 1 Computer architecture Languages: machine, assembly, high
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
PART I SISTEM UTILITIES LECTURE 4.1 LINK_LOAD Ştefan Stăncescu 1.
© 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.
G.Umamaheswari Lect/IT R.M.D.EC system software
Loader and Linker.
Assembler Design Options One-Pass and Multi-Pass Assemblers.
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.
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 10 –Linkers.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 9 - Assembler 4.
Calculation of REF5 (ENDC-LISTC-10)
Machine dependent Assembler Features
System Programming and administration
System Software by Leland L. Beck Chapter 2
Chapter 9 : Assembler Design Options
Assembler Design Options
Assembler Design Options
Assemblers - 2 CSCI/CMPE 3334 David Egle.
Loaders and Linkers: Features
Machine Independent Features
Loaders and Linkers.
Assembler Design Options
Memory Management Tasks
A Simple Two-Pass Assembler
Optional Assembler Features 2
System Programming by Leland L. Beck Chapter 2
Assemblers CSCI/CMPE 3334 David Egle.
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:

Loaders and Linkers CSCI/CMPE 3334 David Egle

Introduction This chapter covers how to prepare object programs for execution Loading brings object program into memory usually provides for relocation, if necessary Linking combines several object programs resolves external references Note that these two functions may be combined in one program

Simplest loader Absolute loader Does all work in one pass does not provide for relocation or linking reads object program and places code in the specified memory locations Does all work in one pass Reads HEADER record to make sure correct program is being read, and that sufficient space is available While no END record Read TEXT record and place code at proper location Start execution at location specified by END record

Bootstrap loader Special type of absolute loader used when computer is turned on, or restarted Typically consists of several parts First part: ROM based, or part of hardware very short (in early days, entered at console) reads in second part from another storage device Second part: reads in program to be run usually operating system kernel expects simple object format this kernel then reads in and sets up the operating system

Machine dependent features Relocation permits program to be loaded anywhere in memory Note that this does not apply to modern systems where memory references are made relative to start of user address space if implemented would require that the object code contain modification records indicating which statements required changes

Machine dependent features 2 Linking need to resolve all external references cannot perform the resolution until all object programs are read requires knowledge of instruction format Consider code on p 136-137

PROGA Source Code 0000 PROGA START 0 EXTDEF LISTA, ENDA EXTREF LISTB, ENDB, LISTC, ENDC ………. 0020 REF1 LDA LISTA 03201D 0023 REF2 +LDT LISTB+4 77100004 0027 REF3 LDX #ENDA-LISTA 050014 0040 LISTA EQU * 0054 ENDA EQU * 0054 REF4 WORD ENDA-LISTA+LISTC 000014 0057 REF5 WORD ENDC-LISTC-10 FFFFF6 005A REF6 WORD ENDC-LISTC+LISTA-1 00003F 005D REF7 WORD ENDA-LISTA-(ENDB-LISTB) 000014 0060 REF8 WORD LISTB-LISTA FFFFC0 END REF1

PROGB Source Code 0000 PROGB START 0 EXTDEF LISTB, ENDB EXTREF LISTA, ENDA, LISTC, ENDC ………. 0036 REF1 +LDA LISTA 03100000 003A REF2 LDT LISTB+4 772027 003D REF3 +LDX #ENDA-LISTA 05100000 0060 LISTB EQU * 0070 ENDB EQU * 0070 REF4 WORD ENDA-LISTA+LISTC 000000 0073 REF5 WORD ENDC-LISTC-10 FFFFF6 0076 REF6 WORD ENDC-LISTC+LISTA-1 FFFFFF 0079 REF7 WORD ENDA-LISTA-(ENDB-LISTB) FFFFF0 007C REF8 WORD LISTB-LISTA 000060 END

PROGC Source Code 0000 PROGC START 0 EXTDEF LISTC, ENDC EXTREF LISTA, ENDA, LISTB, ENDB ………. 0018 REF1 +LDA LISTA 03100000 001C REF2 +LDT LISTB+4 77100004 0020 REF3 +LDX #ENDA-LISTA 05100000 0030 LISTC EQU * 0042 ENDC EQU * 0042 REF4 WORD ENDA-LISTA+LISTC 000030 0045 REF5 WORD ENDC-LISTC-10 000008 0048 REF6 WORD ENDC-LISTC+LISTA-1 000011 004B REF7 WORD ENDA-LISTA-(ENDB-LISTB) 000000 004E REF8 WORD LISTB-LISTA 000000 END

Object code – PROGA and PROGB HPROGA 000000000063 DLISTA 000040ENDA 000054 RLISTB ENDB LISTC ENDC … T0000200A03201D77100004050014 …. T0000540F000014FFFFF600003F000014FFFFC0 M00002405+LISTB M00005406+LISTC M00005706+ENDC M00005706-LISTC M00005A06+ENDC M00005A06-LISTC M00005A06+PROGA M00005D06-ENDB M00005D06+LISTB M00006006+LISTB M00006006-PROGA E000020 HPROGB 00000000007F DLISTB 000060ENDB 000070 RLISTA ENDA LISTC ENDC … T0000360B0310000077202705100000 …. T0000700F000000FFFFF6FFFFFFFFFFF0000060 M00003705+LISTA M00003E05+ENDA M00003E05-LISTA M00007006+ENDA M00007006-LISTA M00007006+LISTC M00007306+ENDC M00007306-LISTC M00007606+ENDC M00007606-LISTC M00007606+LISTA M00007906+ENDA M00007906-LISTA M00007C06+PROGB M00007C06-LISTA E

Object code – PROGC HPROGC 000000000051 DLISTC 000030ENDC 000042 RLISTA ENDA LISTB ENDB … T0000180C031000007710000005100000 …. T0000420F0000300000080000011000000000000 M00001905+LISTA M00001D05+LISTB M00002105+ENDA M00002105-LISTA M00004206+ENDA M00004206-LISTA M00004206+PROGC M00004806+LISTA M00004B06+ENDA M00004B06-LISTA M00004B06-ENDB M00004B06+LISTB M00004E06+LISTB M00004E06-LISTA E

What needs to be done? Need a list of all the globally defined symbols Need to know where each program will be loaded in memory Need to fix up the external references Need to load programs into memory Just as in the assembler, this is done in two passes pass 1 – get the addresses of the global symbols pass 2 – use the information to get the program loaded

Two approaches Link and load object programs directly into memory Link programs and save in an executable program which will be loaded into memory later

Data Structures External symbol table (ESTAB) stores the name, address, and control section of each external symbol also holds control section names, starting addresses (CSADDR), and lengths (CSLTH) can be organized as a hash table Program load address (PROGADDR) variable that contains the beginning address in memory for the linked program typically supplied by the OS

Pass 1 Algorithm 1. get PROGADDR from operating system 2. set CSADDR to PROGADDR for first control section 3. while not end of input do [for each object file] 3.1. read next input record 3.2. set CSLTH to control section length 3.3. search ESTAB for control section name 3.4. if found then set error flag (duplicate external symbol) else enter control section name into ESTAB with value CSADDR 3.5. while record type <> ‘E’ do process record 1 3.6. add CSLTH to CSADDR

Process Record 1 1. read next input record 2. if record type == ‘D’ then for each symbol in the record do search ESTAB for symbol name if found then set error flag (duplicate external symbol) else enter symbol into ESTAB with value (CSADDR+ indicated address)

Pass 2 Algorithm 1. set CSADDR to PROGADDR 2. set EXECADDR to PROGADDR 3. while not end of input do 3.1. read next input record 3.2. set CSLTH to control section length 3.3. while record type <> ‘E’ do process record 2 3.4. if an address is specified in End record then set EXECADDR to (CSADDR + specified address) 3.5. add CSLTH to CADDR 4. jump to location given by EXECADDR to start execution

Process Record 2 1. read next input record 2. if record type == ‘T’ then if object code is in character form, convert into internal representation move object code to location (CSADDR + specified address) else if record type == ‘M’ then search ESTAB for modifying symbol name if found then add/subtract symbol value at location (CSADDR + specified address) else set error flag (undefined external reference)

An efficient change Assign a reference number to each external symbol referred to in a control section the control section name is assigned the reference number 01 The reference number is used instead of the symbol name in Modification records This technique requires the use of Refer records (not used in our algorithm) Avoids multiple searches of ESTAB during the loading

Example of reference numbers HPROGA 000000000063 DLISTA 000040ENDA 000054 R02LISTB 03ENDB 04LISTC 05ENDC … T0000200A03201D77100004050014 T0000540F000014FFFFF600003F000014FFFFC0 M00002405+02 M00005406+04 M00005706+05 M00005706-04 M00005A06+05 M00005A06-04 M00005A06+01 M00005D06-03 M00005D06+02 M00006006+02 M00006006-01 E000020