annotate lwlink/link.c @ 265:68fbca173508 2.6

Added generated files for release
author lost
date Tue, 22 Dec 2009 05:31:23 +0000
parents e8d70b95ec41
children
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;
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
36 static fileinfo_t *lookingfrom;
119
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
37
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
38 void check_section_name(char *name, int *base, fileinfo_t *fn)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
39 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
40 int sn;
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
41
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
42 if (fn -> forced != 0)
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
43 {
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
44 for (sn = 0; sn < fn -> nsections; sn++)
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
45 {
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
46 if (!strcmp(name, fn -> sections[sn].name))
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
47 {
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
48 // we have a match
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
49 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1));
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
50 sectlist[nsects].ptr = &(fn -> sections[sn]);
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
51
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
52 fn -> sections[sn].processed = 1;
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
53 fn -> sections[sn].loadaddress = *base;
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
54 *base += fn -> sections[sn].codesize;
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
55 nsects++;
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
56 }
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
57 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
58 }
173
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
59 for (sn = 0; sn < fn -> nsubs; sn++)
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
60 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
61 check_section_name(name, base, fn -> subs[sn]);
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
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
65 void add_matching_sections(char *name, int yesflags, int noflags, int *base);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
66 void check_section_flags(int yesflags, int noflags, int *base, fileinfo_t *fn)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
67 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
68 int sn;
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
69
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
70 if (fn -> forced != 0)
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
71 {
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
72 for (sn = 0; sn < fn -> nsections; sn++)
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
73 {
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
74 // ignore if the noflags tell us to
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
75 if (noflags && (fn -> sections[sn].flags & noflags))
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
76 continue;
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
77 // ignore unless the yesflags tell us not to
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
78 if (yesflags && (fn -> sections[sn].flags & yesflags == 0))
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
79 continue;
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
80 // ignore it if already processed
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
81 if (fn -> sections[sn].processed)
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
82 continue;
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
83
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
84 // we have a match - now collect *all* sections of the same name!
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
85 add_matching_sections(fn -> sections[sn].name, 0, 0, base);
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
86
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
87 // and then continue looking for sections
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
88 }
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
89 }
173
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
90 for (sn = 0; sn < fn -> nsubs; sn++)
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
91 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
92 check_section_flags(yesflags, noflags, base, fn -> subs[sn]);
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
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
98 void add_matching_sections(char *name, int yesflags, int noflags, int *base)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
99 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
100 int fn;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
101 if (name)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
102 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
103 // named section
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
104 // look for all instances of a section by the specified name
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
105 // and resolve base addresses and add to the list
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
106 for (fn = 0; fn < ninputfiles; fn++)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
107 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
108 check_section_name(name, base, inputfiles[fn]);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
109 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
110 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
111 else
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
112 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
113 // wildcard section
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
114 // named section
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
115 // look for all instances of a section by the specified name
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
116 // and resolve base addresses and add to the list
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
117 for (fn = 0; fn < ninputfiles; fn++)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
118 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
119 check_section_flags(yesflags, noflags, base, inputfiles[fn]);
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 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
123
119
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
124 // work out section load order and resolve base addresses for each section
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
125 // make a list of sections to load in order
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
126 void resolve_sections(void)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
127 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
128 int laddr = 0;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
129 int ln, sn, fn;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
130
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
131 for (ln = 0; ln < linkscript.nlines; ln++)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
132 {
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
133 if (linkscript.lines[ln].loadat >= 0)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
134 laddr = linkscript.lines[ln].loadat;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
135 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
136
119
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
137 if (linkscript.lines[ln].sectname)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
138 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
139 }
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
140 else
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
141 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
142 // wildcard section
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
143 // look for all sections not yet processed that match flags
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
144
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
145 int f = 0;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
146 int fn0, sn0;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
147 char *sname;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
148
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
149 // named section
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
150 // look for all instances of a section by the specified name
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
151 // and resolve base addresses and add to the list
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
152 for (fn0 = 0; fn0 < ninputfiles; fn0++)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
153 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
154 for (sn0 = 0; sn0 < inputfiles[fn0] -> nsections; sn0++)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
155 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
156 // ignore if the "no flags" bit says to
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
157 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
158 continue;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
159 // ignore unless the yes flags tell us not to
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
160 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
161 continue;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
162 if (inputfiles[fn0] -> sections[sn0].processed == 0)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
163 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
164 sname = inputfiles[fn0] -> sections[sn0].name;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
165 for (fn = 0; fn < ninputfiles; fn++)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
166 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
167 for (sn = 0; sn < inputfiles[fn] -> nsections; sn++)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
168 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
169 if (!strcmp(sname, inputfiles[fn] -> sections[sn].name))
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
170 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
171 // we have a match
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
172 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1));
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
173 sectlist[nsects].ptr = &(inputfiles[fn] -> sections[sn]);
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
174
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
175 inputfiles[fn] -> sections[sn].processed = 1;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
176 if (!f && linkscript.lines[ln].loadat >= 0)
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
177 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
178 f = 1;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
179 sectlist[nsects].forceaddr = 1;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
180 laddr = linkscript.lines[ln].loadat;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
181 }
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
182 else
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
183 {
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
184 sectlist[nsects].forceaddr = 0;
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
185 }
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
186 inputfiles[fn] -> sections[sn].loadaddress = laddr;
131
5276565799bd Fixed load addresses of chained sections and subsections to actually increment
lost
parents: 130
diff changeset
187 laddr += inputfiles[fn] -> sections[sn].codesize;
119
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
188 nsects++;
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
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
198 // theoretically, all the base addresses are set now
8bc00221ae89 section order and address resolution done
lost
parents:
diff changeset
199 }
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
200
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
201 lw_expr_stack_t *find_external_sym_recurse(char *sym, fileinfo_t *fn)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
202 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
203 int sn;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
204 lw_expr_stack_t *r;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
205 lw_expr_term_t *term;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
206 symtab_t *se;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
207 int val;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
208
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
209 for (sn = 0; sn < fn -> nsections; sn++)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
210 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
211 for (se = fn -> sections[sn].exportedsyms; se; se = se -> next)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
212 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
213 if (!strcmp(sym, se -> sym))
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
214 {
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
215 if (!(fn -> forced))
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
216 {
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
217 // we if this isn't a true external reference, don't force inclusion
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
218 // (without an external reference, internal references don't matter)
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
219 if (fn == lookingfrom)
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
220 continue;
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
221 // fprintf(stderr, "Forced inclusion of %s due to symbol reference (%s) from (%s)\n", fn -> filename, sym, lookingfrom ? lookingfrom -> filename : "<none>");
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
222 fn -> forced = 1;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
223 nforced = 1;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
224 }
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
225 fn -> resolves = 1;
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
226 val = se -> offset + fn -> sections[sn].loadaddress;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
227 r = lw_expr_stack_create();
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
228 term = lw_expr_term_create_int(val & 0xffff);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
229 lw_expr_stack_push(r, term);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
230 lw_expr_term_free(term);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
231 return r;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
232 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
233 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
234 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
235
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
236 for (sn = 0; sn < fn -> nsubs; sn++)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
237 {
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
238 r = find_external_sym_recurse(sym, fn -> subs[sn]);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
239 if (r)
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
240 {
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
241 // don't do this when recursing - the sub file will already be set if needed
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
242 // if (!(fn -> forced))
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
243 // {
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
244 // fprintf(stderr, "Forced inclusion of %s due to symbol reference (%s)\n", fn -> filename, sym);
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
245 // nforced = 1;
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
246 // fn -> forced = 1;
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
247 // }
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
248 if (r)
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
249 fn -> resolves = 1;
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
250 return r;
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
251 }
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
252 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
253 return NULL;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
254 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
255
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
256 // resolve all incomplete references now
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
257 // anything that is unresolvable at this stage will throw an error
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
258 // because we know the load address of every section now
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
259 lw_expr_stack_t *resolve_sym(char *sym, int symtype, void *state)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
260 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
261 section_t *sect = state;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
262 lw_expr_term_t *term;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
263 int val = 0, i, fn;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
264 lw_expr_stack_t *s;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
265 symtab_t *se;
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
266 fileinfo_t *fp;
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
267
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
268 if (symtype == 1)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
269 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
270 // local symbol
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
271 if (!sym)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
272 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
273 val = sect -> loadaddress;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
274 goto out;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
275 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
276
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
277 // start with this section
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
278 for (se = sect -> 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 -> 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 // not in this section - check all sections in this file
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
287 for (i = 0; i < sect -> file -> nsections; i++)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
288 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
289 for (se = sect -> file -> sections[i].localsyms; se; se = se -> next)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
290 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
291 if (!strcmp(se -> sym, sym))
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
292 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
293 val = se -> offset + sect -> file -> sections[i].loadaddress;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
294 goto out;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
295 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
296 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
297 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
298 // not found
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
299 symerr = 1;
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
300 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
301 goto outerr;
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
302 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
303 else
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
304 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
305 // external symbol
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
306 // 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
307 if (sect)
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
308 {
173
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
309 for (fp = sect -> file; fp; fp = fp -> parent)
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
310 {
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
311 s = find_external_sym_recurse(sym, fp);
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
312 if (s)
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
313 return s;
0395e6fd67e9 Fixed stupid errors with changes for archive handling
lost
parents: 171
diff changeset
314 }
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
315 }
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
316
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
317 for (fn = 0; fn < ninputfiles; fn++)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
318 {
171
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
319 s = find_external_sym_recurse(sym, inputfiles[fn]);
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
320 if (s)
d610b8aef91b Added LWAR skeleton
lost
parents: 139
diff changeset
321 return s;
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
322 }
130
8349048d67b3 Fixed crash when entry symbol is not exported
lost
parents: 126
diff changeset
323 if (sect)
8349048d67b3 Fixed crash when entry symbol is not exported
lost
parents: 126
diff changeset
324 {
8349048d67b3 Fixed crash when entry symbol is not exported
lost
parents: 126
diff changeset
325 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
326 }
8349048d67b3 Fixed crash when entry symbol is not exported
lost
parents: 126
diff changeset
327 else
8349048d67b3 Fixed crash when entry symbol is not exported
lost
parents: 126
diff changeset
328 {
8349048d67b3 Fixed crash when entry symbol is not exported
lost
parents: 126
diff changeset
329 fprintf(stderr, "External symbol %s not found\n", sym);
8349048d67b3 Fixed crash when entry symbol is not exported
lost
parents: 126
diff changeset
330 }
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
331 symerr = 1;
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
332 goto outerr;
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
333 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
334 fprintf(stderr, "Shouldn't ever get here!!!\n");
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
335 exit(88);
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
336 out:
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
337 s = lw_expr_stack_create();
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
338 term = lw_expr_term_create_int(val & 0xffff);
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
339 lw_expr_stack_push(s, term);
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
340 lw_expr_term_free(term);
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
341 return s;
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
342 outerr:
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
343 return NULL;
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
344 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
345
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
346 void resolve_references(void)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
347 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
348 int sn;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
349 reloc_t *rl;
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
350 int rval;
121
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
351
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
352 // resolve entry point if required
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
353 // 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
354 // first instance of that symbol
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
355 if (linkscript.execsym)
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
356 {
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
357 lw_expr_stack_t *s;
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
358
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
359 lookingfrom = NULL;
121
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
360 s = resolve_sym(linkscript.execsym, 0, NULL);
187
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
361 if (!s)
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
362 {
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
363 fprintf(stderr, "Cannot resolve exec address '%s'\n", linkscript.execsym);
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
364 symerr = 1;
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
365 }
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
366 else
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
367 {
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
368 linkscript.execaddr = lw_expr_get_value(s);
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
369 lw_expr_stack_free(s);
857cb407229e Added LWEX0 (LWOS simple binary) target to lwlink
lost
parents: 184
diff changeset
370 }
121
7bc853cb2ca9 Added simplistic output module for DECB target
lost
parents: 120
diff changeset
371 }
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
372
124
4ac96c697ef0 Corrected errors with parsing script and object files
lost
parents: 121
diff changeset
373 for (sn = 0; sn < nsects; sn++)
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
374 {
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
375 for (rl = sectlist[sn].ptr -> incompletes; rl; rl = rl -> next)
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
376 {
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
377 lookingfrom = sectlist[sn].ptr -> file;
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
378 // do a "simplify" on the expression
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
379 rval = lw_expr_reval(rl -> expr, resolve_sym, sectlist[sn].ptr);
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
380
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
381 // is it constant? error out if not
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
382 if (rval != 0 || !lw_expr_is_constant(rl -> expr))
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
383 {
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
384 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
385 symerr = 1;
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
386 }
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
387 else
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
388 {
243
f9f01a499525 Added zero-width external references
lost
parents: 212
diff changeset
389 // is it a zero-width link?
f9f01a499525 Added zero-width external references
lost
parents: 212
diff changeset
390 if (rl -> flags & RELOC_0BIT)
f9f01a499525 Added zero-width external references
lost
parents: 212
diff changeset
391 continue;
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
392 // 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
393 rval = lw_expr_get_value(rl -> expr);
204
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
394 if (rl -> flags & RELOC_8BIT)
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
395 {
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
396 sectlist[sn].ptr -> code[rl -> offset] = rval & 0xff;
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
397 }
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
398 else
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
399 {
048ebb85f6ef Added 8 bit external references for base page addressing mode
lost
parents: 187
diff changeset
400 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
401 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
402 }
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
403 }
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
404 }
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
405 }
184
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
406
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
407 if (symerr)
220a760ec654 Make lwlink display all undefined references instead of bailing after the first one
lost
parents: 173
diff changeset
408 exit(1);
120
36ce328df3c3 resolve incomplete references done
lost
parents: 119
diff changeset
409 }
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
410
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
411 /*
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
412 This is just a pared down version of the algo for resolving references.
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
413 */
245
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
414 void resolve_files_aux(fileinfo_t *fn)
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
415 {
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
416 int n;
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
417 int sn;
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
418 int rval;
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
419 lw_expr_stack_t *te;
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
420 reloc_t *rl;
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
421
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
422 if (fn -> forced != 0)
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
423 {
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
424 lookingfrom = fn;
245
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
425 for (sn = 0; sn < fn -> nsections; sn++)
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
426 {
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
427 for (rl = fn -> sections[sn].incompletes; rl; rl = rl -> next)
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
428 {
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
429 // do a "simplify" on the expression
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
430 te = lw_expr_stack_dup(rl -> expr);
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
431 rval = lw_expr_reval(te, resolve_sym, &(fn -> sections[sn]));
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
432
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
433 // is it constant? error out if not
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
434 if (rval != 0 || !lw_expr_is_constant(te))
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
435 {
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
436 fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", fn -> filename, fn -> sections[sn].name, rl -> offset);
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
437 symerr = 1;
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
438 }
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
439 lw_expr_stack_free(te);
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
440 }
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
441 }
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
442 }
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
443 // handle sub files
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
444 for (n = 0; n < fn -> nsubs; n++)
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
445 resolve_files_aux(fn -> subs[n]);
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
446 }
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
447
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
448 void resolve_files(void)
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
449 {
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
450 int sn;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
451 int fn;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
452 reloc_t *rl;
206
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
453 lw_expr_stack_t *te;
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
454 // int c = 0;
206
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
455
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
456 int rval;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
457
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
458 // resolve entry point if required
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
459 // this must resolve to an *exported* symbol and will resolve to the
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
460 // first instance of that symbol
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
461 if (linkscript.execsym)
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
462 {
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
463 lw_expr_stack_t *s;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
464
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
465 lookingfrom = NULL;
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
466 s = resolve_sym(linkscript.execsym, 0, NULL);
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
467 if (!s)
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
468 {
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
469 fprintf(stderr, "Cannot resolve exec address '%s'\n", linkscript.execsym);
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
470 symerr = 1;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
471 }
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
472 }
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
473
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
474 do
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
475 {
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
476 nforced = 0;
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
477 for (fn = 0; fn < ninputfiles; fn++)
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
478 {
245
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
479 resolve_files_aux(inputfiles[fn]);
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
480 }
245
eb499c146c0d Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
lost
parents: 243
diff changeset
481 // fprintf(stderr, "File resolution pass %d, nforced = %d\n", ++c, nforced);
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
482 }
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
483 while (nforced == 1);
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
484
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
485 if (symerr)
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
486 exit(1);
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
487
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
488 // 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
489 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
490 {
248
e8d70b95ec41 Fixed various problems with determining which files to include in the output and also fixed problem identifying which files actually resolved symbols
lost
parents: 245
diff changeset
491 if (inputfiles[fn] -> forced == 1 || inputfiles[fn] -> resolves == 1)
206
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
492 continue;
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
493
299c5d793aca Made lwlink smarter about not included unneeded (unreferenced) members of a library file
lost
parents: 205
diff changeset
494 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
495 }
205
42df94f30d82 checkpoint
lost
parents: 204
diff changeset
496 }