Mercurial > hg > index.cgi
comparison lwlink/link.c @ 155:1571e150f1fd
Fixed error where external references within a library file were not resolved when linking
author | lost@l-w.ca |
---|---|
date | Sun, 28 Aug 2011 00:07:15 -0600 |
parents | 729a9c70934e |
children | fc8386b13399 |
comparison
equal
deleted
inserted
replaced
154:5ac1c4cd81a7 | 155:1571e150f1fd |
---|---|
211 { | 211 { |
212 for (se = fn -> sections[sn].exportedsyms; se; se = se -> next) | 212 for (se = fn -> sections[sn].exportedsyms; se; se = se -> next) |
213 { | 213 { |
214 if (!strcmp(sym, (char *)(se -> sym))) | 214 if (!strcmp(sym, (char *)(se -> sym))) |
215 { | 215 { |
216 // fprintf(stderr, "Found symbol %s in %s\n", sym, fn -> filename); | |
216 if (!(fn -> forced)) | 217 if (!(fn -> forced)) |
217 { | 218 { |
219 // fprintf(stderr, " Forced\n"); | |
218 fn -> forced = 1; | 220 fn -> forced = 1; |
219 nforced = 1; | 221 nforced = 1; |
220 } | 222 } |
221 val = se -> offset + fn -> sections[sn].loadaddress; | 223 val = se -> offset + fn -> sections[sn].loadaddress; |
222 r = lw_expr_stack_create(); | 224 r = lw_expr_stack_create(); |
231 for (sn = 0; sn < fn -> nsubs; sn++) | 233 for (sn = 0; sn < fn -> nsubs; sn++) |
232 { | 234 { |
233 r = find_external_sym_recurse(sym, fn -> subs[sn]); | 235 r = find_external_sym_recurse(sym, fn -> subs[sn]); |
234 if (r) | 236 if (r) |
235 { | 237 { |
238 // fprintf(stderr, "Found symbol %s in %s\n", sym, fn -> filename); | |
236 if (!(fn -> forced)) | 239 if (!(fn -> forced)) |
237 { | 240 { |
241 // fprintf(stderr, " Forced\n"); | |
238 nforced = 1; | 242 nforced = 1; |
239 fn -> forced = 1; | 243 fn -> forced = 1; |
240 } | 244 } |
241 return r; | 245 return r; |
242 } | 246 } |
253 lw_expr_term_t *term; | 257 lw_expr_term_t *term; |
254 int val = 0, i, fn; | 258 int val = 0, i, fn; |
255 lw_expr_stack_t *s; | 259 lw_expr_stack_t *s; |
256 symtab_t *se; | 260 symtab_t *se; |
257 fileinfo_t *fp; | 261 fileinfo_t *fp; |
262 | |
263 // fprintf(stderr, "Looking up %s\n", sym); | |
258 | 264 |
259 if (symtype == 1) | 265 if (symtype == 1) |
260 { | 266 { |
261 // local symbol | 267 // local symbol |
262 if (!sym) | 268 if (!sym) |
395 | 401 |
396 if (outformat == OUTPUT_OS9) | 402 if (outformat == OUTPUT_OS9) |
397 check_os9(); | 403 check_os9(); |
398 } | 404 } |
399 | 405 |
406 void resolve_files_aux(fileinfo_t *fn) | |
407 { | |
408 int sn; | |
409 reloc_t *rl; | |
410 lw_expr_stack_t *te; | |
411 | |
412 int rval; | |
413 | |
414 | |
415 if (fn -> forced == 0) | |
416 return; | |
417 | |
418 for (sn = 0; sn < fn -> nsections; sn++) | |
419 { | |
420 for (rl = fn -> sections[sn].incompletes; rl; rl = rl -> next) | |
421 { | |
422 // do a "simplify" on the expression | |
423 te = lw_expr_stack_dup(rl -> expr); | |
424 rval = lw_expr_reval(te, resolve_sym, &(fn -> sections[sn])); | |
425 | |
426 // is it constant? error out if not | |
427 if (rval != 0 || !lw_expr_is_constant(te)) | |
428 { | |
429 fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", fn -> filename, fn -> sections[sn].name, rl -> offset); | |
430 symerr = 1; | |
431 } | |
432 lw_expr_stack_free(te); | |
433 } | |
434 } | |
435 | |
436 // handle any sub files | |
437 for (sn = 0; sn < fn -> nsubs; sn++) | |
438 resolve_files_aux(fn -> subs[sn]); | |
439 } | |
440 | |
400 /* | 441 /* |
401 This is just a pared down version of the algo for resolving references. | 442 This is just a pared down version of the algo for resolving references. |
402 */ | 443 */ |
403 void resolve_files(void) | 444 void resolve_files(void) |
404 { | 445 { |
405 int sn; | |
406 int fn; | 446 int fn; |
407 reloc_t *rl; | |
408 lw_expr_stack_t *te; | |
409 | |
410 int rval; | |
411 | 447 |
412 // resolve entry point if required | 448 // resolve entry point if required |
413 // this must resolve to an *exported* symbol and will resolve to the | 449 // this must resolve to an *exported* symbol and will resolve to the |
414 // first instance of that symbol | 450 // first instance of that symbol |
415 if (linkscript.execsym) | 451 if (linkscript.execsym) |
427 do | 463 do |
428 { | 464 { |
429 nforced = 0; | 465 nforced = 0; |
430 for (fn = 0; fn < ninputfiles; fn++) | 466 for (fn = 0; fn < ninputfiles; fn++) |
431 { | 467 { |
432 if (inputfiles[fn] -> forced == 0) | 468 resolve_files_aux(inputfiles[fn]); |
433 continue; | |
434 | |
435 for (sn = 0; sn < inputfiles[fn] -> nsections; sn++) | |
436 { | |
437 for (rl = inputfiles[fn] -> sections[sn].incompletes; rl; rl = rl -> next) | |
438 { | |
439 // do a "simplify" on the expression | |
440 te = lw_expr_stack_dup(rl -> expr); | |
441 rval = lw_expr_reval(te, resolve_sym, &(inputfiles[fn] -> sections[sn])); | |
442 | |
443 // is it constant? error out if not | |
444 if (rval != 0 || !lw_expr_is_constant(te)) | |
445 { | |
446 fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", inputfiles[fn] -> filename, inputfiles[fn] -> sections[sn].name, rl -> offset); | |
447 symerr = 1; | |
448 } | |
449 lw_expr_stack_free(te); | |
450 } | |
451 } | |
452 } | 469 } |
453 } | 470 } |
454 while (nforced == 1); | 471 while (nforced == 1); |
455 | 472 |
456 if (symerr) | 473 if (symerr) |