1 /* Main program of GNU linker.
2 Copyright (C) 1991, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 Written by Steve Chamberlain steve@cygnus.com
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);
326 if (nocrossref_list != NULL)
327 check_nocrossrefs ();
329 /* Even if we're producing relocateable output, some non-fatal errors should
330 be reported in the exit status. (What non-fatal errors, if any, do we
331 want to ignore for relocateable output?) */
333 if (config.make_executable == false && force_make_executable == false)
335 if (trace_files == true)
337 einfo ("%P: link errors found, deleting executable `%s'\n",
341 /* The file will be removed by remove_output. */
347 if (! bfd_close (output_bfd))
348 einfo ("%F%B: final close failed: %E\n", output_bfd);
350 /* If the --force-exe-suffix is enabled, and we're making an
351 executable file and it doesn't end in .exe, copy it to one which does. */
353 if (! link_info.relocateable && command_line.force_exe_suffix)
355 int len = strlen (output_filename);
357 || (strcasecmp (output_filename + len - 4, ".exe") != 0
358 && strcasecmp (output_filename + len - 4, ".dll") != 0))
362 const int bsize = 4096;
363 char *buf = xmalloc (bsize);
365 char *dst_name = xmalloc (len + 5);
366 strcpy (dst_name, output_filename);
367 strcat (dst_name, ".exe");
368 src = fopen (output_filename, FOPEN_RB);
369 dst = fopen (dst_name, FOPEN_WB);
372 einfo ("%X%P: unable to open for source of copy `%s'\n", output_filename);
374 einfo ("%X%P: unable to open for destination of copy `%s'\n", dst_name);
375 while ((l = fread (buf, 1, bsize, src)) > 0)
377 int done = fwrite (buf, 1, l, dst);
380 einfo ("%P: Error writing file `%s'\n", dst_name);
386 einfo ("%P: Error closing file `%s'\n", dst_name);
394 END_PROGRESS (program_name);
398 extern char **environ;
400 char *lim = (char *) sbrk (0);
402 long run_time = get_run_time () - start_time;
404 fprintf (stderr, "%s: total time in link: %ld.%06ld\n",
405 program_name, run_time / 1000000, run_time % 1000000);
407 fprintf (stderr, "%s: data size %ld\n", program_name,
408 (long) (lim - (char *) &environ));
412 /* Prevent remove_output from doing anything, after a successful link. */
413 output_filename = NULL;
419 /* We need to find any explicitly given emulation in order to initialize the
420 state that's needed by the lex&yacc argument parser (parse_args). */
423 get_emulation (argc, argv)
430 emulation = (char *) getenv (EMULATION_ENVIRON);
431 if (emulation == NULL)
432 emulation = DEFAULT_EMULATION;
434 for (i = 1; i < argc; i++)
436 if (!strncmp (argv[i], "-m", 2))
438 if (argv[i][2] == '\0')
443 emulation = argv[i + 1];
448 einfo("%P%F: missing argument to -m\n");
451 else if (strcmp (argv[i], "-mips1") == 0
452 || strcmp (argv[i], "-mips2") == 0
453 || strcmp (argv[i], "-mips3") == 0)
455 /* FIXME: The arguments -mips1, -mips2 and -mips3 are
456 passed to the linker by some MIPS compilers. They
457 generally tell the linker to use a slightly different
458 library path. Perhaps someday these should be
459 implemented as emulations; until then, we just ignore
460 the arguments and hope that nobody ever creates
461 emulations named ips1, ips2 or ips3. */
463 else if (strcmp (argv[i], "-m486") == 0)
465 /* FIXME: The argument -m486 is passed to the linker on
466 some Linux systems. Hope that nobody creates an
467 emulation named 486. */
472 emulation = &argv[i][2];
480 /* If directory DIR contains an "ldscripts" subdirectory,
481 add DIR to the library search path and return true,
482 else return false. */
485 check_for_scripts_dir (dir)
493 dirlen = strlen (dir);
494 /* sizeof counts the terminating NUL. */
495 buf = (char *) xmalloc (dirlen + sizeof("/ldscripts"));
496 sprintf (buf, "%s/ldscripts", dir);
498 res = stat (buf, &s) == 0 && S_ISDIR (s.st_mode);
501 ldfile_add_library_path (dir, false);
505 /* Set the default directory for finding script files.
506 Libraries will be searched for here too, but that's ok.
507 We look for the "ldscripts" directory in:
509 SCRIPTDIR (passed from Makefile)
510 the dir where this program is (for using it from the build tree)
511 the dir where this program is/../lib (for installing the tool suite elsewhere) */
519 if (check_for_scripts_dir (SCRIPTDIR))
520 return; /* We've been installed normally. */
522 /* Look for "ldscripts" in the dir where our binary is. */
523 end = strrchr (program_name, '/');
527 /* Don't look for ldscripts in the current directory. There is
528 too much potential for confusion. */
532 dirlen = end - program_name;
533 /* Make a copy of program_name in dir.
534 Leave room for later "/../lib". */
535 dir = (char *) xmalloc (dirlen + 8);
536 strncpy (dir, program_name, dirlen);
539 if (check_for_scripts_dir (dir))
540 return; /* Don't free dir. */
542 /* Look for "ldscripts" in <the dir where our binary is>/../lib. */
543 strcpy (dir + dirlen, "/../lib");
544 if (check_for_scripts_dir (dir))
547 free (dir); /* Well, we tried. */
554 if (link_info.notice_hash == (struct bfd_hash_table *) NULL)
556 link_info.notice_hash = ((struct bfd_hash_table *)
557 xmalloc (sizeof (struct bfd_hash_table)));
558 if (! bfd_hash_table_init_n (link_info.notice_hash,
561 einfo ("%P%F: bfd_hash_table_init failed: %E\n");
564 if (bfd_hash_lookup (link_info.notice_hash, name, true, true)
565 == (struct bfd_hash_entry *) NULL)
566 einfo ("%P%F: bfd_hash_lookup failed: %E\n");
569 /* Record a symbol to be wrapped, from the --wrap option. */
575 if (link_info.wrap_hash == NULL)
577 link_info.wrap_hash = ((struct bfd_hash_table *)
578 xmalloc (sizeof (struct bfd_hash_table)));
579 if (! bfd_hash_table_init_n (link_info.wrap_hash,
582 einfo ("%P%F: bfd_hash_table_init failed: %E\n");
584 if (bfd_hash_lookup (link_info.wrap_hash, name, true, true) == NULL)
585 einfo ("%P%F: bfd_hash_lookup failed: %E\n");
588 /* Handle the -retain-symbols-file option. */
591 add_keepsyms_file (filename)
592 const char *filename;
599 if (link_info.strip == strip_some)
600 einfo ("%X%P: error: duplicate retain-symbols-file\n");
602 file = fopen (filename, "r");
603 if (file == (FILE *) NULL)
605 bfd_set_error (bfd_error_system_call);
606 einfo ("%X%P: %s: %E\n", filename);
610 link_info.keep_hash = ((struct bfd_hash_table *)
611 xmalloc (sizeof (struct bfd_hash_table)));
612 if (! bfd_hash_table_init (link_info.keep_hash, bfd_hash_newfunc))
613 einfo ("%P%F: bfd_hash_table_init failed: %E\n");
616 buf = (char *) xmalloc (bufsize);
628 while (! isspace (c) && c != EOF)
635 buf = xrealloc (buf, bufsize);
642 if (bfd_hash_lookup (link_info.keep_hash, buf, true, true)
643 == (struct bfd_hash_entry *) NULL)
644 einfo ("%P%F: bfd_hash_lookup for insertion failed: %E\n");
648 if (link_info.strip != strip_none)
649 einfo ("%P: `-retain-symbols-file' overrides `-s' and `-S'\n");
651 link_info.strip = strip_some;
654 /* Callbacks from the BFD linker routines. */
656 /* This is called when BFD has decided to include an archive member in
661 add_archive_element (info, abfd, name)
662 struct bfd_link_info *info;
666 lang_input_statement_type *input;
668 input = ((lang_input_statement_type *)
669 xmalloc (sizeof (lang_input_statement_type)));
670 input->filename = abfd->filename;
671 input->local_sym_name = abfd->filename;
672 input->the_bfd = abfd;
673 input->asymbols = NULL;
675 input->just_syms_flag = false;
676 input->loaded = false;
677 input->search_dirs_flag = false;
679 /* FIXME: The following fields are not set: header.next,
680 header.type, closed, passive_position, symbol_count,
681 next_real_file, is_archive, target, real. This bit of code is
682 from the old decode_library_subfile function. I don't know
683 whether any of those fields matters. */
685 ldlang_add_file (input);
687 if (config.map_file != (FILE *) NULL)
689 static boolean header_printed;
690 struct bfd_link_hash_entry *h;
694 h = bfd_link_hash_lookup (link_info.hash, name, false, false, true);
706 case bfd_link_hash_defined:
707 case bfd_link_hash_defweak:
708 from = h->u.def.section->owner;
711 case bfd_link_hash_undefined:
712 case bfd_link_hash_undefweak:
713 from = h->u.undef.abfd;
716 case bfd_link_hash_common:
717 from = h->u.c.p->section->owner;
722 if (! header_printed)
726 sprintf (buf, "%-29s %s\n\n", "Archive member included",
727 "because of file (symbol)");
729 header_printed = true;
732 if (bfd_my_archive (abfd) == NULL)
734 minfo ("%s", bfd_get_filename (abfd));
735 len = strlen (bfd_get_filename (abfd));
739 minfo ("%s(%s)", bfd_get_filename (bfd_my_archive (abfd)),
740 bfd_get_filename (abfd));
741 len = (strlen (bfd_get_filename (bfd_my_archive (abfd)))
742 + strlen (bfd_get_filename (abfd))
760 minfo ("(%T)\n", h->root.string);
762 minfo ("(%s)\n", name);
765 if (trace_files || trace_file_tries)
766 info_msg ("%I\n", input);
771 /* This is called when BFD has discovered a symbol which is defined
776 multiple_definition (info, name, obfd, osec, oval, nbfd, nsec, nval)
777 struct bfd_link_info *info;
786 /* If either section has the output_section field set to
787 bfd_abs_section_ptr, it means that the section is being
788 discarded, and this is not really a multiple definition at all.
789 FIXME: It would be cleaner to somehow ignore symbols defined in
790 sections which are being discarded. */
791 if ((osec->output_section != NULL
792 && bfd_is_abs_section (osec->output_section))
793 || (nsec->output_section != NULL
794 && bfd_is_abs_section (nsec->output_section)))
797 einfo ("%X%C: multiple definition of `%T'\n",
798 nbfd, nsec, nval, name);
799 if (obfd != (bfd *) NULL)
800 einfo ("%D: first defined here\n", obfd, osec, oval);
804 /* This is called when there is a definition of a common symbol, or
805 when a common symbol is found for a symbol that is already defined,
806 or when two common symbols are found. We only do something if
807 -warn-common was used. */
811 multiple_common (info, name, obfd, otype, osize, nbfd, ntype, nsize)
812 struct bfd_link_info *info;
815 enum bfd_link_hash_type otype;
818 enum bfd_link_hash_type ntype;
821 if (! config.warn_common)
824 if (ntype == bfd_link_hash_defined
825 || ntype == bfd_link_hash_defweak
826 || ntype == bfd_link_hash_indirect)
828 ASSERT (otype == bfd_link_hash_common);
829 einfo ("%B: warning: definition of `%T' overriding common\n",
832 einfo ("%B: warning: common is here\n", obfd);
834 else if (otype == bfd_link_hash_defined
835 || otype == bfd_link_hash_defweak
836 || otype == bfd_link_hash_indirect)
838 ASSERT (ntype == bfd_link_hash_common);
839 einfo ("%B: warning: common of `%T' overridden by definition\n",
842 einfo ("%B: warning: defined here\n", obfd);
846 ASSERT (otype == bfd_link_hash_common && ntype == bfd_link_hash_common);
849 einfo ("%B: warning: common of `%T' overridden by larger common\n",
852 einfo ("%B: warning: larger common is here\n", obfd);
854 else if (nsize > osize)
856 einfo ("%B: warning: common of `%T' overriding smaller common\n",
859 einfo ("%B: warning: smaller common is here\n", obfd);
863 einfo ("%B: warning: multiple common of `%T'\n", nbfd, name);
865 einfo ("%B: warning: previous common is here\n", obfd);
872 /* This is called when BFD has discovered a set element. H is the
873 entry in the linker hash table for the set. SECTION and VALUE
874 represent a value which should be added to the set. */
878 add_to_set (info, h, reloc, abfd, section, value)
879 struct bfd_link_info *info;
880 struct bfd_link_hash_entry *h;
881 bfd_reloc_code_real_type reloc;
886 if (config.warn_constructors)
887 einfo ("%P: warning: global constructor %s used\n",
890 if (! config.build_constructors)
893 ldctor_add_set_entry (h, reloc, (const char *) NULL, section, value);
895 if (h->type == bfd_link_hash_new)
897 h->type = bfd_link_hash_undefined;
898 h->u.undef.abfd = abfd;
899 /* We don't call bfd_link_add_undef to add this to the list of
900 undefined symbols because we are going to define it
907 /* This is called when BFD has discovered a constructor. This is only
908 called for some object file formats--those which do not handle
909 constructors in some more clever fashion. This is similar to
910 adding an element to a set, but less general. */
913 constructor_callback (info, constructor, name, abfd, section, value)
914 struct bfd_link_info *info;
922 struct bfd_link_hash_entry *h;
923 char set_name[1 + sizeof "__CTOR_LIST__"];
925 if (config.warn_constructors)
926 einfo ("%P: warning: global constructor %s used\n", name);
928 if (! config.build_constructors)
931 /* Ensure that BFD_RELOC_CTOR exists now, so that we can give a
932 useful error message. */
933 if (bfd_reloc_type_lookup (output_bfd, BFD_RELOC_CTOR) == NULL
934 && (link_info.relocateable
935 || bfd_reloc_type_lookup (abfd, BFD_RELOC_CTOR) == NULL))
936 einfo ("%P%F: BFD backend error: BFD_RELOC_CTOR unsupported\n");
939 if (bfd_get_symbol_leading_char (abfd) != '\0')
940 *s++ = bfd_get_symbol_leading_char (abfd);
942 strcpy (s, "__CTOR_LIST__");
944 strcpy (s, "__DTOR_LIST__");
946 h = bfd_link_hash_lookup (info->hash, set_name, true, true, true);
947 if (h == (struct bfd_link_hash_entry *) NULL)
948 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
949 if (h->type == bfd_link_hash_new)
951 h->type = bfd_link_hash_undefined;
952 h->u.undef.abfd = abfd;
953 /* We don't call bfd_link_add_undef to add this to the list of
954 undefined symbols because we are going to define it
958 ldctor_add_set_entry (h, BFD_RELOC_CTOR, name, section, value);
962 /* A structure used by warning_callback to pass information through
963 bfd_map_over_sections. */
965 struct warning_callback_info
973 /* This is called when there is a reference to a warning symbol. */
977 warning_callback (info, warning, symbol, abfd, section, address)
978 struct bfd_link_info *info;
985 /* This is a hack to support warn_multiple_gp. FIXME: This should
986 have a cleaner interface, but what? */
987 if (! config.warn_multiple_gp
988 && strcmp (warning, "using multiple gp values") == 0)
992 einfo ("%C: %s\n", abfd, section, address, warning);
993 else if (abfd == NULL)
994 einfo ("%P: %s\n", warning);
995 else if (symbol == NULL)
996 einfo ("%B: %s\n", abfd, warning);
999 lang_input_statement_type *entry;
1001 struct warning_callback_info info;
1003 /* Look through the relocs to see if we can find a plausible
1006 entry = (lang_input_statement_type *) abfd->usrdata;
1007 if (entry != NULL && entry->asymbols != NULL)
1008 asymbols = entry->asymbols;
1014 symsize = bfd_get_symtab_upper_bound (abfd);
1016 einfo ("%B%F: could not read symbols: %E\n", abfd);
1017 asymbols = (asymbol **) xmalloc (symsize);
1018 symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
1019 if (symbol_count < 0)
1020 einfo ("%B%F: could not read symbols: %E\n", abfd);
1023 entry->asymbols = asymbols;
1024 entry->symbol_count = symbol_count;
1029 info.warning = warning;
1030 info.symbol = symbol;
1031 info.asymbols = asymbols;
1032 bfd_map_over_sections (abfd, warning_find_reloc, (PTR) &info);
1035 einfo ("%B: %s\n", abfd, warning);
1044 /* This is called by warning_callback for each section. It checks the
1045 relocs of the section to see if it can find a reference to the
1046 symbol which triggered the warning. If it can, it uses the reloc
1047 to give an error message with a file and line number. */
1050 warning_find_reloc (abfd, sec, iarg)
1055 struct warning_callback_info *info = (struct warning_callback_info *) iarg;
1059 arelent **p, **pend;
1064 relsize = bfd_get_reloc_upper_bound (abfd, sec);
1066 einfo ("%B%F: could not read relocs: %E\n", abfd);
1070 relpp = (arelent **) xmalloc (relsize);
1071 relcount = bfd_canonicalize_reloc (abfd, sec, relpp, info->asymbols);
1073 einfo ("%B%F: could not read relocs: %E\n", abfd);
1076 pend = p + relcount;
1077 for (; p < pend && *p != NULL; p++)
1081 if (q->sym_ptr_ptr != NULL
1082 && *q->sym_ptr_ptr != NULL
1083 && strcmp (bfd_asymbol_name (*q->sym_ptr_ptr), info->symbol) == 0)
1085 /* We found a reloc for the symbol we are looking for. */
1086 einfo ("%C: %s\n", abfd, sec, q->address, info->warning);
1095 /* This is called when an undefined symbol is found. */
1099 undefined_symbol (info, name, abfd, section, address)
1100 struct bfd_link_info *info;
1106 static char *error_name;
1107 static unsigned int error_count;
1109 #define MAX_ERRORS_IN_A_ROW 5
1111 if (config.warn_once)
1113 static struct bfd_hash_table *hash;
1115 /* Only warn once about a particular undefined symbol. */
1119 hash = ((struct bfd_hash_table *)
1120 xmalloc (sizeof (struct bfd_hash_table)));
1121 if (! bfd_hash_table_init (hash, bfd_hash_newfunc))
1122 einfo ("%F%P: bfd_hash_table_init failed: %E\n");
1125 if (bfd_hash_lookup (hash, name, false, false) != NULL)
1128 if (bfd_hash_lookup (hash, name, true, true) == NULL)
1129 einfo ("%F%P: bfd_hash_lookup failed: %E\n");
1132 /* We never print more than a reasonable number of errors in a row
1133 for a single symbol. */
1134 if (error_name != (char *) NULL
1135 && strcmp (name, error_name) == 0)
1140 if (error_name != (char *) NULL)
1142 error_name = buystring (name);
1145 if (section != NULL)
1147 if (error_count < MAX_ERRORS_IN_A_ROW)
1148 einfo ("%X%C: undefined reference to `%T'\n",
1149 abfd, section, address, name);
1150 else if (error_count == MAX_ERRORS_IN_A_ROW)
1151 einfo ("%D: more undefined references to `%T' follow\n",
1152 abfd, section, address, name);
1156 if (error_count < MAX_ERRORS_IN_A_ROW)
1157 einfo ("%X%B: undefined reference to `%T'\n",
1159 else if (error_count == MAX_ERRORS_IN_A_ROW)
1160 einfo ("%B: more undefined references to `%T' follow\n",
1167 /* This is called when a reloc overflows. */
1171 reloc_overflow (info, name, reloc_name, addend, abfd, section, address)
1172 struct bfd_link_info *info;
1174 const char *reloc_name;
1180 if (abfd == (bfd *) NULL)
1181 einfo ("%P%X: generated");
1183 einfo ("%X%C:", abfd, section, address);
1184 einfo (" relocation truncated to fit: %s %T", reloc_name, name);
1186 einfo ("+%v", addend);
1191 /* This is called when a dangerous relocation is made. */
1195 reloc_dangerous (info, message, abfd, section, address)
1196 struct bfd_link_info *info;
1197 const char *message;
1202 if (abfd == (bfd *) NULL)
1203 einfo ("%P%X: generated");
1205 einfo ("%X%C:", abfd, section, address);
1206 einfo ("dangerous relocation: %s\n", message);
1210 /* This is called when a reloc is being generated attached to a symbol
1211 that is not being output. */
1215 unattached_reloc (info, name, abfd, section, address)
1216 struct bfd_link_info *info;
1222 if (abfd == (bfd *) NULL)
1223 einfo ("%P%X: generated");
1225 einfo ("%X%C:", abfd, section, address);
1226 einfo (" reloc refers to symbol `%T' which is not being output\n", name);
1230 /* This is called if link_info.notice_all is set, or when a symbol in
1231 link_info.notice_hash is found. Symbols are put in notice_hash
1232 using the -y option. */
1235 notice (info, name, abfd, section, value)
1236 struct bfd_link_info *info;
1242 if (! info->notice_all
1243 || (info->notice_hash != NULL
1244 && bfd_hash_lookup (info->notice_hash, name, false, false) != NULL))
1245 einfo ("%B: %s %s\n", abfd,
1246 bfd_is_und_section (section) ? "reference to" : "definition of",
1249 if (command_line.cref || nocrossref_list != NULL)
1250 add_cref (name, abfd, section, value);