annotate lwlink/trunk/doc/lwlink.txt @ 122:2ece9adb4e4b

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