comparison lwlink/link.c @ 245:eb499c146c0d 2.x

Fixed selection of objects for inclusion from within libraries to actually resolve references correctly
author lost
date Thu, 19 Nov 2009 00:51:31 +0000
parents f9f01a499525
children e8d70b95ec41
comparison
equal deleted inserted replaced
244:c8bcc396ec59 245:eb499c146c0d
211 { 211 {
212 if (!strcmp(sym, se -> sym)) 212 if (!strcmp(sym, se -> sym))
213 { 213 {
214 if (!(fn -> forced)) 214 if (!(fn -> forced))
215 { 215 {
216 // fprintf(stderr, "Forced inclusion of %s due to symbol reference\n", fn -> filename);
216 fn -> forced = 1; 217 fn -> forced = 1;
217 nforced = 1; 218 nforced = 1;
218 } 219 }
219 val = se -> offset + fn -> sections[sn].loadaddress; 220 val = se -> offset + fn -> sections[sn].loadaddress;
220 r = lw_expr_stack_create(); 221 r = lw_expr_stack_create();
396 } 397 }
397 398
398 /* 399 /*
399 This is just a pared down version of the algo for resolving references. 400 This is just a pared down version of the algo for resolving references.
400 */ 401 */
402 void resolve_files_aux(fileinfo_t *fn)
403 {
404 int n;
405 int sn;
406 int rval;
407 lw_expr_stack_t *te;
408 reloc_t *rl;
409
410 if (fn -> forced != 0)
411 {
412 for (sn = 0; sn < fn -> nsections; sn++)
413 {
414 for (rl = fn -> sections[sn].incompletes; rl; rl = rl -> next)
415 {
416 // do a "simplify" on the expression
417 te = lw_expr_stack_dup(rl -> expr);
418 rval = lw_expr_reval(te, resolve_sym, &(fn -> sections[sn]));
419
420 // is it constant? error out if not
421 if (rval != 0 || !lw_expr_is_constant(te))
422 {
423 fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", fn -> filename, fn -> sections[sn].name, rl -> offset);
424 symerr = 1;
425 }
426 lw_expr_stack_free(te);
427 }
428 }
429 }
430 // handle sub files
431 for (n = 0; n < fn -> nsubs; n++)
432 resolve_files_aux(fn -> subs[n]);
433 }
434
401 void resolve_files(void) 435 void resolve_files(void)
402 { 436 {
403 int sn; 437 int sn;
404 int fn; 438 int fn;
405 reloc_t *rl; 439 reloc_t *rl;
406 lw_expr_stack_t *te; 440 lw_expr_stack_t *te;
441 int c = 0;
407 442
408 int rval; 443 int rval;
409 444
410 // resolve entry point if required 445 // resolve entry point if required
411 // this must resolve to an *exported* symbol and will resolve to the 446 // this must resolve to an *exported* symbol and will resolve to the
428 for (fn = 0; fn < ninputfiles; fn++) 463 for (fn = 0; fn < ninputfiles; fn++)
429 { 464 {
430 if (inputfiles[fn] -> forced == 0) 465 if (inputfiles[fn] -> forced == 0)
431 continue; 466 continue;
432 467
433 for (sn = 0; sn < inputfiles[fn] -> nsections; sn++) 468 resolve_files_aux(inputfiles[fn]);
434 { 469 }
435 for (rl = inputfiles[fn] -> sections[sn].incompletes; rl; rl = rl -> next) 470 // fprintf(stderr, "File resolution pass %d, nforced = %d\n", ++c, nforced);
436 {
437 // do a "simplify" on the expression
438 te = lw_expr_stack_dup(rl -> expr);
439 rval = lw_expr_reval(te, resolve_sym, &(inputfiles[fn] -> sections[sn]));
440
441 // is it constant? error out if not
442 if (rval != 0 || !lw_expr_is_constant(te))
443 {
444 fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", inputfiles[fn] -> filename, inputfiles[fn] -> sections[sn].name, rl -> offset);
445 symerr = 1;
446 }
447 lw_expr_stack_free(te);
448 }
449 }
450 }
451 } 471 }
452 while (nforced == 1); 472 while (nforced == 1);
453 473
454 if (symerr) 474 if (symerr)
455 exit(1); 475 exit(1);