<<

9/30/14

CS 240, Fall 2014! WELLESLEY CS! CS 240, Fall 2014! WELLESLEY CS!

Linker: links separate object codes into one. program

compiler

Linking and Loading Object file header describes size and assembly code pieces of file. Text segment contains . assembler Stac data contains long lived data. object code Relocaon informaon idenfies When your program is more than a single .asm file... instrucons and data that depend on absolute addresses. Symbol table contains remaining labels such as external references. Debugging informaon concerning how modules were compiled. 1. Assign all text and data secons 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 schemac Loader: loads executable into memory. C program

compiler Executable file Object file assembly code main: main: . assembler . . object code library rounes . . 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 instrucons and data into memory. memory call, prin prin: . 4. Copy parameters to main program onto stack. . Relocaon info . 5. Inialize 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 Stac 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-me. Dynamic: external code is linked and loaded only if used. • may save stac and dynamic work • moves some stac work to run-me.

*assuming the API does not change.

CS 240, Fall 2014! WELLESLEY CS! CS 240, Fall 2014! WELLESLEY CS! Idenfying the desired roune /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 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 protecons operand stack

constant + memory, structured as objects, pool not an array of bytes.

12

3