CPE 23 KU Program Linking System Software Emergency

  • Slides: 30
Download presentation
CPE 23 KU Program Linking System Software Emergency Resolution Lecture #1

CPE 23 KU Program Linking System Software Emergency Resolution Lecture #1

CPE 23 KU Why This Presentation? • Due to unforeseen circumstances, the entire course

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

Agenda CPE 23 KU • Recap of our past: The SIC/XE Civilization • Program

Agenda CPE 23 KU • Recap of our past: The SIC/XE Civilization • Program Linking Procedures • Solution #1 • Solution #2 • Linking Loader • Principles • Overview of Post-Assembly-Time

CPE 23 KU The SIC/XE Civilization [BECK] Dyna mic • Allows “library sharing” at

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

CPE 23 KU Load Link What is Program Linking? OBJ OBJ er Modul e

CPE 23 KU Load Link What is Program Linking? OBJ OBJ er Modul e

CPE 23 KU Reasons for Program Linking (1) MAIN (symbols) Address (in Hex) START

CPE 23 KU Reasons for Program Linking (1) MAIN (symbols) Address (in Hex) START 000000 dump 00007 E mem 0000 BE MATH (symbols) Address (in Hex) sin 00001 E cos 00003 E tan 00005 E asin 00007 E acos 00009 E atan 0000 BE … … 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

CPE 23 KU Reasons for Program Linking (2) #include MATH MAIN MAT H •

CPE 23 KU Reasons for Program Linking (2) #include MATH MAIN MAT H • So why not just “include”? • Answer: It will work, but assembly will be slowed down. Libraries like “math. h” are usually precompiled (. o, . lib, . pyc, …), very large, and has NOTE: real-world, headers “headers” usually only. In some tocontain only declarations. So there can already be math. h math. dll separately. the This is actually helpandyou “reach” linking, but still gives illusion of “including. ”

Types of Linking • Linking Loader OB J Linking Loader Addr Value 01000 0

Types of Linking • Linking Loader OB J Linking Loader Addr Value 01000 0 01003 0 01006 0 01009 0 CPE 23 KU • Link, Load later (Linkage. OB Editor) OB OB J J J Linker Load_Module. e xe* Loader * Or “ 755”, you geek.

CPE 23 KU =0 SPROGC=SPRO GB+LPROGB PROGC LPROGB LPROGC SPROGB=SPRO GA+LPROGA Understanding Program Offsets

CPE 23 KU =0 SPROGC=SPRO GB+LPROGB PROGC LPROGB LPROGC SPROGB=SPRO GA+LPROGA Understanding Program Offsets SPROGA • 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} +

CPE 23 KU Linking Method #1: “Naïve” Linking [CCD 1] • Simple • Easy

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

CPE 23 KU Method #1: Pass 1/2 H, PROGA , 000000, 000063 D, LISTA

CPE 23 KU Method #1: Pass 1/2 H, PROGA , 000000, 000063 D, LISTA , 000040, ENDA , 000054 R, LISTB , ENDB , LISTC , ENDC. . . T RECORDS. . . M RECORDS. . . E, 000020 H, PROGB , 000000, 00007 F D, LISTB , 000060, ENDB , 000070 R, LISTA , ENDA , LISTC , ENDC • Scan H and D records only 0 63 • Current Keep. Offset: results in. E 2 ESTAB Symbol Address Length ESTAB PROGA 00000 00063 LISTA 00040 ENDA 00054 PROGB 00063 D, LISTC , 000030, ENDC , 000042 LISTB 000 C 3 R, LISTA , ENDA , LISTB , ENDB 000 D 3 . . . T RECORDS. . . M RECORDS. . . PROGC 000 E 2 LISTC 00112 ENDC 00124 . . . T RECORDS. . . M RECORDS. . . E H, PROGC , 000000, 000051 E 0007 F 00051

CPE 23 KU Method #1: Pass 2/2 H, PROGA , 000000, 000063 D, LISTA

CPE 23 KU Method #1: Pass 2/2 H, PROGA , 000000, 000063 D, LISTA , 000040, ENDA , 000054 R, LISTB , ENDB , LISTC , ENDC. . . T RECORDS. . . M RECORDS. . . E, 000020 H, PROGB , 000000, 00007 F D, LISTB , 000060, ENDB , 000070 R, LISTA , ENDA , LISTC , ENDC. . . T RECORDS. . . M RECORDS. . . E H, PROGC , 000000, 000051 D, LISTC , 000030, ENDC , 000042 R, LISTA , ENDA , LISTB , ENDB. . . T RECORDS. . . M RECORDS. . . E • 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 &

CPE 23 KU Method #1: Pass 2/2: Unify H &E H, LDMODL, 000000, 000133

CPE 23 KU Method #1: Pass 2/2: Unify H &E H, LDMODL, 000000, 000133 H, PROGA , 000000, 000063 E, 000020 H, PROGB , 000000, 00007 F • H • Sum length, put at top • Program start = 0 • Absolute programs are usually not linkable… E H, PROGC , 000000, 000051 E E, 000020 • E • Keep execution start address of

CPE 23 KU Method #1: Pass 2/2: Shift T • To make program CS

CPE 23 KU Method #1: Pass 2/2: Shift T • To make program CS PROGA: Offset = 0 codes co-exist peacefully, we need T, 000020, 0 A, . . . to shift addresses. +0 T, 000020, 0 A, . . . ESTAB Symbol Address Length PROGA 00000 00063 LISTA 00040 ENDA 00054 PROGB 00063 LISTB 000 C 3 ENDB 000 D 3 PROGC 000 E 2 LISTC 00112 ENDC 00124 0007 F 00051

CPE 23 KU Method #1: Pass 2/2: Shift T (2) • To make program

CPE 23 KU Method #1: Pass 2/2: Shift T (2) • To make program codes co-exist CS PROGB: Offset = 0 x 63 peacefully, we need T, 000036, 0 B, . . . to shift addresses. +63 T, 000099, 0 B, . . . ESTAB Symbol Address Length PROGA 00000 00063 LISTA 00040 ENDA 00054 PROGB 00063 LISTB 000 C 3 ENDB 000 D 3 PROGC 000 E 2 LISTC 00112 ENDC 00124 0007 F 00051

CPE 23 KU Method #1: Pass 2/2: Shift T (3) • To make program

CPE 23 KU Method #1: Pass 2/2: Shift T (3) • To make program codes co-exist CS PROGC: Offset = 0 x 63+0 x 7 F peacefully, we need T, 000018, 0 C, . . . to shift addresses. +E 2 T, 0000 FA, 0 C, . . . ESTAB Symbol Address Length PROGA 00000 00063 LISTA 00040 ENDA 00054 PROGB 00063 LISTB 000 C 3 ENDB 000 D 3 PROGC 000 E 2 LISTC 00112 ENDC 00124 0007 F 00051

CPE 23 KU Method #1: Pass 2/2: Change M • Just use ESTAB. CS

CPE 23 KU Method #1: Pass 2/2: Change M • Just use ESTAB. CS PROGA: Offset = 0(No expressions M, 000024, 05, +LISTB allowed for now) M, 000054, 06, +LISTC • Don’t forget to. Length add M, 000057, 06, +ENDC ESTAB Symbol Address offset. 00000 PROGA 00063 +0 LISTA Substitute. ENDA M, 000024, 05, +0000 C 3 M, 000054, 06, +000112 M, 000057, 06, +000124 00040 00054 PROGB 00063 LISTB 000 C 3 ENDB 000 D 3 PROGC 000 E 2 LISTC 00112 ENDC 00124 0007 F 00051

CPE 23 KU Method #1: Pass 2/2: Change M (2) • Don’t forget to

CPE 23 KU Method #1: Pass 2/2: Change M (2) • Don’t forget to add CS PROGB: Offset = 0 x 63 offset. M, 000037, 05, +LISTA M, 00003 E, 05, +ENDA M, 00003 E, 05, -LISTA +63 ESTAB Symbol Address Length PROGA 00000 00063 LISTA 00040 Substitute. ENDA M, 00009 A, 05, +000040 M, 0000 A 1, 05, +000054 M, 0000 A 1, 05, -000040 00054 PROGB 00063 LISTB 000 C 3 ENDB 000 D 3 PROGC 000 E 2 LISTC 00112 ENDC 00124 0007 F 00051

CPE 23 KU Method #1: Pass 2/2: Change M (3) • Offsets add up!

CPE 23 KU Method #1: Pass 2/2: Change M (3) • Offsets add up! CS PROGC: Offset = 0 x 63+0 x 7 F M, 000019, 05, +LISTA M, 00001 D, 05, +LISTB M, 000021, 05, +ENDA +E 2 ESTAB Symbol Address Length PROGA 00000 00063 LISTA 00040 Substitute. ENDA M, 0000 FB, 05, +000040 M, 0000 FF, 05, +0000 C 3 M, 000103, 05, +000054 PROGB 00063 LISTB 000 C 3 ENDB 000 D 3 PROGC 000 E 2 LISTC 00112 ENDC 00124 0007 F 00051

CPE 23 KU Method #1: Ready for Loading H, LDMODL, 000000, 000133 T, 000020,

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

CPE 23 KU Method #1: Notes • Just one note: In pass-2, you just

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

CPE 23 KU Method #2: Introduction [CCD 2] • Likeness with Method #1 •

CPE 23 KU Method #2: Introduction [CCD 2] • 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

CPE 23 KU Method #2: Pass 1: M-Table M, 000024, 05, +LISTB M, 000054,

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

CPE 23 KU Method #2: Pass 1: Make the M-Table Start = 0 Length

CPE 23 KU Method #2: Pass 1: Make the M-Table Start = 0 Length = 0 x 63 Start = 0 x 63 Length = 0 x 7 F Start = 0 x. E 2 Length = 0 x 51 M, 000024, 05, +LISTB M, 000054, 06, +LISTC M, 000057, 06, +ENDC M, 000057, 06, -LISTC M, 000037, 05, +LISTA M, 00003 E, 05, +ENDA M, 00003 E, 05, -LISTA M, 000070, 06, +ENDA M, 000019, 05, +LISTA M, 00001 D, 05, +LISTB M, 000021, 05, +ENDA M, 000021, 05, -LISTA • Make MLocation Length. Expression table! 00024 05 +LISTB 00054 06 +LISTC 00057 06 +ENDC -LISTC 0009 A 05 +LISTA 000 A 1 05 +ENDA -LISTA 000 D 3 06 +ENDA 000 FB 05 +LISTA 000 FF 05 +LISTB 00103 05 +ENDA -LISTA

CPE 23 KU Method #2: Pass 1. 5: Evaluate M-Table ESTAB Old M-Table Result

CPE 23 KU Method #2: Pass 1. 5: Evaluate M-Table ESTAB Old M-Table Result ESTAB Symbol Address Location Length. Expression Eval. Result Type (Abs/ Rel) PROGA 00000 00024 05 +LISTB 000 C 3 R LISTA 00040 00054 06 +LISTC 000112 R ENDA 00054 00057 06 +ENDC -LISTC 000012 A PROGB 00063 0009 A 05 +LISTA 00040 R LISTB 000 C 3 000 A 1 05 +ENDA -LISTA 00014 A ENDB 000 D 3 06 +ENDA 000054 R PROGC 000 E 2 000 FB 05 +LISTA 00040 R LISTC 00112 000 FF 05 +LISTB 000 C 3 R ENDC 00124 00103 05 +ENDA -LISTA 00014 A TIP: If (Number of +’s == Number of –’s) then

CPE 23 KU Method #2: Pass 2 • Same thing as Method #1 •

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

CPE 23 KU Method #2: Pass 2: Edit T records. Location Length. Eval. Result

CPE 23 KU Method #2: Pass 2: Edit T records. Location Length. Eval. Result Type 00024 05 000 C 3 R 00054 06 000112 R 00057 06 000012 A 0009 A 05 00040 R 000 A 1 05 00014 A 000 D 3 06 000054 R 000 FB 05 00040 R 000 FF 05 000 C 3 R 00103 05 00014 A T, 000020, 0 A, 03201 D 77100004. . . +000 C 3 T, 000020, 0 A, 03201 D 771000 C 7. . . T, 000054, 0 F, 000014. . . +000112 T, 000054, 0 F, 000126. . . etc.

CPE 23 KU Method #2: Dump the M Records Location Length. Eval. Result Type

CPE 23 KU Method #2: Dump the M Records Location Length. Eval. Result Type • For R types only: 00024 05 000 C 3 R 00054 06 000112 R 00057 06 000012 A 0009 A 05 00040 R 000 A 1 05 00014 A 000 D 3 06 000054 R • Dump “empty” M record to tell Loader to relocate. • Keep only Location and Length. M, 000024, 05 000 FB 05 00040 R M, 000054, 06 000 FF 05 000 C 3 R 00103 05 00014 A M, 00009 A, 05 M, 0000 D 3, 06 M, 0000 FB, 05 M, 0000 FF, 05

CPE 23 KU Method #2: Finished H, LDMODL, 000000, 000133 T, 000020, 0 A,

CPE 23 KU Method #2: Finished H, LDMODL, 000000, 000133 T, 000020, 0 A, 03201 D 771000 C 7. . . T, 000054, 0 F, 000126. . . T. . . M, 000024, 05 M, 000054, 06 M. . . E, 000020 • Just dump the modified T records. • Add the M lines • The rest is no different.

Further Reading CPE 23 KU • [BECK] L. L. Beck. "Loaders and Linkers" in

Further Reading CPE 23 KU • [BECK] L. L. Beck. "Loaders and Linkers" in System Software: An Introduction to Systems Programming, 3 rd ed. Addison-Wesley, 1997, ch 3. (ISBN: 0201423006) • [CCD 1] C. Chatdokmaiprai. (2004, August 25). Load Module & Linker (Solution #1) [Online]. Available: http: //cpe. ku. ac. th/~ccd/204331/lmdfmt 1. pdf • [CCD 2] ______. (2004, August 25). Load Module & Linker (Solution #2) [Online]. Available: http: //cpe. ku. ac. th/~ccd/204331/lmdfmt 2. pdf • [CSSH] C. S. Shieh. (? ). Linking Loader for SIC/XE Machine [Online]. Available: