l2 Object Files
l2 Object Files
OBJECT FILE
Objective:
Understand the role of object files
Understand structure of an object file and its organization mechanism
under limitation of hardware
in the allocation of memory
in the relocation
Content
Study structure of a common object file.
MS-DOS COM
MS-DOS EXE
UNIX a.out
UNIX ELF
Study allocation of memory for object files
Study techniques for relocation of object files
Linkable
Linkable with other object files
Used as input to the linker
Contain global symbols and relocation information
Executable
Loadable on memory and executable
Usually contain page code for easily mapping on address space
Not contain symbol
Not have (very little) relocation information
Loadable
Be loadable onto memory and used by other programs (libraries)
Static linking: Not contain symbols
Dynamic linking: contain symbols and relocation information
Example
CS:IP points to instruction address
CS=0x1234, IP=0x2140
Absolute address: 0x12340 + 0x2140 = 0x14480
Characteristic
Simple
Only contain program code (execution code, data), not contain
anything else
When a program is loaded
A new memory region is allocated immediately after the memory region
was used, on the top of freedom memory
PSP(program segment prefix, 256 bytes) is created on the top of this
new memory region
Contain information about size of the allocated memory region, point
to caller’s PSP, etc.
Load and execute the program
The program is not loaded at a fixed address.
Header
Size (header, relocation table, program, data)
Initial values for SP and IP
minalloc stores size of BBS
maxalloc
...
Program and data
Be combined together
BBS region is particularly determined by minalloc
Relocation table
Program loading address is not specified when compiling
The compiler generates code for the program starting from the address
0x0000
Jump instruction (across the border of a segment) is set by real address
(generated by compiler)
file
+--------+
| header |
+--------+
|text |
+--------+
|data |
+--------+
|reloc. | ... relocation information
|for text| (only for undefined symbols)
+--------+ - address (offset of text/data seg.)
|reloc. | - text seg.? or data seg.?
|for data| - pointer to symbol table
+--------+
|symbol | ... Information about relocation symbols (function/variable)
| table| - address (offset in string table)
+--------+ - type (global or local)
|string |
| table| ... Label of symbol (function/variable)
+--------+