comparison lwlink/link.c @ 235:e3741cf53e00

Fix error messages related to undefined symbols in lwlink Make lwlink not complain about seciton base and length symbols. Also silence duplicate complaints about undefined symbols. There is no need to complain about undefined symbols during the file/section resolution stage! If they are truly undefined, they'll still be undefined at the reference resolution stage.
author William Astle <lost@l-w.ca>
date Sat, 11 Aug 2012 15:18:58 -0600
parents d389adbcc4ab
children ce1fdc8d6568
comparison
equal deleted inserted replaced
234:d389adbcc4ab 235:e3741cf53e00
35 35
36 struct section_list *sectlist = NULL; 36 struct section_list *sectlist = NULL;
37 int nsects = 0; 37 int nsects = 0;
38 static int nforced = 0; 38 static int nforced = 0;
39 static int resolveonly = 0; 39 static int resolveonly = 0;
40
41 int quietsym = 1;
40 42
41 symlist_t *symlist = NULL; 43 symlist_t *symlist = NULL;
42 44
43 void check_section_name(char *name, int *base, fileinfo_t *fn) 45 void check_section_name(char *name, int *base, fileinfo_t *fn)
44 { 46 {
224 int sn; 226 int sn;
225 char *lastsect = NULL; 227 char *lastsect = NULL;
226 char sym[256]; 228 char sym[256];
227 int len; 229 int len;
228 symlist_t *se; 230 symlist_t *se;
229 fprintf(stderr, "Generating symbols\n");
230 for (sn = 0; sn < nsects; sn++) 231 for (sn = 0; sn < nsects; sn++)
231 { 232 {
232 fprintf(stderr, "Section %s (%s)\n", sectlist[sn].ptr -> name, lastsect);
233 if (!lastsect || strcmp(lastsect, (char *)(sectlist[sn].ptr -> name))) 233 if (!lastsect || strcmp(lastsect, (char *)(sectlist[sn].ptr -> name)))
234 { 234 {
235 if (lastsect && linkscript.lensympat) 235 if (lastsect && linkscript.lensympat)
236 { 236 {
237 /* handle length symbol */ 237 /* handle length symbol */
397 goto out; 397 goto out;
398 } 398 }
399 } 399 }
400 } 400 }
401 // not found 401 // not found
402 symerr = 1; 402 if (!quietsym)
403 fprintf(stderr, "Local symbol %s not found in %s:%s\n", sanitize_symbol(sym), sect -> file -> filename, sect -> name); 403 {
404 symerr = 1;
405 fprintf(stderr, "Local symbol %s not found in %s:%s\n", sanitize_symbol(sym), sect -> file -> filename, sect -> name);
406 }
404 goto outerr; 407 goto outerr;
405 } 408 }
406 else 409 else
407 { 410 {
408 symlist_t *se; 411 symlist_t *se;
435 // fprintf(stderr, "Looking in %s\n", inputfiles[fn] -> filename); 438 // fprintf(stderr, "Looking in %s\n", inputfiles[fn] -> filename);
436 s = find_external_sym_recurse(sym, inputfiles[fn]); 439 s = find_external_sym_recurse(sym, inputfiles[fn]);
437 if (s) 440 if (s)
438 return s; 441 return s;
439 } 442 }
440 if (sect) 443 if (!quietsym)
441 { 444 {
442 fprintf(stderr, "External symbol %s not found in %s:%s\n", sanitize_symbol(sym), sect -> file -> filename, sect -> name); 445 if (sect)
443 } 446 {
444 else 447 fprintf(stderr, "External symbol %s not found in %s:%s\n", sanitize_symbol(sym), sect -> file -> filename, sect -> name);
445 { 448 }
446 fprintf(stderr, "External symbol %s not found\n", sym); 449 else
447 } 450 {
448 symerr = 1; 451 fprintf(stderr, "External symbol %s not found\n", sym);
452 }
453 symerr = 1;
454 }
449 goto outerr; 455 goto outerr;
450 } 456 }
451 fprintf(stderr, "Shouldn't ever get here!!!\n"); 457 fprintf(stderr, "Shouldn't ever get here!!!\n");
452 exit(88); 458 exit(88);
453 out: 459 out:
464 { 470 {
465 int sn; 471 int sn;
466 reloc_t *rl; 472 reloc_t *rl;
467 int rval; 473 int rval;
468 474
475 quietsym = 0;
476
469 // resolve entry point if required 477 // resolve entry point if required
470 // this must resolve to an *exported* symbol and will resolve to the 478 // this must resolve to an *exported* symbol and will resolve to the
471 // first instance of that symbol 479 // first instance of that symbol
472 if (linkscript.execsym) 480 if (linkscript.execsym)
473 { 481 {
474 lw_expr_stack_t *s; 482 lw_expr_stack_t *s;
475 483
476 s = resolve_sym(linkscript.execsym, 0, NULL); 484 s = resolve_sym(linkscript.execsym, 0, NULL);
477 if (!s) 485 if (!s)
478 { 486 {
479 fprintf(stderr, "Cannot resolve exec address '%s'\n", linkscript.execsym); 487 fprintf(stderr, "Cannot resolve exec address '%s'\n", linkscript.execsym);
480 symerr = 1; 488 symerr = 1;
481 } 489 }
482 else 490 else
483 { 491 {
484 linkscript.execaddr = lw_expr_get_value(s); 492 linkscript.execaddr = lw_expr_get_value(s);
485 lw_expr_stack_free(s); 493 lw_expr_stack_free(s);
494 rval = lw_expr_reval(rl -> expr, resolve_sym, sectlist[sn].ptr); 502 rval = lw_expr_reval(rl -> expr, resolve_sym, sectlist[sn].ptr);
495 503
496 // is it constant? error out if not 504 // is it constant? error out if not
497 if (rval != 0 || !lw_expr_is_constant(rl -> expr)) 505 if (rval != 0 || !lw_expr_is_constant(rl -> expr))
498 { 506 {
499 fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", sectlist[sn].ptr -> file -> filename, sectlist[sn].ptr -> name, rl -> offset); 507 fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", sectlist[sn].ptr -> file -> filename, sectlist[sn].ptr -> name, rl -> offset);
500 symerr = 1; 508 symerr = 1;
501 } 509 }
502 else 510 else
503 { 511 {
504 // put the value into the relocation address 512 // put the value into the relocation address
505 rval = lw_expr_get_value(rl -> expr); 513 rval = lw_expr_get_value(rl -> expr);
542 // do a "simplify" on the expression 550 // do a "simplify" on the expression
543 te = lw_expr_stack_dup(rl -> expr); 551 te = lw_expr_stack_dup(rl -> expr);
544 rval = lw_expr_reval(te, resolve_sym, &(fn -> sections[sn])); 552 rval = lw_expr_reval(te, resolve_sym, &(fn -> sections[sn]));
545 553
546 // is it constant? error out if not 554 // is it constant? error out if not
547 if (rval != 0 || !lw_expr_is_constant(te)) 555 // incompletes will error out during resolve_references()
548 { 556 //if (rval != 0 || !lw_expr_is_constant(te))
549 fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", fn -> filename, fn -> sections[sn].name, rl -> offset); 557 //{
550 symerr = 1; 558 // fprintf(stderr, "Incomplete reference at %s:%s+%02X\n", fn -> filename, fn -> sections[sn].name, rl -> offset);
551 } 559 // symerr = 1;
560 //}
552 lw_expr_stack_free(te); 561 lw_expr_stack_free(te);
553 } 562 }
554 } 563 }
555 564
556 // handle any sub files 565 // handle any sub files