annotate src/link.c @ 308:ecc092adc0be

Fixed stupid logic problem reading input files
author lost
date Fri, 23 Jan 2009 05:10:33 +0000
parents be1abc4ac114
children 5dc105fd619e
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
303
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
35 struct section_list *sectlist = NULL;
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
36 int nsects = 0;
301
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
37
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
38 // work out section load order and resolve base addresses for each section
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
39 // make a list of sections to load in order
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
40 void resolve_sections(void)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
41 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
42 int laddr = 0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
43 int ln, sn, fn;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
44
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
45 for (ln = 0; ln < linkscript.nlines; ln++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
46 {
308
ecc092adc0be Fixed stupid logic problem reading input files
lost
parents: 306
diff changeset
47 // printf("Linker script line %d: '%s', %04X, %d, %d\n", ln, linkscript.lines[ln].sectname, linkscript.lines[ln].loadat, linkscript.lines[ln].yesflags, linkscript.lines[ln].noflags);
301
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
48 if (linkscript.lines[ln].sectname)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
49 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
50 int f = 0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
51 // named section
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
52 // look for all instances of a section by the specified name
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
53 // and resolve base addresses and add to the list
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
54 for (fn = 0; fn < ninputfiles; fn++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
55 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
56 for (sn = 0; sn < inputfiles[fn] -> nsections; sn++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
57 {
308
ecc092adc0be Fixed stupid logic problem reading input files
lost
parents: 306
diff changeset
58 // printf(" Considering %s:%s\n", inputfiles[fn]->filename, inputfiles[fn]->sections[sn].name);
301
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
59 if (!strcmp(linkscript.lines[ln].sectname, inputfiles[fn] -> sections[sn].name))
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
60 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
61 // we have a match
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
62 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1));
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
63 sectlist[nsects].ptr = &(inputfiles[fn] -> sections[sn]);
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
64
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
65 inputfiles[fn] -> sections[sn].processed = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
66 if (!f && linkscript.lines[ln].loadat >= 0)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
67 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
68 f = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
69 sectlist[nsects].forceaddr = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
70 laddr = linkscript.lines[ln].loadat;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
71 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
72 else
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
73 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
74 sectlist[nsects].forceaddr = 0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
75 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
76 inputfiles[fn] -> sections[sn].loadaddress = laddr;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
77 nsects++;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
78 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
79 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
80 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
81 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
82 else
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
83 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
84 // wildcard section
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
85 // look for all sections not yet processed that match flags
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
86
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
87 int f = 0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
88 int fn0, sn0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
89 char *sname;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
90
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
91 // named section
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
92 // look for all instances of a section by the specified name
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
93 // and resolve base addresses and add to the list
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
94 for (fn0 = 0; fn0 < ninputfiles; fn0++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
95 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
96 for (sn0 = 0; sn0 < inputfiles[fn0] -> nsections; sn0++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
97 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
98 // ignore if the "no flags" bit says to
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
99 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
100 continue;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
101 // ignore unless the yes flags tell us not to
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
102 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
103 continue;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
104 if (inputfiles[fn0] -> sections[sn0].processed == 0)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
105 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
106 sname = inputfiles[fn0] -> sections[sn0].name;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
107 for (fn = 0; fn < ninputfiles; fn++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
108 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
109 for (sn = 0; sn < inputfiles[fn] -> nsections; sn++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
110 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
111 if (!strcmp(sname, inputfiles[fn] -> sections[sn].name))
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
112 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
113 // we have a match
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
114 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1));
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
115 sectlist[nsects].ptr = &(inputfiles[fn] -> sections[sn]);
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
116
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
117 inputfiles[fn] -> sections[sn].processed = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
118 if (!f && linkscript.lines[ln].loadat >= 0)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
119 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
120 f = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
121 sectlist[nsects].forceaddr = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
122 laddr = linkscript.lines[ln].loadat;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
123 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
124 else
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
125 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
126 sectlist[nsects].forceaddr = 0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
127 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
128 inputfiles[fn] -> sections[sn].loadaddress = laddr;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
129 nsects++;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
130 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
131 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
132 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
133 }
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 // theoretically, all the base addresses are set now
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
140 }
302
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
141
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
142 // resolve all incomplete references now
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
143 // anything that is unresolvable at this stage will throw an error
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
144 // because we know the load address of every section now
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
145 lw_expr_stack_t *resolve_sym(char *sym, int symtype, void *state)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
146 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
147 section_t *sect = state;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
148 lw_expr_term_t *term;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
149 int val = 0, i, fn;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
150 lw_expr_stack_t *s;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
151 symtab_t *se;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
152
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
153 if (symtype == 1)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
154 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
155 // local symbol
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
156 if (!sym)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
157 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
158 val = sect -> loadaddress;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
159 goto out;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
160 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
161
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
162 // start with this section
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
163 for (se = sect -> localsyms; se; se = se -> next)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
164 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
165 if (!strcmp(se -> sym, sym))
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
166 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
167 val = se -> offset + sect -> loadaddress;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
168 goto out;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
169 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
170 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
171 // not in this section - check all sections in this file
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
172 for (i = 0; i < sect -> file -> nsections; i++)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
173 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
174 for (se = sect -> file -> sections[i].localsyms; se; se = se -> next)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
175 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
176 if (!strcmp(se -> sym, sym))
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
177 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
178 val = se -> offset + sect -> file -> sections[i].loadaddress;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
179 goto out;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
180 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
181 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
182 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
183 // not found
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
184 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
185 exit(1);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
186 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
187 else
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
188 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
189 // external symbol
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
190 // read all files in order until found (or not found)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
191 for (fn = 0; fn < ninputfiles; fn++)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
192 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
193 for (i = 0; i < inputfiles[fn] -> nsections; i++)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
194 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
195 for (se = inputfiles[fn] -> sections[i].exportedsyms; se; se = se -> next)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
196 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
197 if (!strcmp(sym, se -> sym))
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
198 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
199 val = se -> offset + inputfiles[fn] -> sections[i].loadaddress;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
200 goto out;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
201 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
202 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
203 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
204 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
205 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
206 exit(1);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
207 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
208 fprintf(stderr, "Shouldn't ever get here!!!\n");
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
209 exit(88);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
210 out:
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
211 s = lw_expr_stack_create();
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
212 term = lw_expr_term_create_int(val & 0xffff);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
213 lw_expr_stack_push(s, term);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
214 lw_expr_term_free(term);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
215 return s;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
216 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
217
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
218 void resolve_references(void)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
219 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
220 int sn;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
221 reloc_t *rl;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
222 int rval;
303
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
223
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
224 // resolve entry point if required
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
225 // this must resolve to an *exported* symbol and will resolve to the
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
226 // first instance of that symbol
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
227 if (linkscript.execsym)
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
228 {
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
229 lw_expr_stack_t *s;
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
230
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
231 s = resolve_sym(linkscript.execsym, 0, NULL);
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
232 linkscript.execaddr = lw_expr_get_value(s);
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
233 lw_expr_stack_free(s);
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
234 }
302
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
235
306
be1abc4ac114 Corrected errors with parsing script and object files
lost
parents: 303
diff changeset
236 for (sn = 0; sn < nsects; sn++)
302
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
237 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
238 for (rl = sectlist[sn].ptr -> incompletes; rl; rl = rl -> next)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
239 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
240 // do a "simplify" on the expression
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
241 rval = lw_expr_reval(rl -> expr, resolve_sym, sectlist[sn].ptr);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
242
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
243 // is it constant? error out if not
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
244 if (rval != 0 || !lw_expr_is_constant(rl -> expr))
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
245 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
246 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
247 exit(1);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
248 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
249
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
250 // put the value into the relocation address
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
251 rval = lw_expr_get_value(rl -> expr);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
252 sectlist[sn].ptr -> code[rl -> offset] = (rval >> 8) & 0xff;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
253 sectlist[sn].ptr -> code[rl -> offset + 1] = rval & 0xff;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
254 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
255 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
256 }