|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--asm.Linker
The Linker takes multiple object files and produces a single executable.
Executable file format:
Magic Number (4 bytes) Text segment size (4 bytes) Data segment size (4 bytes) Stack size (4 bytes) Heap size (4 bytes) Entry point (instruction of main, 4 bytes) Text segment (variable in size) Data segment (variable in size)Parses each of the given .o files, and builds a structure that has the fields defined above. Then build a global symbol table: (read each symbol table, and map each symbol -> module)
Order all of the modules, and set two offsets per module: one for where its global data starts, one for where its instructions start.
Resolving references:
for each module for each reference look up the defining module in the global symbol table. if found patch up the reference 1. jumps: this is going to be the base offset for the defining module, plus the symbols location in that module) 2. global data: this is going to be a 16-bit (can't have big static data this way, but who cares) offset for a given load/store instruction.Now if all references got resolved successfully, we can write the .exe file: dump the data segment size, the text segment, and whatever they want to be the total size (or maybe heap and stack?).
Go through the modules in order dumping the data segments. Go through the modules in order dumping the text segments.
Will also build a "raw" executable, meaning that it has no segment size information, it's just raw instructions.
For info on using the linker.
,
For info on the magic number.
Field Summary | |
(package private) int |
dataSize
|
(package private) int |
entryPoint
|
(package private) java.util.List |
modules
|
(package private) java.util.Map |
symTable
Global symbol table. |
(package private) int |
textSize
|
Constructor Summary | |
Linker()
|
Method Summary | |
void |
add(Module m)
|
void |
dumpExe(java.io.DataOutputStream out,
boolean bare)
|
void |
findEntry(java.lang.String entryName)
|
static void |
main(java.lang.String[] args)
The linker takes the following arguments: --bare (just dump instructions, no executable format) --verbose (print lots of messages) --entry [name] (set the entry point the given symbol) --at [address] (link as if the text segment will begin at the given address, zero is the default). |
void |
patch()
|
void |
print(boolean printText)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
java.util.List modules
java.util.Map symTable
int dataSize
int textSize
int entryPoint
Constructor Detail |
public Linker()
Method Detail |
public void add(Module m)
public void patch()
public void print(boolean printText)
public void findEntry(java.lang.String entryName)
public void dumpExe(java.io.DataOutputStream out, boolean bare) throws java.io.IOException
java.io.IOException
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |