annotate doc/lwlink.txt @ 316:ba58dbe39c67 1.0

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