153
|
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
|
|
2 <HTML
|
|
3 ><HEAD
|
|
4 ><TITLE
|
|
5 >Linker Operation</TITLE
|
|
6 ><META
|
|
7 NAME="GENERATOR"
|
|
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
|
|
9 REL="HOME"
|
|
10 TITLE="LW Tool Chain"
|
|
11 HREF="index.html"><LINK
|
|
12 REL="UP"
|
|
13 TITLE="LWLINK"
|
|
14 HREF="c436.html"><LINK
|
|
15 REL="PREVIOUS"
|
|
16 TITLE="LWLINK"
|
|
17 HREF="c436.html"><LINK
|
|
18 REL="NEXT"
|
|
19 TITLE="Linking Scripts"
|
|
20 HREF="x524.html"></HEAD
|
|
21 ><BODY
|
|
22 CLASS="SECTION"
|
|
23 BGCOLOR="#FFFFFF"
|
|
24 TEXT="#000000"
|
|
25 LINK="#0000FF"
|
|
26 VLINK="#840084"
|
|
27 ALINK="#0000FF"
|
|
28 ><DIV
|
|
29 CLASS="NAVHEADER"
|
|
30 ><TABLE
|
|
31 SUMMARY="Header navigation table"
|
|
32 WIDTH="100%"
|
|
33 BORDER="0"
|
|
34 CELLPADDING="0"
|
|
35 CELLSPACING="0"
|
|
36 ><TR
|
|
37 ><TH
|
|
38 COLSPAN="3"
|
|
39 ALIGN="center"
|
|
40 >LW Tool Chain</TH
|
|
41 ></TR
|
|
42 ><TR
|
|
43 ><TD
|
|
44 WIDTH="10%"
|
|
45 ALIGN="left"
|
|
46 VALIGN="bottom"
|
|
47 ><A
|
|
48 HREF="c436.html"
|
|
49 ACCESSKEY="P"
|
|
50 >Prev</A
|
|
51 ></TD
|
|
52 ><TD
|
|
53 WIDTH="80%"
|
|
54 ALIGN="center"
|
|
55 VALIGN="bottom"
|
|
56 >Chapter 4. LWLINK</TD
|
|
57 ><TD
|
|
58 WIDTH="10%"
|
|
59 ALIGN="right"
|
|
60 VALIGN="bottom"
|
|
61 ><A
|
|
62 HREF="x524.html"
|
|
63 ACCESSKEY="N"
|
|
64 >Next</A
|
|
65 ></TD
|
|
66 ></TR
|
|
67 ></TABLE
|
|
68 ><HR
|
|
69 ALIGN="LEFT"
|
|
70 WIDTH="100%"></DIV
|
|
71 ><DIV
|
|
72 CLASS="SECTION"
|
|
73 ><H1
|
|
74 CLASS="SECTION"
|
|
75 ><A
|
|
76 NAME="AEN510"
|
|
77 >4.2. Linker Operation</A
|
|
78 ></H1
|
|
79 ><P
|
|
80 >LWLINK takes one or more files in the LWTOOLS object file format and links
|
|
81 them into a single binary. While the precise method is slightly different,
|
|
82 linking can be conceptualized as the following steps.</P
|
|
83 ><P
|
|
84 ></P
|
|
85 ><OL
|
|
86 TYPE="1"
|
|
87 ><LI
|
|
88 ><P
|
|
89 >First, the linker loads a linking script. If no script is specified, it
|
|
90 loads a built-in default script based on the output format selected. This
|
|
91 script tells the linker how to lay out the various sections in the final
|
|
92 binary.</P
|
|
93 ></LI
|
|
94 ><LI
|
|
95 ><P
|
|
96 >Next, the linker reads all the input files into memory. At this time, it
|
|
97 flags any format errors in those files. It constructs a table of symbols
|
|
98 for each object at this time.</P
|
|
99 ></LI
|
|
100 ><LI
|
|
101 ><P
|
|
102 >The linker then proceeds with organizing the sections loaded from each file
|
|
103 according to the linking script. As it does so, it is able to assign addresses
|
|
104 to each symbol defined in each object file. At this time, the linker may
|
|
105 also collapse different instances of the same section name into a single
|
|
106 section by appending the data from each subsequent instance of the section
|
|
107 to the first instance of the section.</P
|
|
108 ></LI
|
|
109 ><LI
|
|
110 ><P
|
|
111 >Next, the linker looks through every object file for every incomplete reference.
|
|
112 It then attempts to fully resolve that reference. If it cannot do so, it
|
|
113 throws an error. Once a reference is resolved, the value is placed into
|
|
114 the binary code at the specified section. It should be noted that an
|
|
115 incomplete reference can reference either a symbol internal to the object
|
|
116 file or an external symbol which is in the export list of another object
|
|
117 file.</P
|
|
118 ></LI
|
|
119 ><LI
|
|
120 ><P
|
|
121 >If all of the above steps are successful, the linker opens the output file
|
|
122 and actually constructs the binary.</P
|
|
123 ></LI
|
|
124 ></OL
|
|
125 ></DIV
|
|
126 ><DIV
|
|
127 CLASS="NAVFOOTER"
|
|
128 ><HR
|
|
129 ALIGN="LEFT"
|
|
130 WIDTH="100%"><TABLE
|
|
131 SUMMARY="Footer navigation table"
|
|
132 WIDTH="100%"
|
|
133 BORDER="0"
|
|
134 CELLPADDING="0"
|
|
135 CELLSPACING="0"
|
|
136 ><TR
|
|
137 ><TD
|
|
138 WIDTH="33%"
|
|
139 ALIGN="left"
|
|
140 VALIGN="top"
|
|
141 ><A
|
|
142 HREF="c436.html"
|
|
143 ACCESSKEY="P"
|
|
144 >Prev</A
|
|
145 ></TD
|
|
146 ><TD
|
|
147 WIDTH="34%"
|
|
148 ALIGN="center"
|
|
149 VALIGN="top"
|
|
150 ><A
|
|
151 HREF="index.html"
|
|
152 ACCESSKEY="H"
|
|
153 >Home</A
|
|
154 ></TD
|
|
155 ><TD
|
|
156 WIDTH="33%"
|
|
157 ALIGN="right"
|
|
158 VALIGN="top"
|
|
159 ><A
|
|
160 HREF="x524.html"
|
|
161 ACCESSKEY="N"
|
|
162 >Next</A
|
|
163 ></TD
|
|
164 ></TR
|
|
165 ><TR
|
|
166 ><TD
|
|
167 WIDTH="33%"
|
|
168 ALIGN="left"
|
|
169 VALIGN="top"
|
|
170 >LWLINK</TD
|
|
171 ><TD
|
|
172 WIDTH="34%"
|
|
173 ALIGN="center"
|
|
174 VALIGN="top"
|
|
175 ><A
|
|
176 HREF="c436.html"
|
|
177 ACCESSKEY="U"
|
|
178 >Up</A
|
|
179 ></TD
|
|
180 ><TD
|
|
181 WIDTH="33%"
|
|
182 ALIGN="right"
|
|
183 VALIGN="top"
|
|
184 >Linking Scripts</TD
|
|
185 ></TR
|
|
186 ></TABLE
|
|
187 ></DIV
|
|
188 ></BODY
|
|
189 ></HTML
|
|
190 > |