asm
Class Linker

java.lang.Object
  |
  +--asm.Linker

public class Linker
extends java.lang.Object

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.

Version:
$Id: Linker.java,v 1.10 2003/01/22 05:35:08 dugan Exp $
See Also:
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

modules

java.util.List modules

symTable

java.util.Map symTable
Global symbol table. Maps symbols to ArrayList of Modules that define that symbol.


dataSize

int dataSize

textSize

int textSize

entryPoint

int entryPoint
Constructor Detail

Linker

public Linker()
Method Detail

add

public void add(Module m)

patch

public void patch()

print

public void print(boolean printText)

findEntry

public void findEntry(java.lang.String entryName)

dumpExe

public void dumpExe(java.io.DataOutputStream out,
                    boolean bare)
             throws java.io.IOException
java.io.IOException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
The linker takes the following arguments:
  1. --bare (just dump instructions, no executable format)
  2. --verbose (print lots of messages)
  3. --entry [name] (set the entry point the given symbol)
  4. --at [address] (link as if the text segment will begin at the given address, zero is the default).

java.lang.Exception