
9/30/14 CS 240, Fall 2014! WELLESLEY CS! CS 240, Fall 2014! WELLESLEY CS! Linker: links separate object codes into one. C program compiler Linking and Loading Object file header describes size and assembly code pieces of file. Text segment contains machine code. assembler library object code Stac data contains long lived data. object code Relocaon informaon idenfies When your program is more than a single .asm file... instrucFons and data that depend on absolute addresses. linker Symbol table contains remaining labels such as external references. executable Debugging informaon concerning how modules were compiled. 1. Assign all text and data secFons symbolic spots in address space. 2. Resolve symbolic labels to addresses. 3. Patch up absolute address references. CS 240, Fall 2014! WELLESLEY CS! CS 240, Fall 2014! WELLESLEY CS! Linking schema1c Loader: loads executable into memory. C program compiler Executable file Object file assembly code main: main: . assembler . object code library rouFnes . linker . jal prin . executable jal ???? Linker . prin: 1. Determine size of text and data segments. loader . C library . 2. Create address space large enough for both. object code . 3. Copy instrucFons and data into memory. memory call, prin prin: . 4. Copy parameters to main program onto stack. Relocaon info . 5. IniFalize registers (including $sp). 6. Jump to main procedure. 1 9/30/14 CS 240, Fall 2014! WELLESLEY CS! CS 240, Fall 2014! WELLESLEY CS! First call to dynamically linked code Sta1c vs. dynamic linking Text First call is to a jal! dummy entry via !...! Update flexibility: an indirect jump lw! Stac: Geng library updates requires relinking. jr! Dynamic: Library updates require no changes to executable.* Data Code size: Stac: all code and stac data that might ever be called or used • must be included in the executable. • must be loaded at run-Fme. Dynamic: external code is linked and loaded only if used. • may save stac and dynamic work • moves some stac work to run-Fme. *assuming the API does not change. CS 240, Fall 2014! WELLESLEY CS! CS 240, Fall 2014! WELLESLEY CS! Idenfying the desired roune Dynamic linker/loader Text Text Text jal! jal! jal! !...! !...! !...! lw! lw! lw! jr! jr! jr! Data Data Data The loaded word points to code that loads a register with a number Text Text ...! identifying the desired library ...! li ID! routine li ID! j! j! ...! ...! Text Dyn linker/loader! Remap DLL routine! ... and changes the address in The program jumps j! to the DLL that finds the indirect jump to point to the correct routine, that routine remaps it, ... Program translation 8-9 2 9/30/14 CS 240, Fall 2014! WELLESLEY CS! CS 240, Fall 2014! WELLESLEY CS! Dynamically linked libraries Virtual Machine Model Text Text jal! jal! !...! !...! lw! lw! jr! jr! High-Level Language Program Data Data Bytecode Ahead-of-Fme Text compiler compiler ...! li ID! compile me j! Thereafter, the call to the ...! library routine jumps indirectly Virtual Machine Language to the routine without the run me Text extra hops. Dyn linker/loader! Virtual machine JIT Remap DLL routine! (interpreter) compiler j! After Data/Text Data/Text Nave Machine Language remapping DLL routine! DLL routine! DLL jumps ...! ...! to routine jr! jr! 8-10 11 CS 240, Fall 2014! WELLESLEY CS! Java bytecode like assembly code for JVM, Holds pointer ‘this’ but works on all JVMs: Other arguments to method hardware-independent Other local variables typed (unlike ASM) 0 1 2 3 4 n variable table strong JVM protec1ons operand stack constant + memory, structured as objects, pool not an array of bytes. 12 3 .
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages3 Page
-
File Size-