CPE2 3 KU Program Linking System Software Emergency Resolution Lecture #1.

Slides:



Advertisements
Similar presentations
Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te
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
Loaders & Linkers. Introduction A “Loader” is a program which accepts the object program as input, makes them executable by the computer and initiates.
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.
The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders.
CS 31003: Compilers ANIRUDDHA GUPTA 11CS10004 G2 CLASS DATE : 24/07/2013.
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
Chap 3 Loaders and Linkers. Object program contains translated instructions and data values from the source program. Loading, which brings the object.
Programming Types of Testing.
1 Machine-Independent Features Automatic Library Search automatically incorporate routines from a subprogram library Loading Options.
Chapter 6: Machine dependent Assembler Features
CS2422 Assembly Language and System Programming Linking Loader Department of Computer Science National Tsing Hua University.
© 2004, D. J. Foreman 1 Program Linking. © 2004, D. J. Foreman 2 Program Content  Given the following file: Float Mysqrt(float); void Prog1 () { extern.
Loader- Machine Independent Loader Features
CS2422 Assembly Language & System Programming December 22, 2005.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
An introduction to systems programming
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
1 Chapter 3 Loaders and Linkers Source Program Assembler Object Code Loader Executable Code Linker.
CS 201 Functions Debzani Deb.
Loader- Machine Dependent Loader Features
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Computer Science 210 Computer Organization The Instruction Execution Cycle.
Programming With C.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
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.
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.
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.
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.
Programs – Preprocessing, Compilation and Linking
Calculation of REF5 (ENDC-LISTC-10)
Machine dependent Assembler Features
Computer Science 210 Computer Organization
CC410: System Programming
System Programming and administration
Chapter 8 Main Memory.
Computer Science 210 Computer Organization
Loaders and Linkers CSCI/CMPE 3334 David Egle.
Loaders and Linkers: Features
Machine Independent Features
Chap. 6 Programming the Basic Computer
Loaders and Linkers.
Programming Fundamentals Lecture #3 Overview of Computer Programming
Optional Assembler Features 2
Loaders and Linkers.
Chapter 1 Computer architecture Languages: machine, assembly, high
An introduction to systems programming
Lecture 11 How assembler works
Program Assembly.
UNIT III LOADERS AND LINKERS
Chapter 3 Loaders and Linkers
Presentation transcript:

CPE2 3 KU Program Linking System Software Emergency Resolution Lecture #1

CPE2 3 KU Why This Presentation? Due to unforeseen circumstances, the entire course was abruptly terminated. Class terminated means no lectures. No lectures means no materials for exam, which, unfortunately, still exists. This file fills the gap by adding material to course, even without lecture.

CPE2 3 KUAgenda Recap of our past: The SIC/XE Civilization Program Linking Procedures Solution #1 Solution #2 Linking Loader Principles Overview of Post-Assembly-Time

CPE2 3 KU The SIC/XE Civilization [BECK] Allows “library sharing” at runtime Very important, but we can’t talk right now… Dyna mic Linkin g Lets us create “.exe” for faster loading Allows us to NOT program linker in SIC or SIC/XE Linkage Editor Enables Linking support Linking Loader Allows “fully multiple-file” programming Control Section M-Record Relocation Bit Mask Relocating Loader (SIC or SIC/XE) BSL, for example Absolute Loader

CPE2 3 KU What is Program Linking? OBJ Link er Load Modul e Load Modul e

CPE2 3 KU Reasons for Program Linking (1) MAIN (symbols)Address (in Hex) START dump00007E mem0000BE MATH (symbols)Address (in Hex) sin00001E cos00003E tan00005E asin00007E acos00009E atan0000BE …… Can we differentiate MAIN.dump and MATH.asin, or MAIN.mem and MATH.atan by byte number? How can we jump from an instruction in MAIN to, say, MATH.sin, when they “share” the same “address numbers”? You can’t answer? Good. That’s what’s supposed to happen.

CPE2 3 KU Reasons for Program Linking (2) So why not just “include”? Answer: It will work, but assembly will be slowed down. Libraries like “math.h” are usually pre- compiled (.o,.lib,.pyc, …), very large, and has only some headers to help you “reach” the functions inside. Don’t be fooled by their appearances. MAIN MAT H #include MATH NOTE: In real-world, “headers” usually contain only declarations. So there can already be math.h and math.dll separately. This is actually linking, but still gives illusion of “including.”

CPE2 3 KU Types of Linking Linking LoaderLink, Load later (Linkage Editor) Linking Loader AddrValue OB J Linker OB J Load_Module.e xe* Loader * Or “755”, you geek.

CPE2 3 KU Understanding Program Offsets Files/CSs are joined end-to-head, like this diagram. Each file/CS has its own Length. First part starts at zero, or S 1 =0 Subsequent parts start at {previous part’s start} + {previous part’s length}, or S n =S n- 1 +L n-1 for positive int n PROGA PROGB PROGC S PROGA =0 L PROGA S PROGB =S PRO GA +L PROGA L PROGB S PROGC =S PRO GB +L PROGB L PROG C

CPE2 3 KU Linking Method #1: “Naïve” Linking [CCD1] Simple Easy to implement Use 2-pass style Fast (to run: O(2n), n: code lines) Drawbacks: Produces lots of M records May or may not work with complex expressions

CPE2 3 KU Resource: Table-as-object- hierarchy NOTE TO READERS: Resource pages contain information/objects required for typesetting/slide design. They are trivial and have no value to you. ESTAB SymbolAddressLength PROGA LISTA00040 ENDA00054 PROGB F LISTB000C3 ENDB000D3 PROGC000E LISTC00112 ENDC00124

CPE2 3 KU Resource: Method #1: Pass 1/2 Scan H and D records only Keep results in ESTAB R,LISTB,ENDB,LISTC,ENDC E, H,PROGA,000000, D,LISTA,000040,ENDA, T RECORDS M RECORDS... R,LISTA,ENDA,LISTC,ENDC E H,PROGB,000000,00007F D,LISTB,000060,ENDB, T RECORDS M RECORDS... R,LISTA,ENDA,LISTB,ENDB E H,PROGC,000000, D,LISTC,000030,ENDC, T RECORDS M RECORDS... ESTAB Symbol AddressLength PROGA LISTA00040 ENDA00054 PROGB F LISTB000C3 ENDB000D3 PROGC000E LISTC00112 ENDC00124 Current Offset:063E2

CPE2 3 KU Method #1: Pass 1/2 Scan H and D records only Keep results in ESTAB R,LISTB,ENDB,LISTC,ENDC E, H,PROGA,000000, D,LISTA,000040,ENDA, T RECORDS M RECORDS... R,LISTA,ENDA,LISTC,ENDC E H,PROGB,000000,00007F D,LISTB,000060,ENDB, T RECORDS M RECORDS... R,LISTA,ENDA,LISTB,ENDB E H,PROGC,000000, D,LISTC,000030,ENDC, T RECORDS M RECORDS... Current Offset:063E2 ESTAB SymbolAddressLength PROGA LISTA00040 ENDA00054 PROGB F LISTB000C3 ENDB000D3 PROGC000E LISTC00112 ENDC00124

CPE2 3 KU Method #1: Pass 2/2 Time to modify our code. Unify H&E Delete D&R No ext. symbols means no D/R Shift T Use ESTAB for length detect Substitute into & Shift M Use ESTAB R,LISTB,ENDB,LISTC,ENDC E, H,PROGA,000000, D,LISTA,000040,ENDA, T RECORDS M RECORDS... R,LISTA,ENDA,LISTC,ENDC E H,PROGB,000000,00007F D,LISTB,000060,ENDB, T RECORDS M RECORDS... R,LISTA,ENDA,LISTB,ENDB E H,PROGC,000000, D,LISTC,000030,ENDC, T RECORDS M RECORDS...

CPE2 3 KU Method #1: Pass 2/2: Unify H & E H Sum length, put at top Program start = 0 Absolute programs are usually not linkable… E Keep execution start address of Main CS Put at end of program H,PROGA,000000, H,PROGB,000000,00007F H,PROGC,000000, E, E E H,LDMODL,000000, E,000020

CPE2 3 KU Method #1: Pass 2/2: Shift T To make program codes co-exist peacefully, we need to shift addresses. ESTAB SymbolAddressLength PROGA LISTA00040 ENDA00054 PROGB F LISTB000C3 ENDB000D3 PROGC000E LISTC00112 ENDC00124 T,000020,0A, T,000020,0A,... CS PROGA: Offset = 0

CPE2 3 KU Method #1: Pass 2/2: Shift T (2) To make program codes co-exist peacefully, we need to shift addresses. ESTAB SymbolAddressLength PROGA LISTA00040 ENDA00054 PROGB F LISTB000C3 ENDB000D3 PROGC000E LISTC00112 ENDC00124 T,000036,0B, CS PROGB: Offset = 0x63 T,000099,0B,...

CPE2 3 KU Method #1: Pass 2/2: Shift T (3) To make program codes co-exist peacefully, we need to shift addresses. ESTAB SymbolAddressLength PROGA LISTA00040 ENDA00054 PROGB F LISTB000C3 ENDB000D3 PROGC000E LISTC00112 ENDC00124 T,000018,0C,... +E2 CS PROGC: Offset = 0x63+0x7F T,0000FA,0C,...

CPE2 3 KU Method #1: Pass 2/2: Change M Just use ESTAB. (No expressions allowed for now) Don’t forget to add offset. M,000024,05,+LISTB M,000054,06,+LISTC M,000057,06,+ENDC CS PROGA: Offset = 0 M,000024,05,+0000C3 M,000054,06, M,000057,06, Substitute ESTAB SymbolAddressLength PROGA LISTA00040 ENDA00054 PROGB F LISTB000C3 ENDB000D3 PROGC000E LISTC00112 ENDC00124

CPE2 3 KU Method #1: Pass 2/2: Change M (2) Don’t forget to add offset. M,000037,05,+LISTA M,00003E,05,+ENDA M,00003E,05,-LISTA CS PROGB: Offset = 0x63 M,00009A,05, M,0000A1,05, M,0000A1,05, Substitute ESTAB SymbolAddressLength PROGA LISTA00040 ENDA00054 PROGB F LISTB000C3 ENDB000D3 PROGC000E LISTC00112 ENDC00124

CPE2 3 KU Method #1: Pass 2/2: Change M (3) Offsets add up! M,000019,05,+LISTA M,00001D,05,+LISTB M,000021,05,+ENDA CS PROGC: Offset = 0x63+0x7F M,0000FB,05, M,0000FF,05,+0000C3 M,000103,05, E2Substitute ESTAB SymbolAddressLength PROGA LISTA00040 ENDA00054 PROGB F LISTB000C3 ENDB000D3 PROGC000E LISTC00112 ENDC00124

CPE2 3 KU Method #1: Ready for Loading We put the H and E we processed earlier… And the shifted T records… Then the M records… We call this a load module. H,LDMODL,000000, E, M,000024,05,+0000C3 M,000054,06, M,000057,06, M,00009A,05, M,0000A1,05, M,0000A1,05, M,0000FB,05, M,0000FF,05,+0000C3 M,000103,05, T,000020,0A,... T,000099,0B,... T,0000FA,0C,...

CPE2 3 KU Method #1: Notes Just one note: In pass-2, you just run it through and use string processing to determine line types and act automatically. You don’t and shouldn’t need to separate the code lines into types like I demonstrated.

CPE2 3 KU Method #2: Introduction [CCD2] Likeness with Method #1 2-pass Utilizes ESTAB Difference against Method #1 More compact list of M records, which means faster Loading Unified M record offset: No need to add/subtract by symbol addresses However, you may need to implement Expression (-A+B+C-D+E…) Creates M-Table, so this will use more memory in implementation And uses more time: O(2n+ms) (m: M-table size, s: # of Symbols)

CPE2 3 KU Method #2: Pass 1: M-Table While reading in Pass 1, we scan ALL M records to make M- table. M-table should “summarize” the expression. Cut those loose ends. For better illustration, we will add one more M-record per CS. M,000024,05,+LISTB M,000054,06,+LISTC M,000057,06,+ENDC M,000057,06,-LISTC M,000037,05,+LISTA M,00003E,05,+ENDA M,00003E,05,-LISTA M,000070,06,+ENDA M,000019,05,+LISTA M,00001D,05,+LISTB M,000021,05,+ENDA M,000021,05,-LISTA

CPE2 3 KU Method #2: Pass 1: Make the M-Table Make M- table! LocationLengthExpression LISTB LISTC ENDC-LISTC 0009A05+LISTA 000A105+ENDA-LISTA 000D306+ENDA 000FB05+LISTA 000FF05+LISTB ENDA-LISTA M,000024,05,+LISTB M,000054,06,+LISTC M,000057,06,+ENDC M,000057,06,-LISTC M,000037,05,+LISTA M,00003E,05,+ENDA M,00003E,05,-LISTA M,000070,06,+ENDA M,000019,05,+LISTA M,00001D,05,+LISTB M,000021,05,+ENDA M,000021,05,-LISTA Start = 0 Length = 0x63 Start = 0x63 Length = 0x7F Start = 0xE2 Length = 0x51

CPE2 3 KU Method #2: Pass 1.5: Evaluate M-Table Eval. ResultType (Abs/Rel) 000C3R R A 00040R 00014A R 00040R 000C3R 00014A LocationLengthExpression LISTB LISTC ENDC-LISTC 0009A05+LISTA 000A105+ENDA-LISTA 000D306+ENDA 000FB05+LISTA 000FF05+LISTB ENDA-LISTA ESTAB SymbolAddress PROGA00000 LISTA00040 ENDA00054 PROGB00063 LISTB000C3 ENDB000D3 PROGC000E2 LISTC00112 ENDC00124 ESTAB Old M-Table TIP: If (Number of +’s == Number of –’s) then Absolute, else Relative. Result

CPE2 3 KU Method #2: Pass 2 Same thing as Method #1 Process H and E records normally However, … You must add the M values right into the code Since M records are already processed, we can just dump only Relative rows in.

CPE2 3 KU Method #2: Pass 2: Edit T records. T,000020,0A,03201D C3 T,000020,0A,03201D C7... T,000054,0F, T,000054,0F, etc. LocationLength A05 000A D FB05 000FF Eval. ResultType 000C3R R A 00040R 00014A R 00040R 000C3R 00014A

CPE2 3 KU Method #2: Dump the M Records For R types only: Dump “empty” M record to tell Loader to relocate. Keep only Location and Length. LocationLength A05 000A D FB05 000FF Eval. ResultType 000C3R R A 00040R 00014A R 00040R 000C3R 00014A M,000024,05 M,000054,06 M,00009A,05 M,0000D3,06 M,0000FB,05 M,0000FF,05

CPE2 3 KU Method #2: Finished Just dump the modified T records. Add the M lines The rest is no different. T... M,000024,05 M,000054,06 M... H,LDMODL,000000, E, T,000020,0A,03201D C7... T,000054,0F, T...

CPE2 3 KU The M-Table (resource) LISTB LISTC ENDC-LISTC 0005A 06 +ENDC-LISTC+PROGA 0005D 06 –ENDB+LISTB LISTB-PROGA 0009A 05 +LISTA 000A1 05 +ENDA-LISTA 000D3 06 +ENDA-LISTA+LISTC 000D6 06 +ENDC-LISTC 000D9 06 +ENDC-LISTC+LISTA 000DC 06 +ENDA-LISTA 000DF 06 +PROGB-LISTA 000FB 05 +LISTA 000FF 05 +LISTB ENDA-LISTA ENDA-LISTA+PROGC 0012A 06 +LISTA 0012D 06 +ENDA-LISTA-ENDB+LISTB LISTB-LISTA Locati on Len gth Expressi on LISTB LISTC ENDC- LISTC 0009A05+LISTA 000A105+ENDA- LISTA 000D306+ENDA 000FB05+LISTA 000FF05+LISTB ENDA- LISTA Eval. Result Type (Abs/Rel) 000C3R R A 00040R 00014A R 00040R 000C3R 00014A

CPE2 3 KU Further Reading [BECK] L.L. Beck. "Loaders and Linkers" in System Software: An Introduction to Systems Programming, 3rd ed. Addison-Wesley, 1997, ch 3. (ISBN: ) [CCD1] C. Chatdokmaiprai. (2004, August 25). Load Module & Linker (Solution #1) [Online]. Available: [CCD2] ____________. (2004, August 25). Load Module & Linker (Solution #2) [Online]. Available: [CSSH] C.S. Shieh. (?). Linking Loader for SIC/XE Machine [Online]. Available: sp07.ppt sp07.ppt

CPE2 3 KUAbout This file is copyrighted (actually –left) CC- BY-NC-SA 3.0 by Class of 2012, Department of Computer Engineering Students (“CPE23 KU”) Slide composition is attributed to Chawanat “LunaticNeko” Nakasan. We tried extremely hard to limit use of copyrighted materials where unrelated, but when it can’t be helped, we’re claiming that our use is fair, and not endorsed by the original authors.