comparison lwlink/link.c @ 156:fc8386b13399

Added 'constant' sections to object file handling for lwasm and lwlink
author lost@l-w.ca
date Sun, 28 Aug 2011 02:06:42 -0600
parents 1571e150f1fd
children 4682460aed00
comparison
equal deleted inserted replaced
155:1571e150f1fd 156:fc8386b13399
43 if (fn -> forced == 0) 43 if (fn -> forced == 0)
44 return; 44 return;
45 45
46 for (sn = 0; sn < fn -> nsections; sn++) 46 for (sn = 0; sn < fn -> nsections; sn++)
47 { 47 {
48 if (!strcmp(name, (char *)(fn -> sections[sn].name))) 48 if (!strcmp(name, (char *)(fn -> sections[sn].name)) && (fn -> sections[sn].flags | SECTION_CONST) == 0)
49 { 49 {
50 // we have a match 50 // we have a match
51 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1)); 51 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1));
52 sectlist[nsects].ptr = &(fn -> sections[sn]); 52 sectlist[nsects].ptr = &(fn -> sections[sn]);
53 53
71 if (fn -> forced == 0) 71 if (fn -> forced == 0)
72 return; 72 return;
73 73
74 for (sn = 0; sn < fn -> nsections; sn++) 74 for (sn = 0; sn < fn -> nsections; sn++)
75 { 75 {
76 // ignore "constant" sections
77 if (fn -> sections[sn].flags & SECTION_CONST)
78 continue;
76 // ignore if the noflags tell us to 79 // ignore if the noflags tell us to
77 if (noflags && (fn -> sections[sn].flags & noflags)) 80 if (noflags && (fn -> sections[sn].flags & noflags))
78 continue; 81 continue;
79 // ignore unless the yesflags tell us not to 82 // ignore unless the yesflags tell us not to
80 if (yesflags && ((fn -> sections[sn].flags & yesflags) == 0)) 83 if (yesflags && ((fn -> sections[sn].flags & yesflags) == 0))
152 // and resolve base addresses and add to the list 155 // and resolve base addresses and add to the list
153 for (fn0 = 0; fn0 < ninputfiles; fn0++) 156 for (fn0 = 0; fn0 < ninputfiles; fn0++)
154 { 157 {
155 for (sn0 = 0; sn0 < inputfiles[fn0] -> nsections; sn0++) 158 for (sn0 = 0; sn0 < inputfiles[fn0] -> nsections; sn0++)
156 { 159 {
160 // ignore "constant" sections
161 if (inputfiles[fn0] -> sections[sn0].flags & SECTION_CONST)
162 continue;
157 // ignore if the "no flags" bit says to 163 // ignore if the "no flags" bit says to
158 if (linkscript.lines[ln].noflags && (inputfiles[fn0] -> sections[sn0].flags & linkscript.lines[ln].noflags)) 164 if (linkscript.lines[ln].noflags && (inputfiles[fn0] -> sections[sn0].flags & linkscript.lines[ln].noflags))
159 continue; 165 continue;
160 // ignore unless the yes flags tell us not to 166 // ignore unless the yes flags tell us not to
161 if (linkscript.lines[ln].yesflags && ((inputfiles[fn0] -> sections[sn0].flags & linkscript.lines[ln].yesflags) == 0)) 167 if (linkscript.lines[ln].yesflags && ((inputfiles[fn0] -> sections[sn0].flags & linkscript.lines[ln].yesflags) == 0))
211 { 217 {
212 for (se = fn -> sections[sn].exportedsyms; se; se = se -> next) 218 for (se = fn -> sections[sn].exportedsyms; se; se = se -> next)
213 { 219 {
214 if (!strcmp(sym, (char *)(se -> sym))) 220 if (!strcmp(sym, (char *)(se -> sym)))
215 { 221 {
222 // if the section was not previously processed and is CONSTANT, force it in
223 // otherwise error out if it is not being processed
224 if (fn -> sections[sn].processed == 0)
225 {
226 if (fn -> sections[sn].flags & SECTION_CONST)
227 {
228 // add to section list
229 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1));
230 sectlist[nsects].ptr = &(fn -> sections[sn]);
231 fn -> sections[sn].processed = 1;
232 fn -> sections[sn].loadaddress = 0;
233 nsects++;
234 }
235 else
236 {
237 // if we're in a non-processed section, bail!
238 continue;
239 }
240 }
216 // fprintf(stderr, "Found symbol %s in %s\n", sym, fn -> filename); 241 // fprintf(stderr, "Found symbol %s in %s\n", sym, fn -> filename);
217 if (!(fn -> forced)) 242 if (!(fn -> forced))
218 { 243 {
219 // fprintf(stderr, " Forced\n"); 244 // fprintf(stderr, " Forced\n");
220 fn -> forced = 1; 245 fn -> forced = 1;
221 nforced = 1; 246 nforced = 1;
222 } 247 }
223 val = se -> offset + fn -> sections[sn].loadaddress; 248 if (fn -> sections[sn].flags & SECTION_CONST)
249 val = se -> offset;
250 else
251 val = se -> offset + fn -> sections[sn].loadaddress;
224 r = lw_expr_stack_create(); 252 r = lw_expr_stack_create();
225 term = lw_expr_term_create_int(val & 0xffff); 253 term = lw_expr_term_create_int(val & 0xffff);
226 lw_expr_stack_push(r, term); 254 lw_expr_stack_push(r, term);
227 lw_expr_term_free(term); 255 lw_expr_term_free(term);
256
228 return r; 257 return r;
229 } 258 }
230 } 259 }
231 } 260 }
232 261
274 // start with this section 303 // start with this section
275 for (se = sect -> localsyms; se; se = se -> next) 304 for (se = sect -> localsyms; se; se = se -> next)
276 { 305 {
277 if (!strcmp((char *)(se -> sym), sym)) 306 if (!strcmp((char *)(se -> sym), sym))
278 { 307 {
279 val = se -> offset + sect -> loadaddress; 308 if (sect -> flags & SECTION_CONST)
309 val = se -> offset;
310 else
311 val = se -> offset + sect -> loadaddress;
280 goto out; 312 goto out;
281 } 313 }
282 } 314 }
283 // not in this section - check all sections in this file 315 // not in this section - check all sections in this file
284 for (i = 0; i < sect -> file -> nsections; i++) 316 for (i = 0; i < sect -> file -> nsections; i++)
285 { 317 {
286 for (se = sect -> file -> sections[i].localsyms; se; se = se -> next) 318 for (se = sect -> file -> sections[i].localsyms; se; se = se -> next)
287 { 319 {
288 if (!strcmp((char *)(se -> sym), sym)) 320 if (!strcmp((char *)(se -> sym), sym))
289 { 321 {
290 val = se -> offset + sect -> file -> sections[i].loadaddress; 322 if (sect -> file -> sections[i].flags & SECTION_CONST)
323 val = se -> offset;
324 else
325 val = se -> offset + sect -> file -> sections[i].loadaddress;
291 goto out; 326 goto out;
292 } 327 }
293 } 328 }
294 } 329 }
295 // not found 330 // not found