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 Sta c data contains long lived data. object code Reloca on informa on iden fies When your program is more than a single .asm file... instruc ons and data that depend on absolute addresses. linker Symbol table contains remaining labels such as external references. executable Debugging informa on concerning how modules were compiled. 1. Assign all text and data sec ons 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 schema c Loader: loads executable into memory. C program
compiler Executable file Object file assembly code main: main: . assembler . . object code library rou nes . . 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 instruc ons and data into memory. memory call, prin prin : . 4. Copy parameters to main program onto stack. . Reloca on info . 5. Ini alize 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 Sta c vs. dynamic linking Text First call is to a jal! dummy entry via !...! Update flexibility: an indirect jump lw! Sta c: Ge ng library updates requires relinking. jr! Dynamic: Library updates require no changes to executable.* Data
Code size: Sta c: all code and sta c data that might ever be called or used • must be included in the executable. • must be loaded at run- me. Dynamic: external code is linked and loaded only if used. • may save sta c and dynamic work • moves some sta c work to run- me.
*assuming the API does not change.
CS 240, Fall 2014! WELLESLEY CS! CS 240, Fall 2014! WELLESLEY CS! Iden fying the desired rou ne 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- me 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 Na ve 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 protec ons operand stack
constant + memory, structured as objects, pool not an array of bytes.
12
3