25-08-2017, 09:32 PM
Linking & Loading
Linking.ppt (Size: 100 KB / Downloads: 340)
Executable files
The OS expects executable files to have a specific format
Header info
Code locations
Data locations
Code & data
Symbol Table
List of names of things defined in your program and where they are defined
List of names of things defined elsewhere that are used by your program, and where they are used.
From source code to a process
Binding is the process of mapping names to addresses
Most compilers produce relocatable object code
Addresses relative to zero
The linker combines multiple object files and library modules into a single executable file
Addresses also relative to zero
The Loader reads the executable file
Allocates memory
Maps addresses within file to physical memory addresses
Resolves names of dynamic library items
Classic Unix
Linker is inside of gcc command
Loader is part of exec system call
Executable image contains all object and library modules needed by program
Entire image is loaded at once
Every image contains copy of common library routines
Every loaded program contain duplicate copy of library routines
Dynamic Loading
Routine is not loaded until it is called
Better memory-space utilization; unused routine is never loaded.
Useful when large amounts of code are needed to handle infrequently occurring cases.
Silbershatz says [incorrectly]
No special support from the operating system is required
Must be implemented through program design
Dynamic Linking
Complete linking postponed until execution time.
Stub used to locate the appropriate memory-resident library routine.
Stub replaces itself with the address of the routine, and executes the routine.
Operating system needs to check if routine is in processes’ memory address space.
Dynamic linking is particularly useful for libraries.
Linking - Summary
Linker – key part of OS – not in kernel
Combines object files and libraries into a “standard” format that the OS loader can interpret
Resolves references and does static relocation of addresses
Creates information for loader to complete binding process
Supports dynamic shared libraries