1 /* Main program of GNU linker.
2 Copyright (C) 1991, 92, 93, 94, 95, 96, 1997 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)
50 #ifdef NEED_DECLARATION_SBRK
55 static char *get_emulation
PARAMS ((int, char **));
56 static void set_scripts_dir
PARAMS ((void));
61 const char *output_filename
= "a.out";
63 /* Name this program was invoked by. */
66 /* The file that we're creating */
69 /* Set by -G argument, for MIPS ECOFF target. */
70 int g_switch_value
= 8;
72 /* Nonzero means print names of input files as processed. */
75 /* Nonzero means same, but note open failures, too. */
76 boolean trace_file_tries
;
78 /* Nonzero means version number was printed, so exit successfully
79 instead of complaining if no input files are given. */
80 boolean version_printed
;
82 /* Nonzero means link in every member of an archive. */
83 boolean whole_archive
;
85 args_type command_line
;
87 ld_config_type config
;
89 static boolean check_for_scripts_dir
PARAMS ((char *dir
));
90 static boolean add_archive_element
PARAMS ((struct bfd_link_info
*, bfd
*,
92 static boolean multiple_definition
PARAMS ((struct bfd_link_info
*,
94 bfd
*, asection
*, bfd_vma
,
95 bfd
*, asection
*, bfd_vma
));
96 static boolean multiple_common
PARAMS ((struct bfd_link_info
*,
98 enum bfd_link_hash_type
, bfd_vma
,
99 bfd
*, enum bfd_link_hash_type
,
101 static boolean add_to_set
PARAMS ((struct bfd_link_info
*,
102 struct bfd_link_hash_entry
*,
103 bfd_reloc_code_real_type
,
104 bfd
*, asection
*, bfd_vma
));
105 static boolean constructor_callback
PARAMS ((struct bfd_link_info
*,
108 bfd
*, asection
*, bfd_vma
));
109 static boolean warning_callback
PARAMS ((struct bfd_link_info
*,
110 const char *, const char *, bfd
*,
111 asection
*, bfd_vma
));
112 static void warning_find_reloc
PARAMS ((bfd
*, asection
*, PTR
));
113 static boolean undefined_symbol
PARAMS ((struct bfd_link_info
*,
115 asection
*, bfd_vma
));
116 static boolean reloc_overflow
PARAMS ((struct bfd_link_info
*, const char *,
117 const char *, bfd_vma
,
118 bfd
*, asection
*, bfd_vma
));
119 static boolean reloc_dangerous
PARAMS ((struct bfd_link_info
*, const char *,
120 bfd
*, asection
*, bfd_vma
));
121 static boolean unattached_reloc
PARAMS ((struct bfd_link_info
*,
122 const char *, bfd
*, asection
*,
124 static boolean notice
PARAMS ((struct bfd_link_info
*, const char *,
125 bfd
*, asection
*, bfd_vma
));
127 static struct bfd_link_callbacks link_callbacks
=
133 constructor_callback
,
142 struct bfd_link_info link_info
;
149 if (output_bfd
&& output_bfd
->iostream
)
150 fclose((FILE *)(output_bfd
->iostream
));
151 if (delete_output_file_on_failure
)
152 unlink (output_filename
);
162 long start_time
= get_run_time ();
164 program_name
= argv
[0];
165 xmalloc_set_program_name (program_name
);
167 START_PROGRESS (program_name
, 0);
171 bfd_set_error_program_name (program_name
);
173 xatexit (remove_output
);
175 /* Set the default BFD target based on the configured target. Doing
176 this permits the linker to be configured for a particular target,
177 and linked against a shared BFD library which was configured for
178 a different target. The macro TARGET is defined by Makefile. */
179 if (! bfd_set_default_target (TARGET
))
181 einfo ("%X%P: can't set BFD default target to `%s': %E\n", TARGET
);
185 /* Initialize the data about options. */
186 trace_files
= trace_file_tries
= version_printed
= false;
187 whole_archive
= false;
188 config
.build_constructors
= true;
189 config
.dynamic_link
= false;
190 command_line
.force_common_definition
= false;
191 command_line
.interpreter
= NULL
;
192 command_line
.rpath
= NULL
;
194 link_info
.callbacks
= &link_callbacks
;
195 link_info
.relocateable
= false;
196 link_info
.shared
= false;
197 link_info
.symbolic
= false;
198 link_info
.static_link
= false;
199 link_info
.traditional_format
= false;
200 link_info
.strip
= strip_none
;
201 link_info
.discard
= discard_none
;
202 link_info
.keep_memory
= true;
203 link_info
.input_bfds
= NULL
;
204 link_info
.create_object_symbols_section
= NULL
;
205 link_info
.hash
= NULL
;
206 link_info
.keep_hash
= NULL
;
207 link_info
.notice_all
= false;
208 link_info
.notice_hash
= NULL
;
209 link_info
.wrap_hash
= NULL
;
211 ldfile_add_arch ("");
213 config
.make_executable
= true;
214 force_make_executable
= false;
215 config
.magic_demand_paged
= true;
216 config
.text_read_only
= true;
217 config
.make_executable
= true;
219 emulation
= get_emulation (argc
, argv
);
220 ldemul_choose_mode (emulation
);
221 default_target
= ldemul_choose_target ();
223 ldemul_before_parse ();
224 lang_has_input_file
= false;
225 parse_args (argc
, argv
);
227 ldemul_set_symbols ();
229 if (link_info
.relocateable
)
231 if (command_line
.relax
)
232 einfo ("%P%F: -relax and -r may not be used together\n");
233 if (link_info
.shared
)
234 einfo ("%P%F: -r and -shared may not be used together\n");
237 /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I
238 don't see how else this can be handled, since in this case we
239 must preserve all externally visible symbols. */
240 if (link_info
.relocateable
&& link_info
.strip
== strip_all
)
242 link_info
.strip
= strip_debugger
;
243 if (link_info
.discard
== discard_none
)
244 link_info
.discard
= discard_all
;
247 /* This essentially adds another -L directory so this must be done after
248 the -L's in argv have been processed. */
251 if (had_script
== false)
253 /* Read the emulation's appropriate default script. */
255 char *s
= ldemul_get_script (&isfile
);
258 ldfile_open_command_file (s
);
261 if (trace_file_tries
)
263 info_msg ("using internal linker script:\n");
264 info_msg ("==================================================\n");
266 info_msg ("\n==================================================\n");
271 parser_input
= input_script
;
278 if (lang_has_input_file
== false)
282 einfo ("%P%F: no input files\n");
287 info_msg ("%P: mode %s\n", emulation
);
290 ldemul_after_parse ();
293 if (config
.map_filename
)
295 if (strcmp (config
.map_filename
, "-") == 0)
297 config
.map_file
= stdout
;
301 config
.map_file
= fopen (config
.map_filename
, FOPEN_WT
);
302 if (config
.map_file
== (FILE *) NULL
)
304 bfd_set_error (bfd_error_system_call
);
305 einfo ("%P%F: cannot open map file %s: %E\n",
306 config
.map_filename
);
314 /* Print error messages for any missing symbols, for any warning
315 symbols, and possibly multiple definitions */
318 if (config
.text_read_only
)
320 /* Look for a text section and mark the readonly attribute in it */
321 asection
*found
= bfd_get_section_by_name (output_bfd
, ".text");
323 if (found
!= (asection
*) NULL
)
325 found
->flags
|= SEC_READONLY
;
329 if (link_info
.relocateable
)
330 output_bfd
->flags
&= ~EXEC_P
;
332 output_bfd
->flags
|= EXEC_P
;
336 if (config
.map_file
!= NULL
)
338 if (command_line
.cref
)
339 output_cref (config
.map_file
!= NULL
? config
.map_file
: stdout
);
340 if (nocrossref_list
!= NULL
)
341 check_nocrossrefs ();
343 /* Even if we're producing relocateable output, some non-fatal errors should
344 be reported in the exit status. (What non-fatal errors, if any, do we
345 want to ignore for relocateable output?) */
347 if (config
.make_executable
== false && force_make_executable
== false)
349 if (trace_files
== true)
351 einfo ("%P: link errors found, deleting executable `%s'\n",
355 /* The file will be removed by remove_output. */
361 if (! bfd_close (output_bfd
))
362 einfo ("%F%B: final close failed: %E\n", output_bfd
);
364 /* If the --force-exe-suffix is enabled, and we're making an
365 executable file and it doesn't end in .exe, copy it to one which does. */
367 if (! link_info
.relocateable
&& command_line
.force_exe_suffix
)
369 int len
= strlen (output_filename
);
371 || (strcasecmp (output_filename
+ len
- 4, ".exe") != 0
372 && strcasecmp (output_filename
+ len
- 4, ".dll") != 0))
376 const int bsize
= 4096;
377 char *buf
= xmalloc (bsize
);
379 char *dst_name
= xmalloc (len
+ 5);
380 strcpy (dst_name
, output_filename
);
381 strcat (dst_name
, ".exe");
382 src
= fopen (output_filename
, FOPEN_RB
);
383 dst
= fopen (dst_name
, FOPEN_WB
);
386 einfo ("%X%P: unable to open for source of copy `%s'\n", output_filename
);
388 einfo ("%X%P: unable to open for destination of copy `%s'\n", dst_name
);
389 while ((l
= fread (buf
, 1, bsize
, src
)) > 0)
391 int done
= fwrite (buf
, 1, l
, dst
);
394 einfo ("%P: Error writing file `%s'\n", dst_name
);
400 einfo ("%P: Error closing file `%s'\n", dst_name
);
408 END_PROGRESS (program_name
);
412 extern char **environ
;
414 char *lim
= (char *) sbrk (0);
416 long run_time
= get_run_time () - start_time
;
418 fprintf (stderr
, "%s: total time in link: %ld.%06ld\n",
419 program_name
, run_time
/ 1000000, run_time
% 1000000);
421 fprintf (stderr
, "%s: data size %ld\n", program_name
,
422 (long) (lim
- (char *) &environ
));
426 /* Prevent remove_output from doing anything, after a successful link. */
427 output_filename
= NULL
;
433 /* We need to find any explicitly given emulation in order to initialize the
434 state that's needed by the lex&yacc argument parser (parse_args). */
437 get_emulation (argc
, argv
)
444 emulation
= getenv (EMULATION_ENVIRON
);
445 if (emulation
== NULL
)
446 emulation
= DEFAULT_EMULATION
;
448 for (i
= 1; i
< argc
; i
++)
450 if (!strncmp (argv
[i
], "-m", 2))
452 if (argv
[i
][2] == '\0')
457 emulation
= argv
[i
+ 1];
462 einfo("%P%F: missing argument to -m\n");
465 else if (strcmp (argv
[i
], "-mips1") == 0
466 || strcmp (argv
[i
], "-mips2") == 0
467 || strcmp (argv
[i
], "-mips3") == 0
468 || strcmp (argv
[i
], "-mips4") == 0)
470 /* FIXME: The arguments -mips1, -mips2 and -mips3 are
471 passed to the linker by some MIPS compilers. They
472 generally tell the linker to use a slightly different
473 library path. Perhaps someday these should be
474 implemented as emulations; until then, we just ignore
475 the arguments and hope that nobody ever creates
476 emulations named ips1, ips2 or ips3. */
478 else if (strcmp (argv
[i
], "-m486") == 0)
480 /* FIXME: The argument -m486 is passed to the linker on
481 some Linux systems. Hope that nobody creates an
482 emulation named 486. */
487 emulation
= &argv
[i
][2];
495 /* If directory DIR contains an "ldscripts" subdirectory,
496 add DIR to the library search path and return true,
497 else return false. */
500 check_for_scripts_dir (dir
)
508 dirlen
= strlen (dir
);
509 /* sizeof counts the terminating NUL. */
510 buf
= (char *) xmalloc (dirlen
+ sizeof("/ldscripts"));
511 sprintf (buf
, "%s/ldscripts", dir
);
513 res
= stat (buf
, &s
) == 0 && S_ISDIR (s
.st_mode
);
516 ldfile_add_library_path (dir
, false);
520 /* Set the default directory for finding script files.
521 Libraries will be searched for here too, but that's ok.
522 We look for the "ldscripts" directory in:
524 SCRIPTDIR (passed from Makefile)
525 the dir where this program is (for using it from the build tree)
526 the dir where this program is/../lib (for installing the tool suite elsewhere) */
534 if (check_for_scripts_dir (SCRIPTDIR
))
535 return; /* We've been installed normally. */
537 /* Look for "ldscripts" in the dir where our binary is. */
538 end
= strrchr (program_name
, '/');
542 /* Don't look for ldscripts in the current directory. There is
543 too much potential for confusion. */
547 dirlen
= end
- program_name
;
548 /* Make a copy of program_name in dir.
549 Leave room for later "/../lib". */
550 dir
= (char *) xmalloc (dirlen
+ 8);
551 strncpy (dir
, program_name
, dirlen
);
554 if (check_for_scripts_dir (dir
))
555 return; /* Don't free dir. */
557 /* Look for "ldscripts" in <the dir where our binary is>/../lib. */
558 strcpy (dir
+ dirlen
, "/../lib");
559 if (check_for_scripts_dir (dir
))
562 free (dir
); /* Well, we tried. */
569 if (link_info
.notice_hash
== (struct bfd_hash_table
*) NULL
)
571 link_info
.notice_hash
= ((struct bfd_hash_table
*)
572 xmalloc (sizeof (struct bfd_hash_table
)));
573 if (! bfd_hash_table_init_n (link_info
.notice_hash
,
576 einfo ("%P%F: bfd_hash_table_init failed: %E\n");
579 if (bfd_hash_lookup (link_info
.notice_hash
, name
, true, true)
580 == (struct bfd_hash_entry
*) NULL
)
581 einfo ("%P%F: bfd_hash_lookup failed: %E\n");
584 /* Record a symbol to be wrapped, from the --wrap option. */
590 if (link_info
.wrap_hash
== NULL
)
592 link_info
.wrap_hash
= ((struct bfd_hash_table
*)
593 xmalloc (sizeof (struct bfd_hash_table
)));
594 if (! bfd_hash_table_init_n (link_info
.wrap_hash
,
597 einfo ("%P%F: bfd_hash_table_init failed: %E\n");
599 if (bfd_hash_lookup (link_info
.wrap_hash
, name
, true, true) == NULL
)
600 einfo ("%P%F: bfd_hash_lookup failed: %E\n");
603 /* Handle the -retain-symbols-file option. */
606 add_keepsyms_file (filename
)
607 const char *filename
;
614 if (link_info
.strip
== strip_some
)
615 einfo ("%X%P: error: duplicate retain-symbols-file\n");
617 file
= fopen (filename
, "r");
618 if (file
== (FILE *) NULL
)
620 bfd_set_error (bfd_error_system_call
);
621 einfo ("%X%P: %s: %E\n", filename
);
625 link_info
.keep_hash
= ((struct bfd_hash_table
*)
626 xmalloc (sizeof (struct bfd_hash_table
)));
627 if (! bfd_hash_table_init (link_info
.keep_hash
, bfd_hash_newfunc
))
628 einfo ("%P%F: bfd_hash_table_init failed: %E\n");
631 buf
= (char *) xmalloc (bufsize
);
643 while (! isspace (c
) && c
!= EOF
)
650 buf
= xrealloc (buf
, bufsize
);
657 if (bfd_hash_lookup (link_info
.keep_hash
, buf
, true, true)
658 == (struct bfd_hash_entry
*) NULL
)
659 einfo ("%P%F: bfd_hash_lookup for insertion failed: %E\n");
663 if (link_info
.strip
!= strip_none
)
664 einfo ("%P: `-retain-symbols-file' overrides `-s' and `-S'\n");
666 link_info
.strip
= strip_some
;
669 /* Callbacks from the BFD linker routines. */
671 /* This is called when BFD has decided to include an archive member in
676 add_archive_element (info
, abfd
, name
)
677 struct bfd_link_info
*info
;
681 lang_input_statement_type
*input
;
683 input
= ((lang_input_statement_type
*)
684 xmalloc (sizeof (lang_input_statement_type
)));
685 input
->filename
= abfd
->filename
;
686 input
->local_sym_name
= abfd
->filename
;
687 input
->the_bfd
= abfd
;
688 input
->asymbols
= NULL
;
690 input
->just_syms_flag
= false;
691 input
->loaded
= false;
692 input
->search_dirs_flag
= false;
694 /* FIXME: The following fields are not set: header.next,
695 header.type, closed, passive_position, symbol_count,
696 next_real_file, is_archive, target, real. This bit of code is
697 from the old decode_library_subfile function. I don't know
698 whether any of those fields matters. */
700 ldlang_add_file (input
);
702 if (config
.map_file
!= (FILE *) NULL
)
704 static boolean header_printed
;
705 struct bfd_link_hash_entry
*h
;
709 h
= bfd_link_hash_lookup (link_info
.hash
, name
, false, false, true);
721 case bfd_link_hash_defined
:
722 case bfd_link_hash_defweak
:
723 from
= h
->u
.def
.section
->owner
;
726 case bfd_link_hash_undefined
:
727 case bfd_link_hash_undefweak
:
728 from
= h
->u
.undef
.abfd
;
731 case bfd_link_hash_common
:
732 from
= h
->u
.c
.p
->section
->owner
;
737 if (! header_printed
)
741 sprintf (buf
, "%-29s %s\n\n", "Archive member included",
742 "because of file (symbol)");
744 header_printed
= true;
747 if (bfd_my_archive (abfd
) == NULL
)
749 minfo ("%s", bfd_get_filename (abfd
));
750 len
= strlen (bfd_get_filename (abfd
));
754 minfo ("%s(%s)", bfd_get_filename (bfd_my_archive (abfd
)),
755 bfd_get_filename (abfd
));
756 len
= (strlen (bfd_get_filename (bfd_my_archive (abfd
)))
757 + strlen (bfd_get_filename (abfd
))
775 minfo ("(%T)\n", h
->root
.string
);
777 minfo ("(%s)\n", name
);
780 if (trace_files
|| trace_file_tries
)
781 info_msg ("%I\n", input
);
786 /* This is called when BFD has discovered a symbol which is defined
791 multiple_definition (info
, name
, obfd
, osec
, oval
, nbfd
, nsec
, nval
)
792 struct bfd_link_info
*info
;
801 /* If either section has the output_section field set to
802 bfd_abs_section_ptr, it means that the section is being
803 discarded, and this is not really a multiple definition at all.
804 FIXME: It would be cleaner to somehow ignore symbols defined in
805 sections which are being discarded. */
806 if ((osec
->output_section
!= NULL
807 && ! bfd_is_abs_section (osec
)
808 && bfd_is_abs_section (osec
->output_section
))
809 || (nsec
->output_section
!= NULL
810 && ! bfd_is_abs_section (nsec
)
811 && bfd_is_abs_section (nsec
->output_section
)))
814 einfo ("%X%C: multiple definition of `%T'\n",
815 nbfd
, nsec
, nval
, name
);
816 if (obfd
!= (bfd
*) NULL
)
817 einfo ("%D: first defined here\n", obfd
, osec
, oval
);
821 /* This is called when there is a definition of a common symbol, or
822 when a common symbol is found for a symbol that is already defined,
823 or when two common symbols are found. We only do something if
824 -warn-common was used. */
828 multiple_common (info
, name
, obfd
, otype
, osize
, nbfd
, ntype
, nsize
)
829 struct bfd_link_info
*info
;
832 enum bfd_link_hash_type otype
;
835 enum bfd_link_hash_type ntype
;
838 if (! config
.warn_common
)
841 if (ntype
== bfd_link_hash_defined
842 || ntype
== bfd_link_hash_defweak
843 || ntype
== bfd_link_hash_indirect
)
845 ASSERT (otype
== bfd_link_hash_common
);
846 einfo ("%B: warning: definition of `%T' overriding common\n",
849 einfo ("%B: warning: common is here\n", obfd
);
851 else if (otype
== bfd_link_hash_defined
852 || otype
== bfd_link_hash_defweak
853 || otype
== bfd_link_hash_indirect
)
855 ASSERT (ntype
== bfd_link_hash_common
);
856 einfo ("%B: warning: common of `%T' overridden by definition\n",
859 einfo ("%B: warning: defined here\n", obfd
);
863 ASSERT (otype
== bfd_link_hash_common
&& ntype
== bfd_link_hash_common
);
866 einfo ("%B: warning: common of `%T' overridden by larger common\n",
869 einfo ("%B: warning: larger common is here\n", obfd
);
871 else if (nsize
> osize
)
873 einfo ("%B: warning: common of `%T' overriding smaller common\n",
876 einfo ("%B: warning: smaller common is here\n", obfd
);
880 einfo ("%B: warning: multiple common of `%T'\n", nbfd
, name
);
882 einfo ("%B: warning: previous common is here\n", obfd
);
889 /* This is called when BFD has discovered a set element. H is the
890 entry in the linker hash table for the set. SECTION and VALUE
891 represent a value which should be added to the set. */
895 add_to_set (info
, h
, reloc
, abfd
, section
, value
)
896 struct bfd_link_info
*info
;
897 struct bfd_link_hash_entry
*h
;
898 bfd_reloc_code_real_type reloc
;
903 if (config
.warn_constructors
)
904 einfo ("%P: warning: global constructor %s used\n",
907 if (! config
.build_constructors
)
910 ldctor_add_set_entry (h
, reloc
, (const char *) NULL
, section
, value
);
912 if (h
->type
== bfd_link_hash_new
)
914 h
->type
= bfd_link_hash_undefined
;
915 h
->u
.undef
.abfd
= abfd
;
916 /* We don't call bfd_link_add_undef to add this to the list of
917 undefined symbols because we are going to define it
924 /* This is called when BFD has discovered a constructor. This is only
925 called for some object file formats--those which do not handle
926 constructors in some more clever fashion. This is similar to
927 adding an element to a set, but less general. */
930 constructor_callback (info
, constructor
, name
, abfd
, section
, value
)
931 struct bfd_link_info
*info
;
939 struct bfd_link_hash_entry
*h
;
940 char set_name
[1 + sizeof "__CTOR_LIST__"];
942 if (config
.warn_constructors
)
943 einfo ("%P: warning: global constructor %s used\n", name
);
945 if (! config
.build_constructors
)
948 /* Ensure that BFD_RELOC_CTOR exists now, so that we can give a
949 useful error message. */
950 if (bfd_reloc_type_lookup (output_bfd
, BFD_RELOC_CTOR
) == NULL
951 && (link_info
.relocateable
952 || bfd_reloc_type_lookup (abfd
, BFD_RELOC_CTOR
) == NULL
))
953 einfo ("%P%F: BFD backend error: BFD_RELOC_CTOR unsupported\n");
956 if (bfd_get_symbol_leading_char (abfd
) != '\0')
957 *s
++ = bfd_get_symbol_leading_char (abfd
);
959 strcpy (s
, "__CTOR_LIST__");
961 strcpy (s
, "__DTOR_LIST__");
963 h
= bfd_link_hash_lookup (info
->hash
, set_name
, true, true, true);
964 if (h
== (struct bfd_link_hash_entry
*) NULL
)
965 einfo ("%P%F: bfd_link_hash_lookup failed: %E\n");
966 if (h
->type
== bfd_link_hash_new
)
968 h
->type
= bfd_link_hash_undefined
;
969 h
->u
.undef
.abfd
= abfd
;
970 /* We don't call bfd_link_add_undef to add this to the list of
971 undefined symbols because we are going to define it
975 ldctor_add_set_entry (h
, BFD_RELOC_CTOR
, name
, section
, value
);
979 /* A structure used by warning_callback to pass information through
980 bfd_map_over_sections. */
982 struct warning_callback_info
990 /* This is called when there is a reference to a warning symbol. */
994 warning_callback (info
, warning
, symbol
, abfd
, section
, address
)
995 struct bfd_link_info
*info
;
1002 /* This is a hack to support warn_multiple_gp. FIXME: This should
1003 have a cleaner interface, but what? */
1004 if (! config
.warn_multiple_gp
1005 && strcmp (warning
, "using multiple gp values") == 0)
1008 if (section
!= NULL
)
1009 einfo ("%C: %s\n", abfd
, section
, address
, warning
);
1010 else if (abfd
== NULL
)
1011 einfo ("%P: %s\n", warning
);
1012 else if (symbol
== NULL
)
1013 einfo ("%B: %s\n", abfd
, warning
);
1016 lang_input_statement_type
*entry
;
1018 struct warning_callback_info info
;
1020 /* Look through the relocs to see if we can find a plausible
1023 entry
= (lang_input_statement_type
*) abfd
->usrdata
;
1024 if (entry
!= NULL
&& entry
->asymbols
!= NULL
)
1025 asymbols
= entry
->asymbols
;
1031 symsize
= bfd_get_symtab_upper_bound (abfd
);
1033 einfo ("%B%F: could not read symbols: %E\n", abfd
);
1034 asymbols
= (asymbol
**) xmalloc (symsize
);
1035 symbol_count
= bfd_canonicalize_symtab (abfd
, asymbols
);
1036 if (symbol_count
< 0)
1037 einfo ("%B%F: could not read symbols: %E\n", abfd
);
1040 entry
->asymbols
= asymbols
;
1041 entry
->symbol_count
= symbol_count
;
1046 info
.warning
= warning
;
1047 info
.symbol
= symbol
;
1048 info
.asymbols
= asymbols
;
1049 bfd_map_over_sections (abfd
, warning_find_reloc
, (PTR
) &info
);
1052 einfo ("%B: %s\n", abfd
, warning
);
1061 /* This is called by warning_callback for each section. It checks the
1062 relocs of the section to see if it can find a reference to the
1063 symbol which triggered the warning. If it can, it uses the reloc
1064 to give an error message with a file and line number. */
1067 warning_find_reloc (abfd
, sec
, iarg
)
1072 struct warning_callback_info
*info
= (struct warning_callback_info
*) iarg
;
1076 arelent
**p
, **pend
;
1081 relsize
= bfd_get_reloc_upper_bound (abfd
, sec
);
1083 einfo ("%B%F: could not read relocs: %E\n", abfd
);
1087 relpp
= (arelent
**) xmalloc (relsize
);
1088 relcount
= bfd_canonicalize_reloc (abfd
, sec
, relpp
, info
->asymbols
);
1090 einfo ("%B%F: could not read relocs: %E\n", abfd
);
1093 pend
= p
+ relcount
;
1094 for (; p
< pend
&& *p
!= NULL
; p
++)
1098 if (q
->sym_ptr_ptr
!= NULL
1099 && *q
->sym_ptr_ptr
!= NULL
1100 && strcmp (bfd_asymbol_name (*q
->sym_ptr_ptr
), info
->symbol
) == 0)
1102 /* We found a reloc for the symbol we are looking for. */
1103 einfo ("%C: %s\n", abfd
, sec
, q
->address
, info
->warning
);
1112 /* This is called when an undefined symbol is found. */
1116 undefined_symbol (info
, name
, abfd
, section
, address
)
1117 struct bfd_link_info
*info
;
1123 static char *error_name
;
1124 static unsigned int error_count
;
1126 #define MAX_ERRORS_IN_A_ROW 5
1128 if (config
.warn_once
)
1130 static struct bfd_hash_table
*hash
;
1132 /* Only warn once about a particular undefined symbol. */
1136 hash
= ((struct bfd_hash_table
*)
1137 xmalloc (sizeof (struct bfd_hash_table
)));
1138 if (! bfd_hash_table_init (hash
, bfd_hash_newfunc
))
1139 einfo ("%F%P: bfd_hash_table_init failed: %E\n");
1142 if (bfd_hash_lookup (hash
, name
, false, false) != NULL
)
1145 if (bfd_hash_lookup (hash
, name
, true, true) == NULL
)
1146 einfo ("%F%P: bfd_hash_lookup failed: %E\n");
1149 /* We never print more than a reasonable number of errors in a row
1150 for a single symbol. */
1151 if (error_name
!= (char *) NULL
1152 && strcmp (name
, error_name
) == 0)
1157 if (error_name
!= (char *) NULL
)
1159 error_name
= buystring (name
);
1162 if (section
!= NULL
)
1164 if (error_count
< MAX_ERRORS_IN_A_ROW
)
1165 einfo ("%X%C: undefined reference to `%T'\n",
1166 abfd
, section
, address
, name
);
1167 else if (error_count
== MAX_ERRORS_IN_A_ROW
)
1168 einfo ("%D: more undefined references to `%T' follow\n",
1169 abfd
, section
, address
, name
);
1173 if (error_count
< MAX_ERRORS_IN_A_ROW
)
1174 einfo ("%X%B: undefined reference to `%T'\n",
1176 else if (error_count
== MAX_ERRORS_IN_A_ROW
)
1177 einfo ("%B: more undefined references to `%T' follow\n",
1184 /* This is called when a reloc overflows. */
1188 reloc_overflow (info
, name
, reloc_name
, addend
, abfd
, section
, address
)
1189 struct bfd_link_info
*info
;
1191 const char *reloc_name
;
1197 if (abfd
== (bfd
*) NULL
)
1198 einfo ("%P%X: generated");
1200 einfo ("%X%C:", abfd
, section
, address
);
1201 einfo (" relocation truncated to fit: %s %T", reloc_name
, name
);
1203 einfo ("+%v", addend
);
1208 /* This is called when a dangerous relocation is made. */
1212 reloc_dangerous (info
, message
, abfd
, section
, address
)
1213 struct bfd_link_info
*info
;
1214 const char *message
;
1219 if (abfd
== (bfd
*) NULL
)
1220 einfo ("%P%X: generated");
1222 einfo ("%X%C:", abfd
, section
, address
);
1223 einfo ("dangerous relocation: %s\n", message
);
1227 /* This is called when a reloc is being generated attached to a symbol
1228 that is not being output. */
1232 unattached_reloc (info
, name
, abfd
, section
, address
)
1233 struct bfd_link_info
*info
;
1239 if (abfd
== (bfd
*) NULL
)
1240 einfo ("%P%X: generated");
1242 einfo ("%X%C:", abfd
, section
, address
);
1243 einfo (" reloc refers to symbol `%T' which is not being output\n", name
);
1247 /* This is called if link_info.notice_all is set, or when a symbol in
1248 link_info.notice_hash is found. Symbols are put in notice_hash
1249 using the -y option. */
1252 notice (info
, name
, abfd
, section
, value
)
1253 struct bfd_link_info
*info
;
1259 if (! info
->notice_all
1260 || (info
->notice_hash
!= NULL
1261 && bfd_hash_lookup (info
->notice_hash
, name
, false, false) != NULL
))
1262 einfo ("%B: %s %s\n", abfd
,
1263 bfd_is_und_section (section
) ? "reference to" : "definition of",
1266 if (command_line
.cref
|| nocrossref_list
!= NULL
)
1267 add_cref (name
, abfd
, section
, value
);