1 /* Main program of GNU linker. 2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 3 2002, 2003, 2004, 2005, 2006 4 Free Software Foundation, Inc. 5 Written by Steve Chamberlain steve@cygnus.com 6 7 This file is part of GLD, the Gnu Linker. 8 9 GLD is free software; you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 2, or (at your option) 12 any later version. 13 14 GLD is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with GLD; see the file COPYING. If not, write to the Free 21 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 22 02110-1301, USA. */ 23 24 #include "bfd.h" 25 #include "sysdep.h" 26 #include <stdio.h> 27 #include "safe-ctype.h" 28 #include "libiberty.h" 29 #include "progress.h" 30 #include "bfdlink.h" 31 #include "filenames.h" 32 33 #include "ld.h" 34 #include "ldmain.h" 35 #include "ldmisc.h" 36 #include "ldwrite.h" 37 #include "ldexp.h" 38 #include "ldlang.h" 39 #include <ldgram.h> 40 #include "ldlex.h" 41 #include "ldfile.h" 42 #include "ldemul.h" 43 #include "ldctor.h" 44 45 /* Somewhere above, sys/stat.h got included. */ 46 #if !defined(S_ISDIR) && defined(S_IFDIR) 47 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 48 #endif 49 50 #include <string.h> 51 52 #ifdef HAVE_SBRK 53 #if !HAVE_DECL_SBRK 54 extern void *sbrk (); 55 #endif 56 #endif 57 58 #ifndef TARGET_SYSTEM_ROOT 59 #define TARGET_SYSTEM_ROOT "" 60 #endif 61 62 /* EXPORTS */ 63 64 char *default_target; 65 const char *output_filename = "a.out"; 66 67 /* Name this program was invoked by. */ 68 char *program_name; 69 70 /* The prefix for system library directories. */ 71 const char *ld_sysroot; 72 73 /* The canonical representation of ld_sysroot. */ 74 char * ld_canon_sysroot; 75 int ld_canon_sysroot_len; 76 77 /* The file that we're creating. */ 78 bfd *output_bfd = 0; 79 80 /* Set by -G argument, for MIPS ECOFF target. */ 81 int g_switch_value = 8; 82 83 /* Nonzero means print names of input files as processed. */ 84 bfd_boolean trace_files; 85 86 /* Nonzero means same, but note open failures, too. */ 87 bfd_boolean trace_file_tries; 88 89 /* Nonzero means version number was printed, so exit successfully 90 instead of complaining if no input files are given. */ 91 bfd_boolean version_printed; 92 93 /* Nonzero means link in every member of an archive. */ 94 bfd_boolean whole_archive; 95 96 /* Nonzero means create DT_NEEDED entries only if a dynamic library 97 actually satisfies some reference in a regular object. */ 98 bfd_boolean as_needed; 99 100 /* Nonzero means never create DT_NEEDED entries for dynamic libraries 101 in DT_NEEDED tags. */ 102 bfd_boolean add_needed = TRUE; 103 104 /* TRUE if we should demangle symbol names. */ 105 bfd_boolean demangling; 106 107 args_type command_line; 108 109 ld_config_type config; 110 111 sort_type sort_section; 112 113 static const char *get_sysroot 114 (int, char **); 115 static char *get_emulation 116 (int, char **); 117 static void set_scripts_dir 118 (void); 119 static bfd_boolean add_archive_element 120 (struct bfd_link_info *, bfd *, const char *); 121 static bfd_boolean multiple_definition 122 (struct bfd_link_info *, const char *, bfd *, asection *, bfd_vma, 123 bfd *, asection *, bfd_vma); 124 static bfd_boolean multiple_common 125 (struct bfd_link_info *, const char *, bfd *, enum bfd_link_hash_type, 126 bfd_vma, bfd *, enum bfd_link_hash_type, bfd_vma); 127 static bfd_boolean add_to_set 128 (struct bfd_link_info *, struct bfd_link_hash_entry *, 129 bfd_reloc_code_real_type, bfd *, asection *, bfd_vma); 130 static bfd_boolean constructor_callback 131 (struct bfd_link_info *, bfd_boolean, const char *, bfd *, 132 asection *, bfd_vma); 133 static bfd_boolean warning_callback 134 (struct bfd_link_info *, const char *, const char *, bfd *, 135 asection *, bfd_vma); 136 static void warning_find_reloc 137 (bfd *, asection *, void *); 138 static bfd_boolean undefined_symbol 139 (struct bfd_link_info *, const char *, bfd *, asection *, bfd_vma, 140 bfd_boolean); 141 static bfd_boolean reloc_overflow 142 (struct bfd_link_info *, struct bfd_link_hash_entry *, const char *, 143 const char *, bfd_vma, bfd *, asection *, bfd_vma); 144 static bfd_boolean reloc_dangerous 145 (struct bfd_link_info *, const char *, bfd *, asection *, bfd_vma); 146 static bfd_boolean unattached_reloc 147 (struct bfd_link_info *, const char *, bfd *, asection *, bfd_vma); 148 static bfd_boolean notice 149 (struct bfd_link_info *, const char *, bfd *, asection *, bfd_vma); 150 151 static struct bfd_link_callbacks link_callbacks = 152 { 153 add_archive_element, 154 multiple_definition, 155 multiple_common, 156 add_to_set, 157 constructor_callback, 158 warning_callback, 159 undefined_symbol, 160 reloc_overflow, 161 reloc_dangerous, 162 unattached_reloc, 163 notice, 164 einfo 165 }; 166 167 struct bfd_link_info link_info; 168 169 static void 170 remove_output (void) 171 { 172 if (output_filename) 173 { 174 if (output_bfd) 175 bfd_cache_close (output_bfd); 176 if (delete_output_file_on_failure) 177 unlink_if_ordinary (output_filename); 178 } 179 } 180 181 int 182 main (int argc, char **argv) 183 { 184 char *emulation; 185 long start_time = get_run_time (); 186 187 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) 188 setlocale (LC_MESSAGES, ""); 189 #endif 190 #if defined (HAVE_SETLOCALE) 191 setlocale (LC_CTYPE, ""); 192 #endif 193 bindtextdomain (PACKAGE, LOCALEDIR); 194 textdomain (PACKAGE); 195 196 program_name = argv[0]; 197 xmalloc_set_program_name (program_name); 198 199 START_PROGRESS (program_name, 0); 200 201 expandargv (&argc, &argv); 202 203 bfd_init (); 204 205 bfd_set_error_program_name (program_name); 206 207 xatexit (remove_output); 208 209 /* Set up the sysroot directory. */ 210 ld_sysroot = get_sysroot (argc, argv); 211 if (*ld_sysroot) 212 { 213 if (*TARGET_SYSTEM_ROOT == 0) 214 { 215 einfo ("%P%F: this linker was not configured to use sysroots\n"); 216 ld_sysroot = ""; 217 } 218 else 219 ld_canon_sysroot = lrealpath (ld_sysroot); 220 } 221 if (ld_canon_sysroot) 222 ld_canon_sysroot_len = strlen (ld_canon_sysroot); 223 else 224 ld_canon_sysroot_len = -1; 225 226 /* Set the default BFD target based on the configured target. Doing 227 this permits the linker to be configured for a particular target, 228 and linked against a shared BFD library which was configured for 229 a different target. The macro TARGET is defined by Makefile. */ 230 if (! bfd_set_default_target (TARGET)) 231 { 232 einfo (_("%X%P: can't set BFD default target to `%s': %E\n"), TARGET); 233 xexit (1); 234 } 235 236 #if YYDEBUG 237 { 238 extern int yydebug; 239 yydebug = 1; 240 } 241 #endif 242 243 /* Initialize the data about options. */ 244 trace_files = trace_file_tries = version_printed = FALSE; 245 whole_archive = FALSE; 246 config.build_constructors = TRUE; 247 config.dynamic_link = FALSE; 248 config.has_shared = FALSE; 249 config.split_by_reloc = (unsigned) -1; 250 config.split_by_file = (bfd_size_type) -1; 251 config.hash_table_size = 0; 252 command_line.force_common_definition = FALSE; 253 command_line.inhibit_common_definition = FALSE; 254 command_line.interpreter = NULL; 255 command_line.rpath = NULL; 256 command_line.warn_mismatch = TRUE; 257 command_line.check_section_addresses = TRUE; 258 command_line.accept_unknown_input_arch = FALSE; 259 command_line.reduce_memory_overheads = FALSE; 260 261 sort_section = none; 262 263 /* We initialize DEMANGLING based on the environment variable 264 COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the 265 output of the linker, unless COLLECT_NO_DEMANGLE is set in the 266 environment. Acting the same way here lets us provide the same 267 interface by default. */ 268 demangling = getenv ("COLLECT_NO_DEMANGLE") == NULL; 269 270 link_info.relocatable = FALSE; 271 link_info.emitrelocations = FALSE; 272 link_info.task_link = FALSE; 273 link_info.shared = FALSE; 274 #ifdef PIE_DEFAULT 275 link_info.pie = TRUE; 276 #else 277 link_info.pie = FALSE; 278 #endif 279 link_info.executable = FALSE; 280 link_info.symbolic = FALSE; 281 link_info.export_dynamic = FALSE; 282 link_info.static_link = FALSE; 283 link_info.traditional_format = FALSE; 284 link_info.optimize = FALSE; 285 link_info.unresolved_syms_in_objects = RM_NOT_YET_SET; 286 link_info.unresolved_syms_in_shared_libs = RM_NOT_YET_SET; 287 link_info.allow_multiple_definition = FALSE; 288 link_info.allow_undefined_version = TRUE; 289 link_info.create_default_symver = FALSE; 290 link_info.default_imported_symver = FALSE; 291 link_info.keep_memory = TRUE; 292 link_info.notice_all = FALSE; 293 link_info.nocopyreloc = FALSE; 294 link_info.new_dtags = FALSE; 295 link_info.combreloc = TRUE; 296 link_info.eh_frame_hdr = FALSE; 297 link_info.relro = FALSE; 298 link_info.strip_discarded = TRUE; 299 link_info.strip = strip_none; 300 link_info.discard = discard_sec_merge; 301 link_info.common_skip_ar_aymbols = bfd_link_common_skip_none; 302 link_info.callbacks = &link_callbacks; 303 link_info.hash = NULL; 304 link_info.keep_hash = NULL; 305 link_info.notice_hash = NULL; 306 link_info.wrap_hash = NULL; 307 link_info.input_bfds = NULL; 308 link_info.create_object_symbols_section = NULL; 309 link_info.gc_sym_list = NULL; 310 link_info.base_file = NULL; 311 /* SVR4 linkers seem to set DT_INIT and DT_FINI based on magic _init 312 and _fini symbols. We are compatible. */ 313 link_info.init_function = "_init"; 314 link_info.fini_function = "_fini"; 315 link_info.pei386_auto_import = -1; 316 link_info.pei386_runtime_pseudo_reloc = FALSE; 317 link_info.spare_dynamic_tags = 5; 318 link_info.flags = 0; 319 link_info.flags_1 = 0; 320 link_info.relax_pass = 1; 321 link_info.warn_shared_textrel = FALSE; 322 link_info.gc_sections = FALSE; 323 324 ldfile_add_arch (""); 325 326 config.make_executable = TRUE; 327 force_make_executable = FALSE; 328 config.magic_demand_paged = TRUE; 329 config.text_read_only = TRUE; 330 config.data_bss_contig = FALSE; 331 332 emulation = get_emulation (argc, argv); 333 ldemul_choose_mode (emulation); 334 default_target = ldemul_choose_target (argc, argv); 335 lang_init (); 336 ldemul_before_parse (); 337 lang_has_input_file = FALSE; 338 parse_args (argc, argv); 339 340 if (config.hash_table_size != 0) 341 bfd_hash_set_default_size (config.hash_table_size); 342 343 ldemul_set_symbols (); 344 345 if (! link_info.shared && link_info.pie) 346 { 347 if (link_info.relocatable) 348 link_info.pie = FALSE; 349 else 350 link_info.shared = TRUE; 351 } 352 353 if (link_info.relocatable) 354 { 355 if (link_info.gc_sections) 356 einfo ("%P%F: --gc-sections and -r may not be used together\n"); 357 else if (command_line.relax) 358 einfo (_("%P%F: --relax and -r may not be used together\n")); 359 if (link_info.shared) 360 einfo (_("%P%F: -r and -shared may not be used together\n")); 361 } 362 363 if (! link_info.shared) 364 { 365 if (command_line.filter_shlib) 366 einfo (_("%P%F: -F may not be used without -shared\n")); 367 if (command_line.auxiliary_filters) 368 einfo (_("%P%F: -f may not be used without -shared\n")); 369 } 370 371 if (! link_info.shared || link_info.pie) 372 link_info.executable = TRUE; 373 374 if (! config.dynamic_link && link_info.pie) 375 link_info.static_link = TRUE; 376 377 /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I 378 don't see how else this can be handled, since in this case we 379 must preserve all externally visible symbols. */ 380 if (link_info.relocatable && link_info.strip == strip_all) 381 { 382 link_info.strip = strip_debugger; 383 if (link_info.discard == discard_sec_merge) 384 link_info.discard = discard_all; 385 } 386 387 /* This essentially adds another -L directory so this must be done after 388 the -L's in argv have been processed. */ 389 set_scripts_dir (); 390 391 /* If we have not already opened and parsed a linker script 392 read the emulation's appropriate default script. */ 393 if (saved_script_handle == NULL) 394 { 395 int isfile; 396 char *s = ldemul_get_script (&isfile); 397 398 if (isfile) 399 ldfile_open_command_file (s); 400 else 401 { 402 lex_string = s; 403 lex_redirect (s); 404 } 405 parser_input = input_script; 406 yyparse (); 407 lex_string = NULL; 408 } 409 410 if (trace_file_tries) 411 { 412 if (saved_script_handle) 413 info_msg (_("using external linker script:")); 414 else 415 info_msg (_("using internal linker script:")); 416 info_msg ("\n==================================================\n"); 417 418 if (saved_script_handle) 419 { 420 static const int ld_bufsz = 8193; 421 size_t n; 422 char *buf = xmalloc (ld_bufsz); 423 424 rewind (saved_script_handle); 425 while ((n = fread (buf, 1, ld_bufsz - 1, saved_script_handle)) > 0) 426 { 427 buf[n] = 0; 428 info_msg (buf); 429 } 430 rewind (saved_script_handle); 431 free (buf); 432 } 433 else 434 { 435 int isfile; 436 437 info_msg (ldemul_get_script (&isfile)); 438 } 439 440 info_msg ("\n==================================================\n"); 441 } 442 443 lang_final (); 444 445 if (!lang_has_input_file) 446 { 447 if (version_printed) 448 xexit (0); 449 einfo (_("%P%F: no input files\n")); 450 } 451 452 if (trace_files) 453 info_msg (_("%P: mode %s\n"), emulation); 454 455 ldemul_after_parse (); 456 457 if (config.map_filename) 458 { 459 if (strcmp (config.map_filename, "-") == 0) 460 { 461 config.map_file = stdout; 462 } 463 else 464 { 465 config.map_file = fopen (config.map_filename, FOPEN_WT); 466 if (config.map_file == (FILE *) NULL) 467 { 468 bfd_set_error (bfd_error_system_call); 469 einfo (_("%P%F: cannot open map file %s: %E\n"), 470 config.map_filename); 471 } 472 } 473 } 474 475 lang_process (); 476 477 /* Print error messages for any missing symbols, for any warning 478 symbols, and possibly multiple definitions. */ 479 if (link_info.relocatable) 480 output_bfd->flags &= ~EXEC_P; 481 else 482 output_bfd->flags |= EXEC_P; 483 484 ldwrite (); 485 486 if (config.map_file != NULL) 487 lang_map (); 488 if (command_line.cref) 489 output_cref (config.map_file != NULL ? config.map_file : stdout); 490 if (nocrossref_list != NULL) 491 check_nocrossrefs (); 492 493 lang_finish (); 494 495 /* Even if we're producing relocatable output, some non-fatal errors should 496 be reported in the exit status. (What non-fatal errors, if any, do we 497 want to ignore for relocatable output?) */ 498 if (!config.make_executable && !force_make_executable) 499 { 500 if (trace_files) 501 einfo (_("%P: link errors found, deleting executable `%s'\n"), 502 output_filename); 503 504 /* The file will be removed by remove_output. */ 505 xexit (1); 506 } 507 else 508 { 509 if (! bfd_close (output_bfd)) 510 einfo (_("%F%B: final close failed: %E\n"), output_bfd); 511 512 /* If the --force-exe-suffix is enabled, and we're making an 513 executable file and it doesn't end in .exe, copy it to one 514 which does. */ 515 if (! link_info.relocatable && command_line.force_exe_suffix) 516 { 517 int len = strlen (output_filename); 518 519 if (len < 4 520 || (strcasecmp (output_filename + len - 4, ".exe") != 0 521 && strcasecmp (output_filename + len - 4, ".dll") != 0)) 522 { 523 FILE *src; 524 FILE *dst; 525 const int bsize = 4096; 526 char *buf = xmalloc (bsize); 527 int l; 528 char *dst_name = xmalloc (len + 5); 529 530 strcpy (dst_name, output_filename); 531 strcat (dst_name, ".exe"); 532 src = fopen (output_filename, FOPEN_RB); 533 dst = fopen (dst_name, FOPEN_WB); 534 535 if (!src) 536 einfo (_("%X%P: unable to open for source of copy `%s'\n"), 537 output_filename); 538 if (!dst) 539 einfo (_("%X%P: unable to open for destination of copy `%s'\n"), 540 dst_name); 541 while ((l = fread (buf, 1, bsize, src)) > 0) 542 { 543 int done = fwrite (buf, 1, l, dst); 544 545 if (done != l) 546 einfo (_("%P: Error writing file `%s'\n"), dst_name); 547 } 548 549 fclose (src); 550 if (fclose (dst) == EOF) 551 einfo (_("%P: Error closing file `%s'\n"), dst_name); 552 free (dst_name); 553 free (buf); 554 } 555 } 556 } 557 558 END_PROGRESS (program_name); 559 560 if (config.stats) 561 { 562 #ifdef HAVE_SBRK 563 char *lim = sbrk (0); 564 #endif 565 long run_time = get_run_time () - start_time; 566 567 fprintf (stderr, _("%s: total time in link: %ld.%06ld\n"), 568 program_name, run_time / 1000000, run_time % 1000000); 569 #ifdef HAVE_SBRK 570 fprintf (stderr, _("%s: data size %ld\n"), program_name, 571 (long) (lim - (char *) &environ)); 572 #endif 573 } 574 575 /* Prevent remove_output from doing anything, after a successful link. */ 576 output_filename = NULL; 577 578 xexit (0); 579 return 0; 580 } 581 582 /* If the configured sysroot is relocatable, try relocating it based on 583 default prefix FROM. Return the relocated directory if it exists, 584 otherwise return null. */ 585 586 static char * 587 get_relative_sysroot (const char *from ATTRIBUTE_UNUSED) 588 { 589 #ifdef TARGET_SYSTEM_ROOT_RELOCATABLE 590 char *path; 591 struct stat s; 592 593 path = make_relative_prefix (program_name, from, TARGET_SYSTEM_ROOT); 594 if (path) 595 { 596 if (stat (path, &s) == 0 && S_ISDIR (s.st_mode)) 597 return path; 598 free (path); 599 } 600 #endif 601 return 0; 602 } 603 604 /* Return the sysroot directory. Return "" if no sysroot is being used. */ 605 606 static const char * 607 get_sysroot (int argc, char **argv) 608 { 609 int i; 610 const char *path; 611 612 for (i = 1; i < argc; i++) 613 if (strncmp (argv[i], "--sysroot=", strlen ("--sysroot=")) == 0) 614 return argv[i] + strlen ("--sysroot="); 615 616 path = get_relative_sysroot (BINDIR); 617 if (path) 618 return path; 619 620 path = get_relative_sysroot (TOOLBINDIR); 621 if (path) 622 return path; 623 624 return TARGET_SYSTEM_ROOT; 625 } 626 627 /* We need to find any explicitly given emulation in order to initialize the 628 state that's needed by the lex&yacc argument parser (parse_args). */ 629 630 static char * 631 get_emulation (int argc, char **argv) 632 { 633 char *emulation; 634 int i; 635 636 emulation = getenv (EMULATION_ENVIRON); 637 if (emulation == NULL) 638 emulation = DEFAULT_EMULATION; 639 640 for (i = 1; i < argc; i++) 641 { 642 if (!strncmp (argv[i], "-m", 2)) 643 { 644 if (argv[i][2] == '\0') 645 { 646 /* -m EMUL */ 647 if (i < argc - 1) 648 { 649 emulation = argv[i + 1]; 650 i++; 651 } 652 else 653 einfo (_("%P%F: missing argument to -m\n")); 654 } 655 else if (strcmp (argv[i], "-mips1") == 0 656 || strcmp (argv[i], "-mips2") == 0 657 || strcmp (argv[i], "-mips3") == 0 658 || strcmp (argv[i], "-mips4") == 0 659 || strcmp (argv[i], "-mips5") == 0 660 || strcmp (argv[i], "-mips32") == 0 661 || strcmp (argv[i], "-mips32r2") == 0 662 || strcmp (argv[i], "-mips64") == 0 663 || strcmp (argv[i], "-mips64r2") == 0) 664 { 665 /* FIXME: The arguments -mips1, -mips2, -mips3, etc. are 666 passed to the linker by some MIPS compilers. They 667 generally tell the linker to use a slightly different 668 library path. Perhaps someday these should be 669 implemented as emulations; until then, we just ignore 670 the arguments and hope that nobody ever creates 671 emulations named ips1, ips2 or ips3. */ 672 } 673 else if (strcmp (argv[i], "-m486") == 0) 674 { 675 /* FIXME: The argument -m486 is passed to the linker on 676 some Linux systems. Hope that nobody creates an 677 emulation named 486. */ 678 } 679 else 680 { 681 /* -mEMUL */ 682 emulation = &argv[i][2]; 683 } 684 } 685 } 686 687 return emulation; 688 } 689 690 /* If directory DIR contains an "ldscripts" subdirectory, 691 add DIR to the library search path and return TRUE, 692 else return FALSE. */ 693 694 static bfd_boolean 695 check_for_scripts_dir (char *dir) 696 { 697 size_t dirlen; 698 char *buf; 699 struct stat s; 700 bfd_boolean res; 701 702 dirlen = strlen (dir); 703 /* sizeof counts the terminating NUL. */ 704 buf = xmalloc (dirlen + sizeof ("/ldscripts")); 705 sprintf (buf, "%s/ldscripts", dir); 706 707 res = stat (buf, &s) == 0 && S_ISDIR (s.st_mode); 708 free (buf); 709 if (res) 710 ldfile_add_library_path (dir, FALSE); 711 return res; 712 } 713 714 /* Set the default directory for finding script files. 715 Libraries will be searched for here too, but that's ok. 716 We look for the "ldscripts" directory in: 717 718 SCRIPTDIR (passed from Makefile) 719 (adjusted according to the current location of the binary) 720 SCRIPTDIR (passed from Makefile) 721 the dir where this program is (for using it from the build tree) 722 the dir where this program is/../lib 723 (for installing the tool suite elsewhere). */ 724 725 static void 726 set_scripts_dir (void) 727 { 728 char *end, *dir; 729 size_t dirlen; 730 bfd_boolean found; 731 732 dir = make_relative_prefix (program_name, BINDIR, SCRIPTDIR); 733 if (dir) 734 { 735 found = check_for_scripts_dir (dir); 736 free (dir); 737 if (found) 738 return; 739 } 740 741 dir = make_relative_prefix (program_name, TOOLBINDIR, SCRIPTDIR); 742 if (dir) 743 { 744 found = check_for_scripts_dir (dir); 745 free (dir); 746 if (found) 747 return; 748 } 749 750 if (check_for_scripts_dir (SCRIPTDIR)) 751 /* We've been installed normally. */ 752 return; 753 754 /* Look for "ldscripts" in the dir where our binary is. */ 755 end = strrchr (program_name, '/'); 756 #ifdef HAVE_DOS_BASED_FILE_SYSTEM 757 { 758 /* We could have \foo\bar, or /foo\bar. */ 759 char *bslash = strrchr (program_name, '\\'); 760 761 if (end == NULL || (bslash != NULL && bslash > end)) 762 end = bslash; 763 } 764 #endif 765 766 if (end == NULL) 767 /* Don't look for ldscripts in the current directory. There is 768 too much potential for confusion. */ 769 return; 770 771 dirlen = end - program_name; 772 /* Make a copy of program_name in dir. 773 Leave room for later "/../lib". */ 774 dir = xmalloc (dirlen + 8); 775 strncpy (dir, program_name, dirlen); 776 dir[dirlen] = '\0'; 777 778 if (check_for_scripts_dir (dir)) 779 { 780 free (dir); 781 return; 782 } 783 784 /* Look for "ldscripts" in <the dir where our binary is>/../lib. */ 785 strcpy (dir + dirlen, "/../lib"); 786 check_for_scripts_dir (dir); 787 free (dir); 788 } 789 790 void 791 add_ysym (const char *name) 792 { 793 if (link_info.notice_hash == NULL) 794 { 795 link_info.notice_hash = xmalloc (sizeof (struct bfd_hash_table)); 796 if (!bfd_hash_table_init_n (link_info.notice_hash, 797 bfd_hash_newfunc, 798 sizeof (struct bfd_hash_entry), 799 61)) 800 einfo (_("%P%F: bfd_hash_table_init failed: %E\n")); 801 } 802 803 if (bfd_hash_lookup (link_info.notice_hash, name, TRUE, TRUE) == NULL) 804 einfo (_("%P%F: bfd_hash_lookup failed: %E\n")); 805 } 806 807 /* Record a symbol to be wrapped, from the --wrap option. */ 808 809 void 810 add_wrap (const char *name) 811 { 812 if (link_info.wrap_hash == NULL) 813 { 814 link_info.wrap_hash = xmalloc (sizeof (struct bfd_hash_table)); 815 if (!bfd_hash_table_init_n (link_info.wrap_hash, 816 bfd_hash_newfunc, 817 sizeof (struct bfd_hash_entry), 818 61)) 819 einfo (_("%P%F: bfd_hash_table_init failed: %E\n")); 820 } 821 822 if (bfd_hash_lookup (link_info.wrap_hash, name, TRUE, TRUE) == NULL) 823 einfo (_("%P%F: bfd_hash_lookup failed: %E\n")); 824 } 825 826 /* Handle the -retain-symbols-file option. */ 827 828 void 829 add_keepsyms_file (const char *filename) 830 { 831 FILE *file; 832 char *buf; 833 size_t bufsize; 834 int c; 835 836 if (link_info.strip == strip_some) 837 einfo (_("%X%P: error: duplicate retain-symbols-file\n")); 838 839 file = fopen (filename, "r"); 840 if (file == NULL) 841 { 842 bfd_set_error (bfd_error_system_call); 843 einfo ("%X%P: %s: %E\n", filename); 844 return; 845 } 846 847 link_info.keep_hash = xmalloc (sizeof (struct bfd_hash_table)); 848 if (!bfd_hash_table_init (link_info.keep_hash, bfd_hash_newfunc, 849 sizeof (struct bfd_hash_entry))) 850 einfo (_("%P%F: bfd_hash_table_init failed: %E\n")); 851 852 bufsize = 100; 853 buf = xmalloc (bufsize); 854 855 c = getc (file); 856 while (c != EOF) 857 { 858 while (ISSPACE (c)) 859 c = getc (file); 860 861 if (c != EOF) 862 { 863 size_t len = 0; 864 865 while (! ISSPACE (c) && c != EOF) 866 { 867 buf[len] = c; 868 ++len; 869 if (len >= bufsize) 870 { 871 bufsize *= 2; 872 buf = xrealloc (buf, bufsize); 873 } 874 c = getc (file); 875 } 876 877 buf[len] = '\0'; 878 879 if (bfd_hash_lookup (link_info.keep_hash, buf, TRUE, TRUE) == NULL) 880 einfo (_("%P%F: bfd_hash_lookup for insertion failed: %E\n")); 881 } 882 } 883 884 if (link_info.strip != strip_none) 885 einfo (_("%P: `-retain-symbols-file' overrides `-s' and `-S'\n")); 886 887 free (buf); 888 link_info.strip = strip_some; 889 } 890 891 /* Callbacks from the BFD linker routines. */ 892 893 /* This is called when BFD has decided to include an archive member in 894 a link. */ 895 896 static bfd_boolean 897 add_archive_element (struct bfd_link_info *info, 898 bfd *abfd, 899 const char *name) 900 { 901 lang_input_statement_type *input; 902 903 input = xmalloc (sizeof (lang_input_statement_type)); 904 input->filename = abfd->filename; 905 input->local_sym_name = abfd->filename; 906 input->the_bfd = abfd; 907 input->asymbols = NULL; 908 input->next = NULL; 909 input->just_syms_flag = FALSE; 910 input->loaded = FALSE; 911 input->search_dirs_flag = FALSE; 912 913 /* FIXME: The following fields are not set: header.next, 914 header.type, closed, passive_position, symbol_count, 915 next_real_file, is_archive, target, real. This bit of code is 916 from the old decode_library_subfile function. I don't know 917 whether any of those fields matters. */ 918 919 ldlang_add_file (input); 920 921 if (config.map_file != NULL) 922 { 923 static bfd_boolean header_printed; 924 struct bfd_link_hash_entry *h; 925 bfd *from; 926 int len; 927 928 h = bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE); 929 930 if (h == NULL) 931 from = NULL; 932 else 933 { 934 switch (h->type) 935 { 936 default: 937 from = NULL; 938 break; 939 940 case bfd_link_hash_defined: 941 case bfd_link_hash_defweak: 942 from = h->u.def.section->owner; 943 break; 944 945 case bfd_link_hash_undefined: 946 case bfd_link_hash_undefweak: 947 from = h->u.undef.abfd; 948 break; 949 950 case bfd_link_hash_common: 951 from = h->u.c.p->section->owner; 952 break; 953 } 954 } 955 956 if (! header_printed) 957 { 958 char buf[100]; 959 960 sprintf (buf, _("Archive member included because of file (symbol)\n\n")); 961 minfo ("%s", buf); 962 header_printed = TRUE; 963 } 964 965 if (bfd_my_archive (abfd) == NULL) 966 { 967 minfo ("%s", bfd_get_filename (abfd)); 968 len = strlen (bfd_get_filename (abfd)); 969 } 970 else 971 { 972 minfo ("%s(%s)", bfd_get_filename (bfd_my_archive (abfd)), 973 bfd_get_filename (abfd)); 974 len = (strlen (bfd_get_filename (bfd_my_archive (abfd))) 975 + strlen (bfd_get_filename (abfd)) 976 + 2); 977 } 978 979 if (len >= 29) 980 { 981 print_nl (); 982 len = 0; 983 } 984 while (len < 30) 985 { 986 print_space (); 987 ++len; 988 } 989 990 if (from != NULL) 991 minfo ("%B ", from); 992 if (h != NULL) 993 minfo ("(%T)\n", h->root.string); 994 else 995 minfo ("(%s)\n", name); 996 } 997 998 if (trace_files || trace_file_tries) 999 info_msg ("%I\n", input); 1000 1001 return TRUE; 1002 } 1003 1004 /* This is called when BFD has discovered a symbol which is defined 1005 multiple times. */ 1006 1007 static bfd_boolean 1008 multiple_definition (struct bfd_link_info *info ATTRIBUTE_UNUSED, 1009 const char *name, 1010 bfd *obfd, 1011 asection *osec, 1012 bfd_vma oval, 1013 bfd *nbfd, 1014 asection *nsec, 1015 bfd_vma nval) 1016 { 1017 /* If either section has the output_section field set to 1018 bfd_abs_section_ptr, it means that the section is being 1019 discarded, and this is not really a multiple definition at all. 1020 FIXME: It would be cleaner to somehow ignore symbols defined in 1021 sections which are being discarded. */ 1022 if ((osec->output_section != NULL 1023 && ! bfd_is_abs_section (osec) 1024 && bfd_is_abs_section (osec->output_section)) 1025 || (nsec->output_section != NULL 1026 && ! bfd_is_abs_section (nsec) 1027 && bfd_is_abs_section (nsec->output_section))) 1028 return TRUE; 1029 1030 einfo (_("%X%C: multiple definition of `%T'\n"), 1031 nbfd, nsec, nval, name); 1032 if (obfd != NULL) 1033 einfo (_("%D: first defined here\n"), obfd, osec, oval); 1034 1035 if (command_line.relax) 1036 { 1037 einfo (_("%P: Disabling relaxation: it will not work with multiple definitions\n")); 1038 command_line.relax = 0; 1039 } 1040 1041 return TRUE; 1042 } 1043 1044 /* This is called when there is a definition of a common symbol, or 1045 when a common symbol is found for a symbol that is already defined, 1046 or when two common symbols are found. We only do something if 1047 -warn-common was used. */ 1048 1049 static bfd_boolean 1050 multiple_common (struct bfd_link_info *info ATTRIBUTE_UNUSED, 1051 const char *name, 1052 bfd *obfd, 1053 enum bfd_link_hash_type otype, 1054 bfd_vma osize, 1055 bfd *nbfd, 1056 enum bfd_link_hash_type ntype, 1057 bfd_vma nsize) 1058 { 1059 if (! config.warn_common) 1060 return TRUE; 1061 1062 if (ntype == bfd_link_hash_defined 1063 || ntype == bfd_link_hash_defweak 1064 || ntype == bfd_link_hash_indirect) 1065 { 1066 ASSERT (otype == bfd_link_hash_common); 1067 einfo (_("%B: warning: definition of `%T' overriding common\n"), 1068 nbfd, name); 1069 if (obfd != NULL) 1070 einfo (_("%B: warning: common is here\n"), obfd); 1071 } 1072 else if (otype == bfd_link_hash_defined 1073 || otype == bfd_link_hash_defweak 1074 || otype == bfd_link_hash_indirect) 1075 { 1076 ASSERT (ntype == bfd_link_hash_common); 1077 einfo (_("%B: warning: common of `%T' overridden by definition\n"), 1078 nbfd, name); 1079 if (obfd != NULL) 1080 einfo (_("%B: warning: defined here\n"), obfd); 1081 } 1082 else 1083 { 1084 ASSERT (otype == bfd_link_hash_common && ntype == bfd_link_hash_common); 1085 if (osize > nsize) 1086 { 1087 einfo (_("%B: warning: common of `%T' overridden by larger common\n"), 1088 nbfd, name); 1089 if (obfd != NULL) 1090 einfo (_("%B: warning: larger common is here\n"), obfd); 1091 } 1092 else if (nsize > osize) 1093 { 1094 einfo (_("%B: warning: common of `%T' overriding smaller common\n"), 1095 nbfd, name); 1096 if (obfd != NULL) 1097 einfo (_("%B: warning: smaller common is here\n"), obfd); 1098 } 1099 else 1100 { 1101 einfo (_("%B: warning: multiple common of `%T'\n"), nbfd, name); 1102 if (obfd != NULL) 1103 einfo (_("%B: warning: previous common is here\n"), obfd); 1104 } 1105 } 1106 1107 return TRUE; 1108 } 1109 1110 /* This is called when BFD has discovered a set element. H is the 1111 entry in the linker hash table for the set. SECTION and VALUE 1112 represent a value which should be added to the set. */ 1113 1114 static bfd_boolean 1115 add_to_set (struct bfd_link_info *info ATTRIBUTE_UNUSED, 1116 struct bfd_link_hash_entry *h, 1117 bfd_reloc_code_real_type reloc, 1118 bfd *abfd, 1119 asection *section, 1120 bfd_vma value) 1121 { 1122 if (config.warn_constructors) 1123 einfo (_("%P: warning: global constructor %s used\n"), 1124 h->root.string); 1125 1126 if (! config.build_constructors) 1127 return TRUE; 1128 1129 ldctor_add_set_entry (h, reloc, NULL, section, value); 1130 1131 if (h->type == bfd_link_hash_new) 1132 { 1133 h->type = bfd_link_hash_undefined; 1134 h->u.undef.abfd = abfd; 1135 /* We don't call bfd_link_add_undef to add this to the list of 1136 undefined symbols because we are going to define it 1137 ourselves. */ 1138 } 1139 1140 return TRUE; 1141 } 1142 1143 /* This is called when BFD has discovered a constructor. This is only 1144 called for some object file formats--those which do not handle 1145 constructors in some more clever fashion. This is similar to 1146 adding an element to a set, but less general. */ 1147 1148 static bfd_boolean 1149 constructor_callback (struct bfd_link_info *info, 1150 bfd_boolean constructor, 1151 const char *name, 1152 bfd *abfd, 1153 asection *section, 1154 bfd_vma value) 1155 { 1156 char *s; 1157 struct bfd_link_hash_entry *h; 1158 char set_name[1 + sizeof "__CTOR_LIST__"]; 1159 1160 if (config.warn_constructors) 1161 einfo (_("%P: warning: global constructor %s used\n"), name); 1162 1163 if (! config.build_constructors) 1164 return TRUE; 1165 1166 /* Ensure that BFD_RELOC_CTOR exists now, so that we can give a 1167 useful error message. */ 1168 if (bfd_reloc_type_lookup (output_bfd, BFD_RELOC_CTOR) == NULL 1169 && (info->relocatable 1170 || bfd_reloc_type_lookup (abfd, BFD_RELOC_CTOR) == NULL)) 1171 einfo (_("%P%F: BFD backend error: BFD_RELOC_CTOR unsupported\n")); 1172 1173 s = set_name; 1174 if (bfd_get_symbol_leading_char (abfd) != '\0') 1175 *s++ = bfd_get_symbol_leading_char (abfd); 1176 if (constructor) 1177 strcpy (s, "__CTOR_LIST__"); 1178 else 1179 strcpy (s, "__DTOR_LIST__"); 1180 1181 h = bfd_link_hash_lookup (info->hash, set_name, TRUE, TRUE, TRUE); 1182 if (h == (struct bfd_link_hash_entry *) NULL) 1183 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n")); 1184 if (h->type == bfd_link_hash_new) 1185 { 1186 h->type = bfd_link_hash_undefined; 1187 h->u.undef.abfd = abfd; 1188 /* We don't call bfd_link_add_undef to add this to the list of 1189 undefined symbols because we are going to define it 1190 ourselves. */ 1191 } 1192 1193 ldctor_add_set_entry (h, BFD_RELOC_CTOR, name, section, value); 1194 return TRUE; 1195 } 1196 1197 /* A structure used by warning_callback to pass information through 1198 bfd_map_over_sections. */ 1199 1200 struct warning_callback_info 1201 { 1202 bfd_boolean found; 1203 const char *warning; 1204 const char *symbol; 1205 asymbol **asymbols; 1206 }; 1207 1208 /* This is called when there is a reference to a warning symbol. */ 1209 1210 static bfd_boolean 1211 warning_callback (struct bfd_link_info *info ATTRIBUTE_UNUSED, 1212 const char *warning, 1213 const char *symbol, 1214 bfd *abfd, 1215 asection *section, 1216 bfd_vma address) 1217 { 1218 /* This is a hack to support warn_multiple_gp. FIXME: This should 1219 have a cleaner interface, but what? */ 1220 if (! config.warn_multiple_gp 1221 && strcmp (warning, "using multiple gp values") == 0) 1222 return TRUE; 1223 1224 if (section != NULL) 1225 einfo ("%C: %s%s\n", abfd, section, address, _("warning: "), warning); 1226 else if (abfd == NULL) 1227 einfo ("%P: %s%s\n", _("warning: "), warning); 1228 else if (symbol == NULL) 1229 einfo ("%B: %s%s\n", abfd, _("warning: "), warning); 1230 else 1231 { 1232 lang_input_statement_type *entry; 1233 asymbol **asymbols; 1234 struct warning_callback_info info; 1235 1236 /* Look through the relocs to see if we can find a plausible 1237 address. */ 1238 entry = (lang_input_statement_type *) abfd->usrdata; 1239 if (entry != NULL && entry->asymbols != NULL) 1240 asymbols = entry->asymbols; 1241 else 1242 { 1243 long symsize; 1244 long symbol_count; 1245 1246 symsize = bfd_get_symtab_upper_bound (abfd); 1247 if (symsize < 0) 1248 einfo (_("%B%F: could not read symbols: %E\n"), abfd); 1249 asymbols = xmalloc (symsize); 1250 symbol_count = bfd_canonicalize_symtab (abfd, asymbols); 1251 if (symbol_count < 0) 1252 einfo (_("%B%F: could not read symbols: %E\n"), abfd); 1253 if (entry != NULL) 1254 { 1255 entry->asymbols = asymbols; 1256 entry->symbol_count = symbol_count; 1257 } 1258 } 1259 1260 info.found = FALSE; 1261 info.warning = warning; 1262 info.symbol = symbol; 1263 info.asymbols = asymbols; 1264 bfd_map_over_sections (abfd, warning_find_reloc, &info); 1265 1266 if (! info.found) 1267 einfo ("%B: %s%s\n", abfd, _("warning: "), warning); 1268 1269 if (entry == NULL) 1270 free (asymbols); 1271 } 1272 1273 return TRUE; 1274 } 1275 1276 /* This is called by warning_callback for each section. It checks the 1277 relocs of the section to see if it can find a reference to the 1278 symbol which triggered the warning. If it can, it uses the reloc 1279 to give an error message with a file and line number. */ 1280 1281 static void 1282 warning_find_reloc (bfd *abfd, asection *sec, void *iarg) 1283 { 1284 struct warning_callback_info *info = iarg; 1285 long relsize; 1286 arelent **relpp; 1287 long relcount; 1288 arelent **p, **pend; 1289 1290 if (info->found) 1291 return; 1292 1293 relsize = bfd_get_reloc_upper_bound (abfd, sec); 1294 if (relsize < 0) 1295 einfo (_("%B%F: could not read relocs: %E\n"), abfd); 1296 if (relsize == 0) 1297 return; 1298 1299 relpp = xmalloc (relsize); 1300 relcount = bfd_canonicalize_reloc (abfd, sec, relpp, info->asymbols); 1301 if (relcount < 0) 1302 einfo (_("%B%F: could not read relocs: %E\n"), abfd); 1303 1304 p = relpp; 1305 pend = p + relcount; 1306 for (; p < pend && *p != NULL; p++) 1307 { 1308 arelent *q = *p; 1309 1310 if (q->sym_ptr_ptr != NULL 1311 && *q->sym_ptr_ptr != NULL 1312 && strcmp (bfd_asymbol_name (*q->sym_ptr_ptr), info->symbol) == 0) 1313 { 1314 /* We found a reloc for the symbol we are looking for. */ 1315 einfo ("%C: %s%s\n", abfd, sec, q->address, _("warning: "), 1316 info->warning); 1317 info->found = TRUE; 1318 break; 1319 } 1320 } 1321 1322 free (relpp); 1323 } 1324 1325 /* This is called when an undefined symbol is found. */ 1326 1327 static bfd_boolean 1328 undefined_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED, 1329 const char *name, 1330 bfd *abfd, 1331 asection *section, 1332 bfd_vma address, 1333 bfd_boolean error) 1334 { 1335 static char *error_name; 1336 static unsigned int error_count; 1337 1338 #define MAX_ERRORS_IN_A_ROW 5 1339 1340 if (config.warn_once) 1341 { 1342 static struct bfd_hash_table *hash; 1343 1344 /* Only warn once about a particular undefined symbol. */ 1345 if (hash == NULL) 1346 { 1347 hash = xmalloc (sizeof (struct bfd_hash_table)); 1348 if (!bfd_hash_table_init (hash, bfd_hash_newfunc, 1349 sizeof (struct bfd_hash_entry))) 1350 einfo (_("%F%P: bfd_hash_table_init failed: %E\n")); 1351 } 1352 1353 if (bfd_hash_lookup (hash, name, FALSE, FALSE) != NULL) 1354 return TRUE; 1355 1356 if (bfd_hash_lookup (hash, name, TRUE, TRUE) == NULL) 1357 einfo (_("%F%P: bfd_hash_lookup failed: %E\n")); 1358 } 1359 1360 /* We never print more than a reasonable number of errors in a row 1361 for a single symbol. */ 1362 if (error_name != NULL 1363 && strcmp (name, error_name) == 0) 1364 ++error_count; 1365 else 1366 { 1367 error_count = 0; 1368 if (error_name != NULL) 1369 free (error_name); 1370 error_name = xstrdup (name); 1371 } 1372 1373 if (section != NULL) 1374 { 1375 if (error_count < MAX_ERRORS_IN_A_ROW) 1376 { 1377 if (error) 1378 einfo (_("%X%C: undefined reference to `%T'\n"), 1379 abfd, section, address, name); 1380 else 1381 einfo (_("%C: warning: undefined reference to `%T'\n"), 1382 abfd, section, address, name); 1383 } 1384 else if (error_count == MAX_ERRORS_IN_A_ROW) 1385 { 1386 if (error) 1387 einfo (_("%X%D: more undefined references to `%T' follow\n"), 1388 abfd, section, address, name); 1389 else 1390 einfo (_("%D: warning: more undefined references to `%T' follow\n"), 1391 abfd, section, address, name); 1392 } 1393 else if (error) 1394 einfo ("%X"); 1395 } 1396 else 1397 { 1398 if (error_count < MAX_ERRORS_IN_A_ROW) 1399 { 1400 if (error) 1401 einfo (_("%X%B: undefined reference to `%T'\n"), 1402 abfd, name); 1403 else 1404 einfo (_("%B: warning: undefined reference to `%T'\n"), 1405 abfd, name); 1406 } 1407 else if (error_count == MAX_ERRORS_IN_A_ROW) 1408 { 1409 if (error) 1410 einfo (_("%X%B: more undefined references to `%T' follow\n"), 1411 abfd, name); 1412 else 1413 einfo (_("%B: warning: more undefined references to `%T' follow\n"), 1414 abfd, name); 1415 } 1416 else if (error) 1417 einfo ("%X"); 1418 } 1419 1420 return TRUE; 1421 } 1422 1423 /* Counter to limit the number of relocation overflow error messages 1424 to print. Errors are printed as it is decremented. When it's 1425 called and the counter is zero, a final message is printed 1426 indicating more relocations were omitted. When it gets to -1, no 1427 such errors are printed. If it's initially set to a value less 1428 than -1, all such errors will be printed (--verbose does this). */ 1429 1430 int overflow_cutoff_limit = 10; 1431 1432 /* This is called when a reloc overflows. */ 1433 1434 static bfd_boolean 1435 reloc_overflow (struct bfd_link_info *info ATTRIBUTE_UNUSED, 1436 struct bfd_link_hash_entry *entry, 1437 const char *name, 1438 const char *reloc_name, 1439 bfd_vma addend, 1440 bfd *abfd, 1441 asection *section, 1442 bfd_vma address) 1443 { 1444 if (overflow_cutoff_limit == -1) 1445 return TRUE; 1446 1447 einfo ("%X%C:", abfd, section, address); 1448 1449 if (overflow_cutoff_limit >= 0 1450 && overflow_cutoff_limit-- == 0) 1451 { 1452 einfo (_(" additional relocation overflows omitted from the output\n")); 1453 return TRUE; 1454 } 1455 1456 if (entry) 1457 { 1458 while (entry->type == bfd_link_hash_indirect 1459 || entry->type == bfd_link_hash_warning) 1460 entry = entry->u.i.link; 1461 switch (entry->type) 1462 { 1463 case bfd_link_hash_undefined: 1464 case bfd_link_hash_undefweak: 1465 einfo (_(" relocation truncated to fit: %s against undefined symbol `%T'"), 1466 reloc_name, entry->root.string); 1467 break; 1468 case bfd_link_hash_defined: 1469 case bfd_link_hash_defweak: 1470 einfo (_(" relocation truncated to fit: %s against symbol `%T' defined in %A section in %B"), 1471 reloc_name, entry->root.string, 1472 entry->u.def.section, 1473 entry->u.def.section == bfd_abs_section_ptr 1474 ? output_bfd : entry->u.def.section->owner); 1475 break; 1476 default: 1477 abort (); 1478 break; 1479 } 1480 } 1481 else 1482 einfo (_(" relocation truncated to fit: %s against `%T'"), 1483 reloc_name, name); 1484 if (addend != 0) 1485 einfo ("+%v", addend); 1486 einfo ("\n"); 1487 return TRUE; 1488 } 1489 1490 /* This is called when a dangerous relocation is made. */ 1491 1492 static bfd_boolean 1493 reloc_dangerous (struct bfd_link_info *info ATTRIBUTE_UNUSED, 1494 const char *message, 1495 bfd *abfd, 1496 asection *section, 1497 bfd_vma address) 1498 { 1499 einfo (_("%X%C: dangerous relocation: %s\n"), 1500 abfd, section, address, message); 1501 return TRUE; 1502 } 1503 1504 /* This is called when a reloc is being generated attached to a symbol 1505 that is not being output. */ 1506 1507 static bfd_boolean 1508 unattached_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED, 1509 const char *name, 1510 bfd *abfd, 1511 asection *section, 1512 bfd_vma address) 1513 { 1514 einfo (_("%X%C: reloc refers to symbol `%T' which is not being output\n"), 1515 abfd, section, address, name); 1516 return TRUE; 1517 } 1518 1519 /* This is called if link_info.notice_all is set, or when a symbol in 1520 link_info.notice_hash is found. Symbols are put in notice_hash 1521 using the -y option. */ 1522 1523 static bfd_boolean 1524 notice (struct bfd_link_info *info, 1525 const char *name, 1526 bfd *abfd, 1527 asection *section, 1528 bfd_vma value) 1529 { 1530 if (! info->notice_all 1531 || (info->notice_hash != NULL 1532 && bfd_hash_lookup (info->notice_hash, name, FALSE, FALSE) != NULL)) 1533 { 1534 if (bfd_is_und_section (section)) 1535 einfo ("%B: reference to %s\n", abfd, name); 1536 else 1537 einfo ("%B: definition of %s\n", abfd, name); 1538 } 1539 1540 if (command_line.cref || nocrossref_list != NULL) 1541 add_cref (name, abfd, section, value); 1542 1543 return TRUE; 1544 } 1545