annotate lwlink/link.c @ 243:f9f01a499525 2.x

Added zero-width external references
author lost
date Tue, 15 Sep 2009 03:16:17 +0000
parents bae1e3ecdce1
children eb499c146c0d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
119
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
1 /*
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
2 link.c
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
4
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
5 This file is part of LWLINK.
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
6
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
7 LWLINK is free software: you can redistribute it and/or modify it under the
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
10 version.
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
11
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
15 more details.
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
16
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
19
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
20
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
21 Resolve section and symbol addresses; handle incomplete references
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
22 */
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
23
212
bae1e3ecdce1 More preparation for gnulib integration
lost
parents: 206
diff changeset
24 #include <config.h>
119
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
25
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
26 #include <stdio.h>
119
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
27 #include <stdlib.h>
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
28
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
29 #include "expr.h"
119
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
30 #include "lwlink.h"
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
31 #include "util.h"
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
32
121
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
33 struct section_list *sectlist = NULL;
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
34 int nsects = 0;
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
35 static int nforced = 0;
119
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
36
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
37 void check_section_name(char *name, int *base, fileinfo_t *fn)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
38 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
39 int sn;
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
40
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
41 if (fn -> forced == 0)
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
42 return;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
43
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
44 for (sn = 0; sn < fn -> nsections; sn++)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
45 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
46 if (!strcmp(name, fn -> sections[sn].name))
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
47 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
48 // we have a match
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
49 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1));
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
50 sectlist[nsects].ptr = &(fn -> sections[sn]);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
51
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
52 fn -> sections[sn].processed = 1;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
53 fn -> sections[sn].loadaddress = *base;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
54 *base += fn -> sections[sn].codesize;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
55 nsects++;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
56 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
57 }
173
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
58 for (sn = 0; sn < fn -> nsubs; sn++)
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
59 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
60 check_section_name(name, base, fn -> subs[sn]);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
61 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
62 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
63
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
64 void add_matching_sections(char *name, int yesflags, int noflags, int *base);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
65 void check_section_flags(int yesflags, int noflags, int *base, fileinfo_t *fn)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
66 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
67 int sn;
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
68
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
69 if (fn -> forced == 0)
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
70 return;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
71
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
72 for (sn = 0; sn < fn -> nsections; sn++)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
73 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
74 // ignore if the noflags tell us to
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
75 if (noflags && (fn -> sections[sn].flags & noflags))
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
76 continue;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
77 // ignore unless the yesflags tell us not to
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
78 if (yesflags && (fn -> sections[sn].flags & yesflags == 0))
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
79 continue;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
80 // ignore it if already processed
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
81 if (fn -> sections[sn].processed)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
82 continue;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
83
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
84 // we have a match - now collect *all* sections of the same name!
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
85 add_matching_sections(fn -> sections[sn].name, 0, 0, base);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
86
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
87 // and then continue looking for sections
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
88 }
173
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
89 for (sn = 0; sn < fn -> nsubs; sn++)
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
90 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
91 check_section_flags(yesflags, noflags, base, fn -> subs[sn]);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
92 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
93 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
94
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
95
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
96
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
97 void add_matching_sections(char *name, int yesflags, int noflags, int *base)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
98 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
99 int fn;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
100 if (name)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
101 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
102 // named section
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
103 // look for all instances of a section by the specified name
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
104 // and resolve base addresses and add to the list
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
105 for (fn = 0; fn < ninputfiles; fn++)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
106 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
107 check_section_name(name, base, inputfiles[fn]);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
108 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
109 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
110 else
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
111 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
112 // wildcard section
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
113 // named section
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
114 // look for all instances of a section by the specified name
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
115 // and resolve base addresses and add to the list
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
116 for (fn = 0; fn < ninputfiles; fn++)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
117 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
118 check_section_flags(yesflags, noflags, base, inputfiles[fn]);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
119 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
120 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
121 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
122
119
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
123 // work out section load order and resolve base addresses for each section
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
124 // make a list of sections to load in order
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
125 void resolve_sections(void)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
126 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
127 int laddr = 0;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
128 int ln, sn, fn;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
129
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
130 for (ln = 0; ln < linkscript.nlines; ln++)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
131 {
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
132 if (linkscript.lines[ln].loadat >= 0)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
133 laddr = linkscript.lines[ln].loadat;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
134 add_matching_sections(linkscript.lines[ln].sectname, linkscript.lines[ln].yesflags, linkscript.lines[ln].noflags, &laddr);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
135
119
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
136 if (linkscript.lines[ln].sectname)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
137 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
138 }
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
139 else
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
140 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
141 // wildcard section
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
142 // look for all sections not yet processed that match flags
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
143
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
144 int f = 0;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
145 int fn0, sn0;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
146 char *sname;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
147
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
148 // named section
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
149 // look for all instances of a section by the specified name
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
150 // and resolve base addresses and add to the list
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
151 for (fn0 = 0; fn0 < ninputfiles; fn0++)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
152 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
153 for (sn0 = 0; sn0 < inputfiles[fn0] -> nsections; sn0++)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
154 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
155 // ignore if the "no flags" bit says to
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
156 if (linkscript.lines[ln].noflags && (inputfiles[fn0] -> sections[sn0].flags & linkscript.lines[ln].noflags))
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
157 continue;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
158 // ignore unless the yes flags tell us not to
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
159 if (linkscript.lines[ln].yesflags && (inputfiles[fn0] -> sections[sn0].flags & linkscript.lines[ln].yesflags == 0))
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
160 continue;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
161 if (inputfiles[fn0] -> sections[sn0].processed == 0)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
162 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
163 sname = inputfiles[fn0] -> sections[sn0].name;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
164 for (fn = 0; fn < ninputfiles; fn++)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
165 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
166 for (sn = 0; sn < inputfiles[fn] -> nsections; sn++)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
167 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
168 if (!strcmp(sname, inputfiles[fn] -> sections[sn].name))
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
169 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
170 // we have a match
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
171 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1));
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
172 sectlist[nsects].ptr = &(inputfiles[fn] -> sections[sn]);
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
173
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
174 inputfiles[fn] -> sections[sn].processed = 1;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
175 if (!f && linkscript.lines[ln].loadat >= 0)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
176 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
177 f = 1;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
178 sectlist[nsects].forceaddr = 1;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
179 laddr = linkscript.lines[ln].loadat;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
180 }
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
181 else
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
182 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
183 sectlist[nsects].forceaddr = 0;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
184 }
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
185 inputfiles[fn] -> sections[sn].loadaddress = laddr;
131
5276565799bd Fixed load addresses of chained sections and subsections to actually increment
lost
parents: 130
diff changeset
186 laddr += inputfiles[fn] -> sections[sn].codesize;
119
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
187 nsects++;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
188 }
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
189 }
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
190 }
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
191 }
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
192 }
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
193 }
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
194 }
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
195 }
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
196
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
197 // theoretically, all the base addresses are set now
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
198 }
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
199
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
200 lw_expr_stack_t *find_external_sym_recurse(char *sym, fileinfo_t *fn)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
201 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
202 int sn;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
203 lw_expr_stack_t *r;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
204 lw_expr_term_t *term;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
205 symtab_t *se;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
206 int val;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
207
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
208 for (sn = 0; sn < fn -> nsections; sn++)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
209 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
210 for (se = fn -> sections[sn].exportedsyms; se; se = se -> next)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
211 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
212 if (!strcmp(sym, se -> sym))
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
213 {
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
214 if (!(fn -> forced))
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
215 {
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
216 fn -> forced = 1;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
217 nforced = 1;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
218 }
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
219 val = se -> offset + fn -> sections[sn].loadaddress;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
220 r = lw_expr_stack_create();
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
221 term = lw_expr_term_create_int(val & 0xffff);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
222 lw_expr_stack_push(r, term);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
223 lw_expr_term_free(term);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
224 return r;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
225 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
226 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
227 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
228
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
229 for (sn = 0; sn < fn -> nsubs; sn++)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
230 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
231 r = find_external_sym_recurse(sym, fn -> subs[sn]);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
232 if (r)
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
233 {
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
234 if (!(fn -> forced))
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
235 {
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
236 nforced = 1;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
237 fn -> forced = 1;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
238 }
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
239 return r;
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
240 }
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
241 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
242 return NULL;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
243 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
244
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
245 // resolve all incomplete references now
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
246 // anything that is unresolvable at this stage will throw an error
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
247 // because we know the load address of every section now
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
248 lw_expr_stack_t *resolve_sym(char *sym, int symtype, void *state)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
249 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
250 section_t *sect = state;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
251 lw_expr_term_t *term;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
252 int val = 0, i, fn;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
253 lw_expr_stack_t *s;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
254 symtab_t *se;
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
255 fileinfo_t *fp;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
256
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
257 if (symtype == 1)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
258 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
259 // local symbol
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
260 if (!sym)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
261 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
262 val = sect -> loadaddress;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
263 goto out;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
264 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
265
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
266 // start with this section
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
267 for (se = sect -> localsyms; se; se = se -> next)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
268 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
269 if (!strcmp(se -> sym, sym))
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
270 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
271 val = se -> offset + sect -> loadaddress;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
272 goto out;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
273 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
274 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
275 // not in this section - check all sections in this file
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
276 for (i = 0; i < sect -> file -> nsections; i++)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
277 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
278 for (se = sect -> file -> sections[i].localsyms; se; se = se -> next)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
279 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
280 if (!strcmp(se -> sym, sym))
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
281 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
282 val = se -> offset + sect -> file -> sections[i].loadaddress;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
283 goto out;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
284 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
285 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
286 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
287 // not found
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
288 symerr = 1;
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
289 fprintf(stderr, "Local symbol %s not found in %s:%s\n", sym, sect -> file -> filename, sect -> name);
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
290 goto outerr;
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
291 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
292 else
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
293 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
294 // external symbol
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
295 // read all files in order until found (or not found)
173
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
296 if (sect)
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
297 {
173
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
298 for (fp = sect -> file; fp; fp = fp -> parent)
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
299 {
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
300 s = find_external_sym_recurse(sym, fp);
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
301 if (s)
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
302 return s;
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
303 }
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
304 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
305
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
306 for (fn = 0; fn < ninputfiles; fn++)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
307 {
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
308 s = find_external_sym_recurse(sym, inputfiles[fn]);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
309 if (s)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
310 return s;
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
311 }
130
8349048d67b3 Fixed crash when entry symbol is not exported
lost
parents: 126
diff changeset
312 if (sect)
8349048d67b3 Fixed crash when entry symbol is not exported
lost
parents: 126
diff changeset
313 {
8349048d67b3 Fixed crash when entry symbol is not exported
lost
parents: 126
diff changeset
314 fprintf(stderr, "External symbol %s not found in %s:%s\n", sym, sect -> file -> filename, sect -> name);
8349048d67b3 Fixed crash when entry symbol is not exported
lost
parents: 126
diff changeset
315 }
8349048d67b3 Fixed crash when entry symbol is not exported
lost
parents: 126
diff changeset
316 else
8349048d67b3 Fixed crash when entry symbol is not exported
lost
parents: 126
diff changeset
317 {
8349048d67b3 Fixed crash when entry symbol is not exported
lost
parents: 126
diff changeset
318 fprintf(stderr, "External symbol %s not found\n", sym);
8349048d67b3 Fixed crash when entry symbol is not exported
lost
parents: 126
diff changeset
319 }
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
320 symerr = 1;
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
321 goto outerr;
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
322 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
323 fprintf(stderr, "Shouldn't ever get here!!!\n");
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
324 exit(88);
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
325 out:
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
326 s = lw_expr_stack_create();
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
327 term = lw_expr_term_create_int(val & 0xffff);
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
328 lw_expr_stack_push(s, term);
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
329 lw_expr_term_free(term);
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
330 return s;
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
331 outerr:
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
332 return NULL;
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
333 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
334
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
335 void resolve_references(void)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
336 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
337 int sn;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
338 reloc_t *rl;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
339 int rval;
121
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
340
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
341 // resolve entry point if required
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
342 // this must resolve to an *exported* symbol and will resolve to the
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
343 // first instance of that symbol
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
344 if (linkscript.execsym)
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
345 {
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
346 lw_expr_stack_t *s;
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
347
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
348 s = resolve_sym(linkscript.execsym, 0, NULL);
187
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
349 if (!s)
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
350 {
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
351 fprintf(stderr, "Cannot resolve exec address '%s'\n", linkscript.execsym);
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
352 symerr = 1;
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
353 }
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
354 else
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
355 {
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
356 linkscript.execaddr = lw_expr_get_value(s);
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
357 lw_expr_stack_free(s);
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
358 }
121
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
359 }
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
360
124
4ac96c697ef0 Corrected errors with parsing script and object files
lost
parents: 121
diff changeset
361 for (sn = 0; sn < nsects; sn++)
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
362 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
363 for (rl = sectlist[sn].ptr -> incompletes; rl; rl = rl -> next)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
364 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
365 // do a "simplify" on the expression
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
366 rval = lw_expr_reval(rl -> expr, resolve_sym, sectlist[sn].ptr);
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
367
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
368 // is it constant? error out if not
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
369 if (rval != 0 || !lw_expr_is_constant(rl -> expr))
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
370 {
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
371 fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", sectlist[sn].ptr -> file -> filename, sectlist[sn].ptr -> name, rl -> offset);
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
372 symerr = 1;
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
373 }
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
374 else
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
375 {
243
f9f01a499525 Added zero-width external references
lost
parents: 212
diff changeset
376 // is it a zero-width link?
f9f01a499525 Added zero-width external references
lost
parents: 212
diff changeset
377 if (rl -> flags & RELOC_0BIT)
f9f01a499525 Added zero-width external references
lost
parents: 212
diff changeset
378 continue;
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
379 // put the value into the relocation address
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
380 rval = lw_expr_get_value(rl -> expr);
204
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
381 if (rl -> flags & RELOC_8BIT)
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
382 {
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
383 sectlist[sn].ptr -> code[rl -> offset] = rval & 0xff;
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
384 }
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
385 else
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
386 {
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
387 sectlist[sn].ptr -> code[rl -> offset] = (rval >> 8) & 0xff;
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
388 sectlist[sn].ptr -> code[rl -> offset + 1] = rval & 0xff;
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
389 }
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
390 }
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
391 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
392 }
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
393
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
394 if (symerr)
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
395 exit(1);
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
396 }
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
397
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
398 /*
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
399 This is just a pared down version of the algo for resolving references.
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
400 */
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
401 void resolve_files(void)
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
402 {
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
403 int sn;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
404 int fn;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
405 reloc_t *rl;
206
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
406 lw_expr_stack_t *te;
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
407
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
408 int rval;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
409
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
410 // resolve entry point if required
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
411 // this must resolve to an *exported* symbol and will resolve to the
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
412 // first instance of that symbol
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
413 if (linkscript.execsym)
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
414 {
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
415 lw_expr_stack_t *s;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
416
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
417 s = resolve_sym(linkscript.execsym, 0, NULL);
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
418 if (!s)
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
419 {
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
420 fprintf(stderr, "Cannot resolve exec address '%s'\n", linkscript.execsym);
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
421 symerr = 1;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
422 }
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
423 }
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
424
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
425 do
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
426 {
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
427 nforced = 0;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
428 for (fn = 0; fn < ninputfiles; fn++)
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
429 {
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
430 if (inputfiles[fn] -> forced == 0)
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
431 continue;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
432
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
433 for (sn = 0; sn < inputfiles[fn] -> nsections; sn++)
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
434 {
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
435 for (rl = inputfiles[fn] -> sections[sn].incompletes; rl; rl = rl -> next)
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
436 {
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
437 // do a "simplify" on the expression
206
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
438 te = lw_expr_stack_dup(rl -> expr);
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
439 rval = lw_expr_reval(te, resolve_sym, &(inputfiles[fn] -> sections[sn]));
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
440
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
441 // is it constant? error out if not
206
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
442 if (rval != 0 || !lw_expr_is_constant(te))
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
443 {
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
444 fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", inputfiles[fn] -> filename, inputfiles[fn] -> sections[sn].name, rl -> offset);
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
445 symerr = 1;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
446 }
206
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
447 lw_expr_stack_free(te);
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
448 }
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
449 }
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
450 }
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
451 }
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
452 while (nforced == 1);
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
453
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
454 if (symerr)
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
455 exit(1);
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
456
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
457 // theoretically, all files referenced by other files now have "forced" set to 1
206
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
458 for (fn = 0; fn < ninputfiles; fn++)
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
459 {
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
460 if (inputfiles[fn] -> forced == 1)
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
461 continue;
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
462
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
463 fprintf(stderr, "Warning: %s (%d) does not resolve any symbols\n", inputfiles[fn] -> filename, fn);
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
464 }
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
465 }