1 /* Main program of GNU linker.
2 Copyright (C) 1991, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
5 This file is part of GLD, the Gnu Linker.
7 GLD is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GLD is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GLD; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include "libiberty.h"
42 /* Somewhere above, sys/stat.h got included . . . . */
43 #if !defined(S_ISDIR) && defined(S_IFDIR)
44 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
49 static char *get_emulation PARAMS ((int, char **));
50 static void set_scripts_dir PARAMS ((void));
55 const char *output_filename = "a.out";
57 /* Name this program was invoked by. */
60 /* The file that we're creating */
63 /* Set by -G argument, for MIPS ECOFF target. */
64 int g_switch_value = 8;
66 /* Nonzero means print names of input files as processed. */
69 /* Nonzero means same, but note open failures, too. */
70 boolean trace_file_tries;
72 /* Nonzero means version number was printed, so exit successfully
73 instead of complaining if no input files are given. */
74 boolean version_printed;
76 /* Nonzero means link in every member of an archive. */
77 boolean whole_archive;
79 args_type command_line;
81 ld_config_type config;
83 static boolean check_for_scripts_dir PARAMS ((char *dir));
84 static boolean add_archive_element PARAMS ((struct bfd_link_info *, bfd *,
86 static boolean multiple_definition PARAMS ((struct bfd_link_info *,
88 bfd *, asection *, bfd_vma,
89 bfd *, asection *, bfd_vma));
90 static boolean multiple_common PARAMS ((struct bfd_link_info *,
92 enum bfd_link_hash_type, bfd_vma,
93 bfd *, enum bfd_link_hash_type,
95 static boolean add_to_set PARAMS ((struct bfd_link_info *,
96 struct bfd_link_hash_entry *,
97 bfd_reloc_code_real_type,
98 bfd *, asection *, bfd_vma));
99 static boolean constructor_callback PARAMS ((struct bfd_link_info *,
102 bfd *, asection *, bfd_vma));
103 static boolean warning_callback PARAMS ((struct bfd_link_info *,
104 const char *, const char *, bfd *,
105 asection *, bfd_vma));
106 static void warning_find_reloc PARAMS ((bfd *, asection *, PTR));
107 static boolean undefined_symbol PARAMS ((struct bfd_link_info *,
109 asection *, bfd_vma));
110 static boolean reloc_overflow PARAMS ((struct bfd_link_info *, const char *,
111 const char *, bfd_vma,
112 bfd *, asection *, bfd_vma));
113 static boolean reloc_dangerous PARAMS ((struct bfd_link_info *, const char *,
114 bfd *, asection *, bfd_vma));
115 static boolean unattached_reloc PARAMS ((struct bfd_link_info *,
116 const char *, bfd *, asection *,
118 static boolean notice PARAMS ((struct bfd_link_info *, const char *,
119 bfd *, asection *, bfd_vma));
121 static struct bfd_link_callbacks link_callbacks =
127 constructor_callback,
136 struct bfd_link_info link_info;
143 if (output_bfd && output_bfd->iostream)
144 fclose((FILE *)(output_bfd->iostream));
145 if (delete_output_file_on_failure)
146 unlink (output_filename);
156 long start_time = get_run_time ();
158 program_name = argv[0];
159 xmalloc_set_program_name (program_name);
161 START_PROGRESS (program_name, 0);
165 bfd_set_error_program_name (program_name);
167 xatexit (remove_output);
169 /* Initialize the data about options. */
170 trace_files = trace_file_tries = version_printed = false;
171 whole_archive = false;
172 config.build_constructors = true;
173 config.dynamic_link = false;
174 command_line.force_common_definition = false;
175 command_line.interpreter = NULL;
176 command_line.rpath = NULL;
178 link_info.callbacks = &link_callbacks;
179 link_info.relocateable = false;
180 link_info.shared = false;
181 link_info.symbolic = false;
182 link_info.static_link = false;
183 link_info.traditional_format = false;
184 link_info.strip = strip_none;
185 link_info.discard = discard_none;
186 link_info.lprefix_len = 1;
187 link_info.lprefix = "L";
188 link_info.keep_memory = true;
189 link_info.input_bfds = NULL;
190 link_info.create_object_symbols_section = NULL;
191 link_info.hash = NULL;
192 link_info.keep_hash = NULL;
193 link_info.notice_all = false;
194 link_info.notice_hash = NULL;
195 link_info.wrap_hash = NULL;
197 ldfile_add_arch ("");
199 config.make_executable = true;
200 force_make_executable = false;
201 config.magic_demand_paged = true;
202 config.text_read_only = true;
203 config.make_executable = true;
205 emulation = get_emulation (argc, argv);
206 ldemul_choose_mode (emulation);
207 default_target = ldemul_choose_target ();
209 ldemul_before_parse ();
210 lang_has_input_file = false;
211 parse_args (argc, argv);
213 ldemul_set_symbols ();
215 if (link_info.relocateable)
217 if (command_line.relax)
218 einfo ("%P%F: -relax and -r may not be used together\n");
219 if (link_info.shared)
220 einfo ("%P%F: -r and -shared may not be used together\n");
223 /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I
224 don't see how else this can be handled, since in this case we
225 must preserve all externally visible symbols. */
226 if (link_info.relocateable && link_info.strip == strip_all)
228 link_info.strip = strip_debugger;
229 if (link_info.discard == discard_none)
230 link_info.discard = discard_all;
233 /* This essentially adds another -L directory so this must be done after
234 the -L's in argv have been processed. */
237 if (had_script == false)
239 /* Read the emulation's appropriate default script. */
241 char *s = ldemul_get_script (&isfile);
244 ldfile_open_command_file (s);
247 if (trace_file_tries)
249 info_msg ("using internal linker script:\n");
250 info_msg ("==================================================\n");
252 info_msg ("\n==================================================\n");
257 parser_input = input_script;
264 if (lang_has_input_file == false)
268 einfo ("%P%F: no input files\n");
273 info_msg ("%P: mode %s\n", emulation);
276 ldemul_after_parse ();
279 if (config.map_filename)
281 if (strcmp (config.map_filename, "-") == 0)
283 config.map_file = stdout;
287 config.map_file = fopen (config.map_filename, FOPEN_WT);
288 if (config.map_file == (FILE *) NULL)
290 bfd_set_error (bfd_error_system_call);
291 einfo ("%P%F: cannot open map file %s: %E\n",
292 config.map_filename);
300 /* Print error messages for any missing symbols, for any warning
301 symbols, and possibly multiple definitions */
304 if (config.text_read_only)
306 /* Look for a text section and mark the readonly attribute in it */
307 asection *found = bfd_get_section_by_name (output_bfd, ".text");
309 if (found != (asection *) NULL)
311 found->flags |= SEC_READONLY;
315 if (link_info.relocateable)
316 output_bfd->flags &= ~EXEC_P;
318 output_bfd->flags |= EXEC_P;
322 if (config.map_file != NULL)
324 if (command_line.cref)
325 output_cref (config.map_file != NULL ? config.map_file : stdout);
327 /* Even if we're producing relocateable output, some non-fatal errors should
328 be reported in the exit status. (What non-fatal errors, if any, do we
329 want to ignore for relocateable output?) */
331 if (config.make_executable == false && force_make_executable == false)
333 if (trace_files == true)
335 einfo ("%P: link errors found, deleting executable `%s'\n",
339 /* The file will be removed by remove_output. */
345 if (! bfd_close (output_bfd))
346 einfo ("%F%B: final close failed: %E\n", output_bfd);
348 /* If the --force-exe-suffix is enabled, and we're making an
349 executable file and it doesn't end in .exe, copy it to one which does. */
351 if (! link_info.relocateable && command_line.force_exe_suffix)
353 int len = strlen (output_filename);
355 || (strcasecmp (output_filename + len - 4, ".exe") != 0
356 && strcasecmp (output_filename + len - 4, ".dll") != 0))
360 const int bsize = 4096;
361 char *buf = xmalloc (bsize);
363 char *dst_name = xmalloc (len + 5);
364 strcpy (dst_name, output_filename);
365 strcat (dst_name, ".exe");
366 src = fopen (output_filename, FOPEN_RB);
367 dst = fopen (dst_name, FOPEN_WB);
370 einfo ("%X%P: unable to open for source of copy `%s'\n", output_filename);
372 einfo ("%X%P: unable to open for destination of copy `%s'\n", dst_name);
373 while ((l = fread (buf, 1, bsize, src)) > 0)
375 int done = fwrite (buf, 1, l, dst);
378 einfo ("%P: Error writing file `%s'\n", dst_name);
384 einfo ("%P: Error closing file `%s'\n", dst_name);
392 END_PROGRESS (program_name);
396 extern char **environ;
398 char *lim = (char *) sbrk (0);
400 long run_time = get_run_time () - start_time;
402 fprintf (stderr, "%s: total time in link: %ld.%06ld\n",
403 program_name, run_time / 1000000, run_time % 1000000);
405 fprintf (stderr, "%s: data size %ld\n", program_name,
406 (long) (lim - (char *) &environ));
410 /* Prevent remove_output from doing anything, after a successful link. */
411 output_filename = NULL;
417 /* We need to find any explicitly given emulation in order to initialize the
418 state that's needed by the lex&yacc argument parser (parse_args). */
421 get_emulation (argc, argv)
428 emulation = (char *) getenv (EMULATION_ENVIRON);
429 if (emulation == NULL)
430 emulation = DEFAULT_EMULATION;
432 for (i = 1; i < argc; i++)
434 if (!strncmp (argv[i], "-m", 2))
436 if (argv[i][2] == '\0')
441 emulation = argv[i + 1];
446 einfo("%P%F: missing argument to -m\n");
449 else if (strcmp (argv[i], "-mips1") == 0
450 || strcmp (argv[i], "-mips2") == 0
451 || strcmp (argv[i], "-mips3") == 0)
453 /* FIXME: The arguments -mips1, -mips2 and -mips3 are
454 passed to the linker by some MIPS compilers. They
455 generally tell the linker to use a slightly different
456 library path. Perhaps someday these should be
457 implemented as emulations; until then, we just ignore
458 the arguments and hope that nobody ever creates
459 emulations named ips1, ips2 or ips3. */
461 else if (strcmp (argv[i], "-m486") == 0)
463 /* FIXME: The argument -m486 is passed to the linker on
464 some Linux systems. Hope that nobody creates an
465 emulation named 486. */
470 emulation = &argv[i][2];
478 /* If directory DIR contains an "ldscripts" subdirectory,
479 add DIR to the library search path and return true,
480 else return false. */
483 check_for_scripts_dir (dir)
491 dirlen = strlen (dir);
492 /* sizeof counts the terminating NUL. */
493 buf = (char *) xmalloc (dirlen + sizeof("/ldscripts"));
494 sprintf (buf, "%s/ldscripts", dir);
496 res = stat (buf, &s) == 0 && S_ISDIR (s.st_mode);
499 ldfile_add_library_path (dir, false);
503 /* Set the default directory for finding script files.
504 Libraries will be searched for here too, but that's ok.
505 We look for the "ldscripts" directory in:
507 SCRIPTDIR (passed from Makefile)
508 the dir where this program is (for using it from the build tree)
509 the dir where this program is/../lib (for installing the tool suite elsewhere) */
517 if (check_for_scripts_dir (SCRIPTDIR))
518 return; /* We've been installed normally. */
520 /* Look for "ldscripts" in the dir where our binary is. */
521 end = strrchr (program_name, '/');
525 /* Don't look for ldscripts in the current directory. There is
526 too much potential for confusion. */
530 dirlen = end - program_name;
531 /* Make a copy of program_name in dir.
532 Leave room for later "/../lib". */
533 dir = (char *) xmalloc (dirlen + 8);
534 strncpy (dir, program_name, dirlen);
537 if (check_for_scripts_dir (dir))
538 return; /* Don't free dir. */
540 /* Look for "ldscripts" in <the dir where our binary is>/../lib. */
541 strcpy (dir + dirlen, "/../lib");
542 if (check_for_scripts_dir (dir))
545 free (dir); /* Well, we tried. */
552 if (link_info.notice_hash == (struct bfd_hash_table *) NULL)
554 link_info.notice_hash = ((struct bfd_hash_table *)
555 xmalloc (sizeof (struct bfd_hash_table)));
556 if (! bfd_hash_table_init_n (link_info.notice_hash,
559 einfo ("%P%F: bfd_hash_table_init failed: %E\n");
562 if (bfd_hash_lookup (link_info.notice_hash, name, true, true)
563 == (struct bfd_hash_entry *) NULL)
564 einfo ("%P%F: bfd_hash_lookup failed: %E\n");
567 /* Record a symbol to be wrapped, from the --wrap option. */
573 if (link_info.wrap_hash == NULL)
575 link_info.wrap_hash = ((struct bfd_hash_table *)
576 xmalloc (sizeof (struct bfd_hash_table)));
577 if (! bfd_hash_table_init_n (link_info.wrap_hash,
580 einfo ("%P%F: bfd_hash_table_init failed: %E\n");
582 if (bfd_hash_lookup (link_info.wrap_hash, name, true, true) == NULL)
583 einfo ("%P%F: bfd_hash_lookup failed: %E\n");
586 /* Handle the -retain-symbols-file option. */
589 add_keepsyms_file (filename)
590 const char *filename;
597 if (link_info.strip == strip_some)
598 einfo ("%X%P: error: duplicate retain-symbols-file\n");
600 file = fopen (filename, "r");
601 if (file == (FILE *) NULL)
603 bfd_set_error (bfd_error_system_call);
604 einfo ("%X%P: %s: %E\n", filename);
608 link_info.keep_hash = ((struct bfd_hash_table *)
609 xmalloc (sizeof (struct bfd_hash_table)));
610 if (! bfd_hash_table_init (link_info.keep_hash, bfd_hash_newfunc))
611 einfo ("%P%F: bfd_hash_table_init failed: %E\n");
614 buf = (char *) xmalloc (bufsize);
626 while (! isspace (c) && c != EOF)
633 buf = xrealloc (buf, bufsize);
640 if (bfd_hash_lookup (link_info.keep_hash, buf, true, true)
641 == (struct bfd_hash_entry *) NULL)
642 einfo ("%P%F: bfd_hash_lookup for insertion failed: %E\n");
646 if (link_info.strip != strip_none)
647 einfo ("%P: `-retain-symbols-file' overrides `-s' and `-S'\n");
649 link_info.strip = strip_some;
652 /* Callbacks from the BFD linker routines. */
654 /* This is called when BFD has decided to include an archive member in
659 add_archive_element (info, abfd, name)
660 struct bfd_link_info *info;
664 lang_input_statement_type *input;
666 input = ((lang_input_statement_type *)
667 xmalloc (sizeof (lang_input_statement_type)));
668 input->filename = abfd->filename;
669 input->local_sym_name = abfd->filename;
670 input->the_bfd = abfd;
671 input->asymbols = NULL;
673 input->just_syms_flag = false;
674 input->loaded = false;
675 input->search_dirs_flag = false;
677 /* FIXME: The following fields are not set: header.next,
678 header.type, closed, passive_position, symbol_count,
679 next_real_file, is_archive, target, real. This bit of code is
680 from the old decode_library_subfile function. I don't know
681 whether any of those fields matters. */
683 ldlang_add_file (input);
685 if (config.map_file != (FILE *) NULL)
687 static boolean header_printed;
688 struct bfd_link_hash_entry *h;
692 h = bfd_link_hash_lookup (link_info.hash, name, false, false, true);
704 case bfd_link_hash_defined:
705 case bfd_link_hash_defweak:
706 from = h->u.def.section->owner;
709 case bfd_link_hash_undefined:
710 case bfd_link_hash_undefweak:
711 from = h->u.undef.abfd;
714 case bfd_link_hash_common:
715 from = h->u.c.p->section->owner;
720 if (! header_printed)
724 sprintf (buf, "%-29s %s\n\n", "Archive member included",
725 "because of file (symbol)");
727 header_printed = true;
730 if (bfd_my_archive (abfd) == NULL)
732 minfo ("%s", bfd_get_filename (abfd));
733 len = strlen (bfd_get_filename (abfd));
737 minfo ("%s(%s)", bfd_get_filename (bfd_my_archive (abfd)),
738 bfd_get_filename (abfd));
739 len = (strlen (bfd_get_filename (bfd_my_archive (abfd)))
740 + strlen (bfd_get_filename (abfd))
758 minfo ("(%T)\n", h->root.string);
760 minfo ("(%s)\n", name);
763 if (trace_files || trace_file_tries)
764 info_msg ("%I\n", input);
769 /* This is called when BFD has discovered a symbol which is defined
774 multiple_definition (info, name, obfd, osec, oval, nbfd, nsec, nval)
775 struct bfd_link_info *info;
784 /* If either section has the output_section field set to
785 bfd_abs_section_ptr, it means that the section is being
786 discarded, and this is not really a multiple definition at all.
787 FIXME: It would be cleaner to somehow ignore symbols defined in
788 sections which are being discarded. */
789 if ((osec->output_section != NULL
790 && bfd_is_abs_section (osec->output_section))
791 || (nsec->output_section != NULL
792 && bfd_is_abs_section (nsec->output_section)))
795 einfo ("%X%C: multiple definition of `%T'\n",
796 nbfd, nsec, nval, name);
797 if (obfd != (bfd *) NULL)
798 einfo ("%D: first defined here\n", obfd, osec, oval);
802 /* This is called when there is a definition of a common symbol, or
803 when a common symbol is found for a symbol that is already defined,
804 or when two common symbols are found. We only do something if
805 -warn-common was used. */
809 multiple_common (info, name, obfd, otype, osize, nbfd, ntype, nsize)
810 struct bfd_link_info *info;
813 enum bfd_link_hash_type otype;
816 enum bfd_link_hash_type ntype;
819 if (! config.warn_common)
822 if (ntype == bfd_link_hash_defined
823 || ntype == bfd_link_hash_defweak
824 || ntype == bfd_link_hash_indirect)
826 ASSERT (otype == bfd_link_hash_common);
827 einfo ("%B: warning: definition of `%T' overriding common\n",
830 einfo ("%B: warning: common is here\n", obfd);
832 else if (otype == bfd_link_hash_defined
833 || otype == bfd_link_hash_defweak
834 || otype == bfd_link_hash_indirect)
836 ASSERT (ntype == bfd_link_hash_common);
837 einfo ("%B: warning: common of `%T' overridden by definition\n",
840 einfo ("%B: warning: defined here\n", obfd);
844 ASSERT (otype == bfd_link_hash_common && ntype == bfd_link_hash_common);
847 einfo ("%B: warning: common of `%T' overridden by larger common\n",
850 einfo ("%B: warning: larger common is here\n", obfd);
852 else if (nsize > osize)
854 einfo ("%B: warning: common of `%T' overriding smaller common\n",
857 einfo ("%B: warning: smaller common is here\n", obfd);
861 einfo ("%B: warning: multiple common of `%T'\n", nbfd, name);
863 einfo ("%B: warning: previous common is here\n", obfd);
870 /* This is called when BFD has discovered a set element. H is the
871 entry in the linker hash table for the set. SECTION and VALUE
872 represent a value which should be added to the set. */
876 add_to_set (info, h, reloc, abfd, section, value)
877 struct bfd_link_info *info;
878 struct bfd_link_hash_entry *h;
879 bfd_reloc_code_real_type reloc;
884 if (config.warn_constructors)
885 einfo ("%P: warning: global constructor %s used\n",
888 if (! config.build_constructors)
891 ldctor_add_set_entry (h, reloc, (const char *) NULL, section, value);
893 if (h->type == bfd_link_hash_new)
895 h->type = bfd_link_hash_undefined;
896 h->u.undef.abfd = abfd;
897 /* We don't call bfd_link_add_undef to add this to the list of
898 undefined symbols because we are going to define it
905 /* This is called when BFD has discovered a constructor. This is only
906 called for some object file formats--those which do not handle
907 constructors in some more clever fashion. This is similar to
908 adding an element to a set, but less general. */
911 constructor_callback (info, constructor, name, abfd, section, value)
912 struct bfd_link_info *info;
920 struct bfd_link_hash_entry *h;
921 char set_name[1 + sizeof "__CTOR_LIST__"];
923 if (config.warn_constructors)
924 einfo ("%P: warning: global constructor %s used\n", name);
926 if (! config.build_constructors)
929 /* Ensure that BFD_RELOC_CTOR exists now, so that we can give a
930 useful error message. */
931 if (bfd_reloc_type_lookup (output_bfd, BFD_RELOC_CTOR) == NULL
932 && (link_info.relocateable
933 || bfd_reloc_type_lookup (abfd, BFD_RELOC_CTOR) == NULL))
934 einfo ("%P%F: BFD backend error: BFD_RELOC_CTOR unsupported\n");
937 if (bfd_get_symbol_leading_char (abfd) != '\0')
938 *s++ = bfd_get_symbol_leading_char (abfd);
940 strcpy (s, "__CTOR_LIST__");
942 strcpy (s, "__DTOR_LIST__");
944 h = bfd_link_hash_lookup (info->hash, set_name, true, true, true);
945 if (h == (struct bfd_link_hash_entry *) NULL)
946 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
947 if (h->type == bfd_link_hash_new)
949 h->type = bfd_link_hash_undefined;
950 h->u.undef.abfd = abfd;
951 /* We don't call bfd_link_add_undef to add this to the list of
952 undefined symbols because we are going to define it
956 ldctor_add_set_entry (h, BFD_RELOC_CTOR, name, section, value);
960 /* A structure used by warning_callback to pass information through
961 bfd_map_over_sections. */
963 struct warning_callback_info
971 /* This is called when there is a reference to a warning symbol. */
975 warning_callback (info, warning, symbol, abfd, section, address)
976 struct bfd_link_info *info;
983 /* This is a hack to support warn_multiple_gp. FIXME: This should
984 have a cleaner interface, but what? */
985 if (! config.warn_multiple_gp
986 && strcmp (warning, "using multiple gp values") == 0)
990 einfo ("%C: %s\n", abfd, section, address, warning);
991 else if (abfd == NULL)
992 einfo ("%P: %s\n", warning);
993 else if (symbol == NULL)
994 einfo ("%B: %s\n", abfd, warning);
997 lang_input_statement_type *entry;
999 struct warning_callback_info info;
1001 /* Look through the relocs to see if we can find a plausible
1004 entry = (lang_input_statement_type *) abfd->usrdata;
1005 if (entry != NULL && entry->asymbols != NULL)
1006 asymbols = entry->asymbols;
1012 symsize = bfd_get_symtab_upper_bound (abfd);
1014 einfo ("%B%F: could not read symbols: %E\n", abfd);
1015 asymbols = (asymbol **) xmalloc (symsize);
1016 symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
1017 if (symbol_count < 0)
1018 einfo ("%B%F: could not read symbols: %E\n", abfd);
1021 entry->asymbols = asymbols;
1022 entry->symbol_count = symbol_count;
1027 info.warning = warning;
1028 info.symbol = symbol;
1029 info.asymbols = asymbols;
1030 bfd_map_over_sections (abfd, warning_find_reloc, (PTR) &info);
1033 einfo ("%B: %s\n", abfd, warning);
1039 /* This is called by warning_callback for each section. It checks the
1040 relocs of the section to see if it can find a reference to the
1041 symbol which triggered the warning. If it can, it uses the reloc
1042 to give an error message with a file and line number. */
1045 warning_find_reloc (abfd, sec, iarg)
1050 struct warning_callback_info *info = (struct warning_callback_info *) iarg;
1054 arelent **p, **pend;
1059 relsize = bfd_get_reloc_upper_bound (abfd, sec);
1061 einfo ("%B%F: could not read relocs: %E\n", abfd);
1065 relpp = (arelent **) xmalloc (relsize);
1066 relcount = bfd_canonicalize_reloc (abfd, sec, relpp, info->asymbols);
1068 einfo ("%B%F: could not read relocs: %E\n", abfd);
1071 pend = p + relcount;
1072 for (; p < pend && *p != NULL; p++)
1076 if (q->sym_ptr_ptr != NULL
1077 && *q->sym_ptr_ptr != NULL
1078 && strcmp (bfd_asymbol_name (*q->sym_ptr_ptr), info->symbol) == 0)
1080 /* We found a reloc for the symbol we are looking for. */
1081 einfo ("%C: %s\n", abfd, sec, q->address, info->warning);
1090 /* This is called when an undefined symbol is found. */
1094 undefined_symbol (info, name, abfd, section, address)
1095 struct bfd_link_info *info;
1101 static char *error_name;
1102 static unsigned int error_count;
1104 #define MAX_ERRORS_IN_A_ROW 5
1106 if (config.warn_once)
1108 static struct bfd_hash_table *hash;
1110 /* Only warn once about a particular undefined symbol. */
1114 hash = ((struct bfd_hash_table *)
1115 xmalloc (sizeof (struct bfd_hash_table)));
1116 if (! bfd_hash_table_init (hash, bfd_hash_newfunc))
1117 einfo ("%F%P: bfd_hash_table_init failed: %E\n");
1120 if (bfd_hash_lookup (hash, name, false, false) != NULL)
1123 if (bfd_hash_lookup (hash, name, true, true) == NULL)
1124 einfo ("%F%P: bfd_hash_lookup failed: %E\n");
1127 /* We never print more than a reasonable number of errors in a row
1128 for a single symbol. */
1129 if (error_name != (char *) NULL
1130 && strcmp (name, error_name) == 0)
1135 if (error_name != (char *) NULL)
1137 error_name = buystring (name);
1140 if (section != NULL)
1142 if (error_count < MAX_ERRORS_IN_A_ROW)
1143 einfo ("%X%C: undefined reference to `%T'\n",
1144 abfd, section, address, name);
1145 else if (error_count == MAX_ERRORS_IN_A_ROW)
1146 einfo ("%D: more undefined references to `%T' follow\n",
1147 abfd, section, address, name);
1151 if (error_count < MAX_ERRORS_IN_A_ROW)
1152 einfo ("%X%B: undefined reference to `%T'\n",
1154 else if (error_count == MAX_ERRORS_IN_A_ROW)
1155 einfo ("%B: more undefined references to `%T' follow\n",
1162 /* This is called when a reloc overflows. */
1166 reloc_overflow (info, name, reloc_name, addend, abfd, section, address)
1167 struct bfd_link_info *info;
1169 const char *reloc_name;
1175 if (abfd == (bfd *) NULL)
1176 einfo ("%P%X: generated");
1178 einfo ("%X%C:", abfd, section, address);
1179 einfo (" relocation truncated to fit: %s %T", reloc_name, name);
1181 einfo ("+%v", addend);
1186 /* This is called when a dangerous relocation is made. */
1190 reloc_dangerous (info, message, abfd, section, address)
1191 struct bfd_link_info *info;
1192 const char *message;
1197 if (abfd == (bfd *) NULL)
1198 einfo ("%P%X: generated");
1200 einfo ("%X%C:", abfd, section, address);
1201 einfo ("dangerous relocation: %s\n", message);
1205 /* This is called when a reloc is being generated attached to a symbol
1206 that is not being output. */
1210 unattached_reloc (info, name, abfd, section, address)
1211 struct bfd_link_info *info;
1217 if (abfd == (bfd *) NULL)
1218 einfo ("%P%X: generated");
1220 einfo ("%X%C:", abfd, section, address);
1221 einfo (" reloc refers to symbol `%T' which is not being output\n", name);
1225 /* This is called if link_info.notice_all is set, or when a symbol in
1226 link_info.notice_hash is found. Symbols are put in notice_hash
1227 using the -y option. */
1230 notice (info, name, abfd, section, value)
1231 struct bfd_link_info *info;
1237 if (! info->notice_all
1238 || (info->notice_hash != NULL
1239 && bfd_hash_lookup (info->notice_hash, name, false, false) != NULL))
1240 einfo ("%B: %s %s\n", abfd,
1241 bfd_is_und_section (section) ? "reference to" : "definition of",
1244 if (command_line.cref)
1245 add_cref (name, abfd, section, value);