annotate lwlink/tags/1.0/doc/lwlink.txt @ 136:72d8c84a8734

Release 1.0
author lost
date Tue, 27 Jan 2009 05:54:10 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
136
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
1 This is the companion linker to LWASM. It reads object files generated by
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
2 LWASM and combines them into an actual binary.
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
3
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
4 During linking, each file is read into memory. A list of externally
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
5 referenced symbols is made along with where these symbols are referenced.
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
6 Each external reference is checked against all previously loaded files (in
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
7 order of loading) and if a match is found, a note of that fact is made and a
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
8 link between the previously loaded file and the current reference.
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
9
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
10 Once all files are loaded, the symbol table is checked for any symbols which
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
11 are still unresolved. If any are found, the linking process complains and
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
12 bails out.
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
13
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
14 Once all the object files have been read, the linker follows a
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
15 pre-determined script for the specified target or a script supplied by the
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
16 user to lay out the binary. The instructions from the script are followed
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
17 blindly as it is assumed the user knows what he is doing.
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
18
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
19 For each defined section, the linker begins constructing the section data by
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
20 resolving each instance of that section in the order it was encountered. All
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
21 symbols defined by that section (local or exported) are assigned addresses.
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
22 The exact offset into the final section data is recorded for any incomplete
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
23 references in that section. All section base address references are resolved
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
24 to actual addresses at this stage.
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
25
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
26 Once all sections have been laid out and addresses assigned to all symbols,
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
27 all incomplete references are resolved and the resulting value placed into
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
28 the appropriate data stream. If any references cannot be resolved at this
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
29 stage, the linker will complain and bail out.
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
30
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
31 Once all sections, symbols, and incomplete references have been resolved,
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
32 the binary will output as appropriate for the specified target.
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
33
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
34 See the file "scripts.txt" for information about linker scripts and the
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
35 restrictions based on the output target.
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
36
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
37 The following output targets are supported:
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
38
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
39 Raw: this is a raw binary with no header information, etc. Suitable for ROM
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
40 images, etc. By default, the raw target starts the binary at address 0, puts
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
41 any section named "init" first, then "code", then all other non-bss
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
42 sections, then all bss sections. Note that any "bss" type section that
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
43 exists anywhere but at the end of the binary (i.e. is between or before one
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
44 or more non-bss sections) will be included as a series of NUL bytes.
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
45
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
46 DECB: this creates a LOADM style binary according to the linker script. By
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
47 default, this target places the sections in the same order as the raw target
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
48 but implements a load address of $2000. bss sections will not be included in
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
49 the actual output. If a bss section appears between two non-bss sections, a
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
50 new output block will be created in the output file.
72d8c84a8734 Release 1.0
lost
parents:
diff changeset
51