Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "CPE2 3 KU Program Linking System Software Emergency Resolution Lecture #1."— Presentation transcript:

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

2 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.

3 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

4 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

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

6 CPE2 3 KU Reasons for Program Linking (1) MAIN (symbols)Address (in Hex) START000000 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.

7 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.”

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

9 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

10 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

11 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 PROGA0000000063 LISTA00040 ENDA00054 PROGB000630007F LISTB000C3 ENDB000D3 PROGC000E200051 LISTC00112 ENDC00124

12 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,000020 H,PROGA,000000,000063 D,LISTA,000040,ENDA,000054... T RECORDS...... M RECORDS... R,LISTA,ENDA,LISTC,ENDC E H,PROGB,000000,00007F D,LISTB,000060,ENDB,000070... T RECORDS...... M RECORDS... R,LISTA,ENDA,LISTB,ENDB E H,PROGC,000000,000051 D,LISTC,000030,ENDC,000042... T RECORDS...... M RECORDS... ESTAB Symbol AddressLength PROGA0000000063 LISTA00040 ENDA00054 PROGB000630007F LISTB000C3 ENDB000D3 PROGC000E200051 LISTC00112 ENDC00124 Current Offset:063E2

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

14 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,000020 H,PROGA,000000,000063 D,LISTA,000040,ENDA,000054... T RECORDS...... M RECORDS... R,LISTA,ENDA,LISTC,ENDC E H,PROGB,000000,00007F D,LISTB,000060,ENDB,000070... T RECORDS...... M RECORDS... R,LISTA,ENDA,LISTB,ENDB E H,PROGC,000000,000051 D,LISTC,000030,ENDC,000042... T RECORDS...... M RECORDS...

15 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,000063 H,PROGB,000000,00007F H,PROGC,000000,000051 E,000020 E E H,LDMODL,000000,000133 E,000020

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

17 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 PROGA0000000063 LISTA00040 ENDA00054 PROGB000630007F LISTB000C3 ENDB000D3 PROGC000E200051 LISTC00112 ENDC00124 T,000036,0B,... +63 CS PROGB: Offset = 0x63 T,000099,0B,...

18 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 PROGA0000000063 LISTA00040 ENDA00054 PROGB000630007F LISTB000C3 ENDB000D3 PROGC000E200051 LISTC00112 ENDC00124 T,000018,0C,... +E2 CS PROGC: Offset = 0x63+0x7F T,0000FA,0C,...

19 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,+000112 M,000057,06,+000124 +0Substitute ESTAB SymbolAddressLength PROGA0000000063 LISTA00040 ENDA00054 PROGB000630007F LISTB000C3 ENDB000D3 PROGC000E200051 LISTC00112 ENDC00124

20 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,+000040 M,0000A1,05,+000054 M,0000A1,05,-000040 +63Substitute ESTAB SymbolAddressLength PROGA0000000063 LISTA00040 ENDA00054 PROGB000630007F LISTB000C3 ENDB000D3 PROGC000E200051 LISTC00112 ENDC00124

21 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,+000040 M,0000FF,05,+0000C3 M,000103,05,+000054 +E2Substitute ESTAB SymbolAddressLength PROGA0000000063 LISTA00040 ENDA00054 PROGB000630007F LISTB000C3 ENDB000D3 PROGC000E200051 LISTC00112 ENDC00124

22 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,000133 E,000020 M,000024,05,+0000C3 M,000054,06,+000112 M,000057,06,+000124 M,00009A,05,+000040 M,0000A1,05,+000054 M,0000A1,05,-000040 M,0000FB,05,+000040 M,0000FF,05,+0000C3 M,000103,05,+000054 T,000020,0A,... T,000099,0B,... T,0000FA,0C,...

23 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.

24 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)

25 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

26 CPE2 3 KU Method #2: Pass 1: Make the M-Table Make M- table! LocationLengthExpression 0002405+LISTB 0005406+LISTC 0005706+ENDC-LISTC 0009A05+LISTA 000A105+ENDA-LISTA 000D306+ENDA 000FB05+LISTA 000FF05+LISTB 0010305+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

27 CPE2 3 KU Method #2: Pass 1.5: Evaluate M-Table Eval. ResultType (Abs/Rel) 000C3R 000112R 000012A 00040R 00014A 000054R 00040R 000C3R 00014A LocationLengthExpression 0002405+LISTB 0005406+LISTC 0005706+ENDC-LISTC 0009A05+LISTA 000A105+ENDA-LISTA 000D306+ENDA 000FB05+LISTA 000FF05+LISTB 0010305+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

28 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.

29 CPE2 3 KU Method #2: Pass 2: Edit T records. T,000020,0A,03201D 77100004... +000C3 T,000020,0A,03201D 771000C7... T,000054,0F,000014... +000112 T,000054,0F,000126... etc. LocationLength 0002405 0005406 0005706 0009A05 000A105 000D306 000FB05 000FF05 0010305 Eval. ResultType 000C3R 000112R 000012A 00040R 00014A 000054R 00040R 000C3R 00014A

30 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 0002405 0005406 0005706 0009A05 000A105 000D306 000FB05 000FF05 0010305 Eval. ResultType 000C3R 000112R 000012A 00040R 00014A 000054R 00040R 000C3R 00014A M,000024,05 M,000054,06 M,00009A,05 M,0000D3,06 M,0000FB,05 M,0000FF,05

31 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,000133 E,000020 T,000020,0A,03201D 771000C7... T,000054,0F,000126... T...

32 CPE2 3 KU The M-Table (resource) 00024 05 +LISTB 00054 06 +LISTC 00057 06 +ENDC-LISTC 0005A 06 +ENDC-LISTC+PROGA 0005D 06 –ENDB+LISTB 00060 06 +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 00103 05 +ENDA-LISTA 00124 06 +ENDA-LISTA+PROGC 0012A 06 +LISTA 0012D 06 +ENDA-LISTA-ENDB+LISTB 00130 06 +LISTB-LISTA Locati on Len gth Expressi on 0002405+LISTB 0005406+LISTC 0005706+ENDC- LISTC 0009A05+LISTA 000A105+ENDA- LISTA 000D306+ENDA 000FB05+LISTA 000FF05+LISTB 0010305+ENDA- LISTA Eval. Result Type (Abs/Rel) 000C3R 000112R 000012A 00040R 00014A 000054R 00040R 000C3R 00014A

33 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: 0201423006) [CCD1] C. Chatdokmaiprai. (2004, August 25). Load Module & Linker (Solution #1) [Online]. Available: http://cpe.ku.ac.th/~ccd/204331/lmdfmt1.pdf http://cpe.ku.ac.th/~ccd/204331/lmdfmt1.pdf [CCD2] ____________. (2004, August 25). Load Module & Linker (Solution #2) [Online]. Available: http://cpe.ku.ac.th/~ccd/204331/lmdfmt2.pdf http://cpe.ku.ac.th/~ccd/204331/lmdfmt2.pdf [CSSH] C.S. Shieh. (?). Linking Loader for SIC/XE Machine [Online]. Available: http://bit.kuas.edu.tw/~csshieh/teach/93A/sp/note/ sp07.ppt http://bit.kuas.edu.tw/~csshieh/teach/93A/sp/note/ sp07.ppt

34 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.


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

Similar presentations


Ads by Google