annotate src/link.c @ 302:eff969272fb9

resolve incomplete references done
author lost
date Wed, 21 Jan 2009 06:14:08 +0000
parents 376cc55361c7
children 13272197d278
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
301
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
1 /*
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
2 link.c
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
4
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
5 This file is part of LWLINK.
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
6
376cc55361c7 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
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
10 version.
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
11
376cc55361c7 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
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
15 more details.
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
16
376cc55361c7 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
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
19
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
20
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
21 Resolve section and symbol addresses; handle incomplete references
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
22 */
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
23
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
25 #include "config.h"
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
26 #endif
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
27
302
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
28 #include <stdio.h>
301
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
29 #include <stdlib.h>
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
30
302
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
31 #include "expr.h"
301
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
32 #include "lwlink.h"
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
33 #include "util.h"
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
34
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
35 struct section_list
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
36 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
37 section_t *ptr; // ptr to section structure
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
38 int forceaddr; // was this force to an address by the link script?
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
39 };
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
40
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
41 static struct section_list *sectlist = NULL;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
42 static int nsects = 0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
43
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
44 // work out section load order and resolve base addresses for each section
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
45 // make a list of sections to load in order
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
46 void resolve_sections(void)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
47 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
48 int laddr = 0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
49 int ln, sn, fn;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
50
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
51 for (ln = 0; ln < linkscript.nlines; ln++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
52 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
53 if (linkscript.lines[ln].sectname)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
54 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
55 int f = 0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
56 // named section
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
57 // look for all instances of a section by the specified name
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
58 // and resolve base addresses and add to the list
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
59 for (fn = 0; fn < ninputfiles; fn++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
60 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
61 for (sn = 0; sn < inputfiles[fn] -> nsections; sn++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
62 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
63 if (!strcmp(linkscript.lines[ln].sectname, inputfiles[fn] -> sections[sn].name))
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
64 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
65 // we have a match
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
66 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1));
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
67 sectlist[nsects].ptr = &(inputfiles[fn] -> sections[sn]);
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
68
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
69 inputfiles[fn] -> sections[sn].processed = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
70 if (!f && linkscript.lines[ln].loadat >= 0)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
71 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
72 f = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
73 sectlist[nsects].forceaddr = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
74 laddr = linkscript.lines[ln].loadat;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
75 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
76 else
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
77 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
78 sectlist[nsects].forceaddr = 0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
79 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
80 inputfiles[fn] -> sections[sn].loadaddress = laddr;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
81 nsects++;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
82 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
83 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
84 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
85 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
86 else
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
87 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
88 // wildcard section
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
89 // look for all sections not yet processed that match flags
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
90
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
91 int f = 0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
92 int fn0, sn0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
93 char *sname;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
94
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
95 // named section
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
96 // look for all instances of a section by the specified name
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
97 // and resolve base addresses and add to the list
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
98 for (fn0 = 0; fn0 < ninputfiles; fn0++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
99 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
100 for (sn0 = 0; sn0 < inputfiles[fn0] -> nsections; sn0++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
101 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
102 // ignore if the "no flags" bit says to
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
103 if (linkscript.lines[ln].noflags && (inputfiles[fn0] -> sections[sn0].flags & linkscript.lines[ln].noflags))
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
104 continue;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
105 // ignore unless the yes flags tell us not to
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
106 if (linkscript.lines[ln].yesflags && (inputfiles[fn0] -> sections[sn0].flags & linkscript.lines[ln].yesflags == 0))
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
107 continue;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
108 if (inputfiles[fn0] -> sections[sn0].processed == 0)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
109 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
110 sname = inputfiles[fn0] -> sections[sn0].name;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
111 for (fn = 0; fn < ninputfiles; fn++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
112 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
113 for (sn = 0; sn < inputfiles[fn] -> nsections; sn++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
114 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
115 if (!strcmp(sname, inputfiles[fn] -> sections[sn].name))
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
116 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
117 // we have a match
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
118 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1));
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
119 sectlist[nsects].ptr = &(inputfiles[fn] -> sections[sn]);
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
120
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
121 inputfiles[fn] -> sections[sn].processed = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
122 if (!f && linkscript.lines[ln].loadat >= 0)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
123 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
124 f = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
125 sectlist[nsects].forceaddr = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
126 laddr = linkscript.lines[ln].loadat;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
127 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
128 else
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
129 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
130 sectlist[nsects].forceaddr = 0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
131 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
132 inputfiles[fn] -> sections[sn].loadaddress = laddr;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
133 nsects++;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
134 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
135 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
136 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
137 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
138 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
139 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
140 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
141 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
142
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
143 // theoretically, all the base addresses are set now
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
144 }
302
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
145
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
146 // resolve all incomplete references now
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
147 // anything that is unresolvable at this stage will throw an error
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
148 // because we know the load address of every section now
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
149 lw_expr_stack_t *resolve_sym(char *sym, int symtype, void *state)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
150 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
151 section_t *sect = state;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
152 lw_expr_term_t *term;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
153 int val = 0, i, fn;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
154 lw_expr_stack_t *s;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
155 symtab_t *se;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
156
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
157 if (symtype == 1)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
158 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
159 // local symbol
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
160 if (!sym)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
161 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
162 val = sect -> loadaddress;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
163 goto out;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
164 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
165
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
166 // start with this section
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
167 for (se = sect -> localsyms; se; se = se -> next)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
168 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
169 if (!strcmp(se -> sym, sym))
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
170 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
171 val = se -> offset + sect -> loadaddress;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
172 goto out;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
173 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
174 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
175 // not in this section - check all sections in this file
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
176 for (i = 0; i < sect -> file -> nsections; i++)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
177 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
178 for (se = sect -> file -> sections[i].localsyms; se; se = se -> next)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
179 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
180 if (!strcmp(se -> sym, sym))
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
181 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
182 val = se -> offset + sect -> file -> sections[i].loadaddress;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
183 goto out;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
184 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
185 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
186 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
187 // not found
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
188 fprintf(stderr, "Local symbol %s not found in %s:%s\n", sym, sect -> file -> filename, sect -> name);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
189 exit(1);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
190 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
191 else
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
192 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
193 // external symbol
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
194 // read all files in order until found (or not found)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
195 for (fn = 0; fn < ninputfiles; fn++)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
196 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
197 for (i = 0; i < inputfiles[fn] -> nsections; i++)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
198 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
199 for (se = inputfiles[fn] -> sections[i].exportedsyms; se; se = se -> next)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
200 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
201 if (!strcmp(sym, se -> sym))
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
202 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
203 val = se -> offset + inputfiles[fn] -> sections[i].loadaddress;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
204 goto out;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
205 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
206 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
207 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
208 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
209 fprintf(stderr, "External symbol %s not found in %s:%s\n", sym, sect -> file -> filename, sect -> name);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
210 exit(1);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
211 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
212 fprintf(stderr, "Shouldn't ever get here!!!\n");
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
213 exit(88);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
214 out:
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
215 s = lw_expr_stack_create();
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
216 term = lw_expr_term_create_int(val & 0xffff);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
217 lw_expr_stack_push(s, term);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
218 lw_expr_term_free(term);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
219 return s;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
220 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
221
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
222 void resolve_references(void)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
223 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
224 int sn;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
225 reloc_t *rl;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
226 int rval;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
227
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
228 for (sn = 0; nsects; sn++)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
229 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
230 for (rl = sectlist[sn].ptr -> incompletes; rl; rl = rl -> next)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
231 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
232 // do a "simplify" on the expression
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
233 rval = lw_expr_reval(rl -> expr, resolve_sym, sectlist[sn].ptr);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
234
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
235 // is it constant? error out if not
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
236 if (rval != 0 || !lw_expr_is_constant(rl -> expr))
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
237 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
238 fprintf(stderr, "Incomplete reference at %s:%s:%02X\n", sectlist[sn].ptr -> file -> filename, sectlist[sn].ptr -> name, rl -> offset);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
239 exit(1);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
240 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
241
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
242 // put the value into the relocation address
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
243 rval = lw_expr_get_value(rl -> expr);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
244 sectlist[sn].ptr -> code[rl -> offset] = (rval >> 8) & 0xff;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
245 sectlist[sn].ptr -> code[rl -> offset + 1] = rval & 0xff;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
246 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
247 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
248 }