fsf address update, but not in COPYING files
[deliverable/binutils-gdb.git] / ld / ldmain.c
... / ...
CommitLineData
1/* Main program of GNU linker.
2 Copyright (C) 1991, 92, 93, 94 Free Software Foundation, Inc.
3 Written by Steve Chamberlain steve@cygnus.com
4
5This file is part of GLD, the Gnu Linker.
6
7GLD is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GLD is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GLD; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21
22#include "bfd.h"
23#include "sysdep.h"
24#include <stdio.h>
25#include "libiberty.h"
26#include "progress.h"
27#include "bfdlink.h"
28
29#include "config.h"
30#include "ld.h"
31#include "ldmain.h"
32#include "ldmisc.h"
33#include "ldwrite.h"
34#include "ldgram.h"
35#include "ldexp.h"
36#include "ldlang.h"
37#include "ldemul.h"
38#include "ldlex.h"
39#include "ldfile.h"
40#include "ldctor.h"
41
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)
45#endif
46
47#include <string.h>
48
49/* Use sbrk() except on specific OS types */
50#if !defined(__amigados__) && !defined(WINDOWS_NT)
51#define HAVE_SBRK
52#endif
53
54static char *get_emulation PARAMS ((int, char **));
55static void set_scripts_dir PARAMS ((void));
56
57/* EXPORTS */
58
59char *default_target;
60const char *output_filename = "a.out";
61
62/* Name this program was invoked by. */
63char *program_name;
64
65/* The file that we're creating */
66bfd *output_bfd = 0;
67
68/* Set by -G argument, for MIPS ECOFF target. */
69int g_switch_value = 8;
70
71/* Nonzero means print names of input files as processed. */
72boolean trace_files;
73
74/* Nonzero means same, but note open failures, too. */
75boolean trace_file_tries;
76
77/* Nonzero means version number was printed, so exit successfully
78 instead of complaining if no input files are given. */
79boolean version_printed;
80
81/* Nonzero means link in every member of an archive. */
82boolean whole_archive;
83
84args_type command_line;
85
86ld_config_type config;
87
88static boolean check_for_scripts_dir PARAMS ((char *dir));
89static boolean add_archive_element PARAMS ((struct bfd_link_info *, bfd *,
90 const char *));
91static boolean multiple_definition PARAMS ((struct bfd_link_info *,
92 const char *,
93 bfd *, asection *, bfd_vma,
94 bfd *, asection *, bfd_vma));
95static boolean multiple_common PARAMS ((struct bfd_link_info *,
96 const char *, bfd *,
97 enum bfd_link_hash_type, bfd_vma,
98 bfd *, enum bfd_link_hash_type,
99 bfd_vma));
100static boolean add_to_set PARAMS ((struct bfd_link_info *,
101 struct bfd_link_hash_entry *,
102 bfd_reloc_code_real_type,
103 bfd *, asection *, bfd_vma));
104static boolean constructor_callback PARAMS ((struct bfd_link_info *,
105 boolean constructor,
106 const char *name,
107 bfd *, asection *, bfd_vma));
108static boolean warning_callback PARAMS ((struct bfd_link_info *,
109 const char *));
110static boolean undefined_symbol PARAMS ((struct bfd_link_info *,
111 const char *, bfd *,
112 asection *, bfd_vma));
113static boolean reloc_overflow PARAMS ((struct bfd_link_info *, const char *,
114 const char *, bfd_vma,
115 bfd *, asection *, bfd_vma));
116static boolean reloc_dangerous PARAMS ((struct bfd_link_info *, const char *,
117 bfd *, asection *, bfd_vma));
118static boolean unattached_reloc PARAMS ((struct bfd_link_info *,
119 const char *, bfd *, asection *,
120 bfd_vma));
121static boolean notice_ysym PARAMS ((struct bfd_link_info *, const char *,
122 bfd *, asection *, bfd_vma));
123
124static struct bfd_link_callbacks link_callbacks =
125{
126 add_archive_element,
127 multiple_definition,
128 multiple_common,
129 add_to_set,
130 constructor_callback,
131 warning_callback,
132 undefined_symbol,
133 reloc_overflow,
134 reloc_dangerous,
135 unattached_reloc,
136 notice_ysym
137};
138
139struct bfd_link_info link_info;
140\f
141static void
142remove_output ()
143{
144 if (output_filename)
145 {
146 if (output_bfd && output_bfd->iostream)
147 fclose((FILE *)(output_bfd->iostream));
148 if (delete_output_file_on_failure)
149 unlink (output_filename);
150 }
151}
152
153int
154main (argc, argv)
155 int argc;
156 char **argv;
157{
158 char *emulation;
159 long start_time = get_run_time ();
160
161 program_name = argv[0];
162 xmalloc_set_program_name (program_name);
163
164 START_PROGRESS (program_name, 0);
165
166 bfd_init ();
167
168 xatexit (remove_output);
169
170 /* Initialize the data about options. */
171 trace_files = trace_file_tries = version_printed = false;
172 whole_archive = false;
173 config.traditional_format = false;
174 config.build_constructors = true;
175 config.dynamic_link = false;
176 command_line.force_common_definition = false;
177 command_line.interpreter = NULL;
178 command_line.rpath = NULL;
179
180 link_info.callbacks = &link_callbacks;
181 link_info.relocateable = false;
182 link_info.shared = false;
183 link_info.strip = strip_none;
184 link_info.discard = discard_none;
185 link_info.lprefix_len = 1;
186 link_info.lprefix = "L";
187 link_info.keep_memory = true;
188 link_info.input_bfds = NULL;
189 link_info.create_object_symbols_section = NULL;
190 link_info.hash = NULL;
191 link_info.keep_hash = NULL;
192 link_info.notice_hash = NULL;
193 link_info.subsystem = console;
194 link_info.stack_heap_parameters.stack_defined = false;
195 link_info.stack_heap_parameters.heap_defined = false;
196 link_info.stack_heap_parameters.stack_reserve = 0;
197 link_info.stack_heap_parameters.stack_commit = 0;
198 link_info.stack_heap_parameters.heap_reserve = 0;
199 link_info.stack_heap_parameters.heap_commit = 0;
200
201
202 ldfile_add_arch ("");
203
204 config.make_executable = true;
205 force_make_executable = false;
206 config.magic_demand_paged = true;
207 config.text_read_only = true;
208 config.make_executable = true;
209
210 emulation = get_emulation (argc, argv);
211 ldemul_choose_mode (emulation);
212 default_target = ldemul_choose_target ();
213 lang_init ();
214 ldemul_before_parse ();
215 lang_has_input_file = false;
216 parse_args (argc, argv);
217
218 if (link_info.relocateable)
219 {
220 if (command_line.relax)
221 einfo ("%P%F: -relax and -r may not be used together\n");
222 if (config.dynamic_link)
223 einfo ("%P%F: -r and -call_shared may not be used together\n");
224 if (link_info.shared)
225 einfo ("%P%F: -r and -shared may not be used together\n");
226 }
227
228 /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I
229 don't see how else this can be handled, since in this case we
230 must preserve all externally visible symbols. */
231 if (link_info.relocateable && link_info.strip == strip_all)
232 {
233 link_info.strip = strip_debugger;
234 if (link_info.discard == discard_none)
235 link_info.discard = discard_all;
236 }
237
238 /* This essentially adds another -L directory so this must be done after
239 the -L's in argv have been processed. */
240 set_scripts_dir ();
241
242 if (had_script == false)
243 {
244 /* Read the emulation's appropriate default script. */
245 int isfile;
246 char *s = ldemul_get_script (&isfile);
247
248 if (isfile)
249 ldfile_open_command_file (s);
250 else
251 {
252 if (trace_file_tries)
253 {
254 info_msg ("using internal linker script:\n");
255 info_msg ("==================================================\n");
256 info_msg (s);
257 info_msg ("\n==================================================\n");
258 }
259 lex_redirect (s);
260 }
261 parser_input = input_script;
262 yyparse ();
263 }
264
265 lang_final ();
266
267 if (lang_has_input_file == false)
268 {
269 if (version_printed)
270 xexit (0);
271 einfo ("%P%F: no input files\n");
272 }
273
274 if (trace_files)
275 {
276 info_msg ("%P: mode %s\n", emulation);
277 }
278
279 ldemul_after_parse ();
280
281
282 if (config.map_filename)
283 {
284 if (strcmp (config.map_filename, "-") == 0)
285 {
286 config.map_file = stdout;
287 }
288 else
289 {
290 config.map_file = fopen (config.map_filename, FOPEN_WT);
291 if (config.map_file == (FILE *) NULL)
292 {
293 bfd_set_error (bfd_error_system_call);
294 einfo ("%P%F: cannot open map file %s: %E\n",
295 config.map_filename);
296 }
297 }
298 }
299
300
301 lang_process ();
302
303 /* Print error messages for any missing symbols, for any warning
304 symbols, and possibly multiple definitions */
305
306
307 if (config.text_read_only)
308 {
309 /* Look for a text section and mark the readonly attribute in it */
310 asection *found = bfd_get_section_by_name (output_bfd, ".text");
311
312 if (found != (asection *) NULL)
313 {
314 found->flags |= SEC_READONLY;
315 }
316 }
317
318 if (link_info.relocateable)
319 output_bfd->flags &= ~EXEC_P;
320 else
321 output_bfd->flags |= EXEC_P;
322
323 ldwrite ();
324
325 /* Even if we're producing relocateable output, some non-fatal errors should
326 be reported in the exit status. (What non-fatal errors, if any, do we
327 want to ignore for relocateable output?) */
328
329 if (config.make_executable == false && force_make_executable == false)
330 {
331 if (trace_files == true)
332 {
333 einfo ("%P: link errors found, deleting executable `%s'\n",
334 output_filename);
335 }
336
337 if (output_bfd->iostream)
338 fclose ((FILE *) (output_bfd->iostream));
339
340 unlink (output_filename);
341 xexit (1);
342 }
343 else
344 {
345 if (! bfd_close (output_bfd))
346 einfo ("%F%B: final close failed: %E\n", output_bfd);
347 }
348
349 END_PROGRESS (program_name);
350
351 if (config.stats)
352 {
353 extern char **environ;
354#ifdef HAVE_SBRK
355 char *lim = (char *) sbrk (0);
356#endif
357 long run_time = get_run_time () - start_time;
358
359 fprintf (stderr, "%s: total time in link: %ld.%06ld\n",
360 program_name, run_time / 1000000, run_time % 1000000);
361#ifdef HAVE_SBRK
362 fprintf (stderr, "%s: data size %ld\n", program_name,
363 (long) (lim - (char *) &environ));
364#endif
365 }
366
367 /* Prevent remove_output from doing anything, after a successful link. */
368 output_filename = NULL;
369
370 xexit (0);
371 return 0;
372}
373
374/* We need to find any explicitly given emulation in order to initialize the
375 state that's needed by the lex&yacc argument parser (parse_args). */
376
377static char *
378get_emulation (argc, argv)
379 int argc;
380 char **argv;
381{
382 char *emulation;
383 int i;
384
385 emulation = (char *) getenv (EMULATION_ENVIRON);
386 if (emulation == NULL)
387 emulation = DEFAULT_EMULATION;
388
389 for (i = 1; i < argc; i++)
390 {
391 if (!strncmp (argv[i], "-m", 2))
392 {
393 if (argv[i][2] == '\0')
394 {
395 /* -m EMUL */
396 if (i < argc - 1)
397 {
398 emulation = argv[i + 1];
399 i++;
400 }
401 else
402 {
403 einfo("%P%F: missing argument to -m\n");
404 }
405 }
406 else if (strcmp (argv[i], "-mips1") == 0
407 || strcmp (argv[i], "-mips2") == 0
408 || strcmp (argv[i], "-mips3") == 0)
409 {
410 /* FIXME: The arguments -mips1, -mips2 and -mips3 are
411 passed to the linker by some MIPS compilers. They
412 generally tell the linker to use a slightly different
413 library path. Perhaps someday these should be
414 implemented as emulations; until then, we just ignore
415 the arguments and hope that nobody ever creates
416 emulations named ips1, ips2 or ips3. */
417 }
418 else if (strcmp (argv[i], "-m486") == 0)
419 {
420 /* FIXME: The argument -m486 is passed to the linker on
421 some Linux systems. Hope that nobody creates an
422 emulation named 486. */
423 }
424 else
425 {
426 /* -mEMUL */
427 emulation = &argv[i][2];
428 }
429 }
430 }
431
432 return emulation;
433}
434
435/* If directory DIR contains an "ldscripts" subdirectory,
436 add DIR to the library search path and return true,
437 else return false. */
438
439static boolean
440check_for_scripts_dir (dir)
441 char *dir;
442{
443 size_t dirlen;
444 char *buf;
445 struct stat s;
446 boolean res;
447
448 dirlen = strlen (dir);
449 /* sizeof counts the terminating NUL. */
450 buf = (char *) xmalloc (dirlen + sizeof("/ldscripts"));
451 sprintf (buf, "%s/ldscripts", dir);
452
453 res = stat (buf, &s) == 0 && S_ISDIR (s.st_mode);
454 free (buf);
455 if (res)
456 ldfile_add_library_path (dir, false);
457 return res;
458}
459
460/* Set the default directory for finding script files.
461 Libraries will be searched for here too, but that's ok.
462 We look for the "ldscripts" directory in:
463
464 SCRIPTDIR (passed from Makefile)
465 the dir where this program is (for using it from the build tree)
466 the dir where this program is/../lib (for installing the tool suite elsewhere) */
467
468static void
469set_scripts_dir ()
470{
471 char *end, *dir;
472 size_t dirlen;
473
474 if (check_for_scripts_dir (SCRIPTDIR))
475 return; /* We've been installed normally. */
476
477 /* Look for "ldscripts" in the dir where our binary is. */
478 end = strrchr (program_name, '/');
479 if (end)
480 {
481 dirlen = end - program_name;
482 /* Make a copy of program_name in dir.
483 Leave room for later "/../lib". */
484 dir = (char *) xmalloc (dirlen + 8);
485 strncpy (dir, program_name, dirlen);
486 dir[dirlen] = '\0';
487 }
488 else
489 {
490 dirlen = 1;
491 dir = (char *) xmalloc (dirlen + 8);
492 strcpy (dir, ".");
493 }
494
495 if (check_for_scripts_dir (dir))
496 return; /* Don't free dir. */
497
498 /* Look for "ldscripts" in <the dir where our binary is>/../lib. */
499 strcpy (dir + dirlen, "/../lib");
500 if (check_for_scripts_dir (dir))
501 return;
502
503 free (dir); /* Well, we tried. */
504}
505
506void
507add_ysym (name)
508 const char *name;
509{
510 if (link_info.notice_hash == (struct bfd_hash_table *) NULL)
511 {
512 link_info.notice_hash = ((struct bfd_hash_table *)
513 xmalloc (sizeof (struct bfd_hash_table)));
514 if (! bfd_hash_table_init_n (link_info.notice_hash,
515 bfd_hash_newfunc,
516 61))
517 einfo ("%P%F: bfd_hash_table_init failed: %E\n");
518 }
519
520 if (bfd_hash_lookup (link_info.notice_hash, name, true, true)
521 == (struct bfd_hash_entry *) NULL)
522 einfo ("%P%F: bfd_hash_lookup failed: %E\n");
523}
524
525/* Handle the -retain-symbols-file option. */
526
527void
528add_keepsyms_file (filename)
529 const char *filename;
530{
531 FILE *file;
532 char *buf;
533 size_t bufsize;
534 int c;
535
536 if (link_info.strip == strip_some)
537 einfo ("%X%P: error: duplicate retain-symbols-file\n");
538
539 file = fopen (filename, "r");
540 if (file == (FILE *) NULL)
541 {
542 bfd_set_error (bfd_error_system_call);
543 einfo ("%X%P: %s: %E", filename);
544 return;
545 }
546
547 link_info.keep_hash = ((struct bfd_hash_table *)
548 xmalloc (sizeof (struct bfd_hash_table)));
549 if (! bfd_hash_table_init (link_info.keep_hash, bfd_hash_newfunc))
550 einfo ("%P%F: bfd_hash_table_init failed: %E\n");
551
552 bufsize = 100;
553 buf = (char *) xmalloc (bufsize);
554
555 c = getc (file);
556 while (c != EOF)
557 {
558 while (isspace (c))
559 c = getc (file);
560
561 if (c != EOF)
562 {
563 size_t len = 0;
564
565 while (! isspace (c) && c != EOF)
566 {
567 buf[len] = c;
568 ++len;
569 if (len >= bufsize)
570 {
571 bufsize *= 2;
572 buf = xrealloc (buf, bufsize);
573 }
574 c = getc (file);
575 }
576
577 buf[len] = '\0';
578
579 if (bfd_hash_lookup (link_info.keep_hash, buf, true, true)
580 == (struct bfd_hash_entry *) NULL)
581 einfo ("%P%F: bfd_hash_lookup for insertion failed: %E");
582 }
583 }
584
585 if (link_info.strip != strip_none)
586 einfo ("%P: `-retain-symbols-file' overrides `-s' and `-S'\n");
587
588 link_info.strip = strip_some;
589}
590\f
591/* Callbacks from the BFD linker routines. */
592
593/* This is called when BFD has decided to include an archive member in
594 a link. */
595
596/*ARGSUSED*/
597static boolean
598add_archive_element (info, abfd, name)
599 struct bfd_link_info *info;
600 bfd *abfd;
601 const char *name;
602{
603 lang_input_statement_type *input;
604
605 input = ((lang_input_statement_type *)
606 xmalloc ((bfd_size_type) sizeof (lang_input_statement_type)));
607 input->filename = abfd->filename;
608 input->local_sym_name = abfd->filename;
609 input->the_bfd = abfd;
610 input->asymbols = NULL;
611 input->next = NULL;
612 input->just_syms_flag = false;
613 input->loaded = false;
614 input->search_dirs_flag = false;
615
616 /* FIXME: The following fields are not set: header.next,
617 header.type, closed, passive_position, symbol_count,
618 next_real_file, is_archive, target, real, common_section,
619 common_output_section, complained. This bit of code is from the
620 old decode_library_subfile function. I don't know whether any of
621 those fields matters. */
622
623 ldlang_add_file (input);
624
625 if (config.map_file != (FILE *) NULL)
626 minfo ("%s needed due to %T\n", abfd->filename, name);
627
628 if (trace_files || trace_file_tries)
629 info_msg ("%I\n", input);
630
631 return true;
632}
633
634/* This is called when BFD has discovered a symbol which is defined
635 multiple times. */
636
637/*ARGSUSED*/
638static boolean
639multiple_definition (info, name, obfd, osec, oval, nbfd, nsec, nval)
640 struct bfd_link_info *info;
641 const char *name;
642 bfd *obfd;
643 asection *osec;
644 bfd_vma oval;
645 bfd *nbfd;
646 asection *nsec;
647 bfd_vma nval;
648{
649 einfo ("%X%C: multiple definition of `%T'\n",
650 nbfd, nsec, nval, name);
651 if (obfd != (bfd *) NULL)
652 einfo ("%D: first defined here\n", obfd, osec, oval);
653 return true;
654}
655
656/* This is called when there is a definition of a common symbol, or
657 when a common symbol is found for a symbol that is already defined,
658 or when two common symbols are found. We only do something if
659 -warn-common was used. */
660
661/*ARGSUSED*/
662static boolean
663multiple_common (info, name, obfd, otype, osize, nbfd, ntype, nsize)
664 struct bfd_link_info *info;
665 const char *name;
666 bfd *obfd;
667 enum bfd_link_hash_type otype;
668 bfd_vma osize;
669 bfd *nbfd;
670 enum bfd_link_hash_type ntype;
671 bfd_vma nsize;
672{
673 if (! config.warn_common)
674 return true;
675
676 if (ntype == bfd_link_hash_defined
677 || ntype == bfd_link_hash_defweak
678 || ntype == bfd_link_hash_indirect)
679 {
680 ASSERT (otype == bfd_link_hash_common);
681 einfo ("%B: warning: definition of `%T' overriding common\n",
682 nbfd, name);
683 if (obfd != NULL)
684 einfo ("%B: warning: common is here\n", obfd);
685 }
686 else if (otype == bfd_link_hash_defined
687 || otype == bfd_link_hash_defweak
688 || otype == bfd_link_hash_indirect)
689 {
690 ASSERT (ntype == bfd_link_hash_common);
691 einfo ("%B: warning: common of `%T' overridden by definition\n",
692 nbfd, name);
693 if (obfd != NULL)
694 einfo ("%B: warning: defined here\n", obfd);
695 }
696 else
697 {
698 ASSERT (otype == bfd_link_hash_common && ntype == bfd_link_hash_common);
699 if (osize > nsize)
700 {
701 einfo ("%B: warning: common of `%T' overridden by larger common\n",
702 nbfd, name);
703 if (obfd != NULL)
704 einfo ("%B: warning: larger common is here\n", obfd);
705 }
706 else if (nsize > osize)
707 {
708 einfo ("%B: warning: common of `%T' overriding smaller common\n",
709 nbfd, name);
710 if (obfd != NULL)
711 einfo ("%B: warning: smaller common is here\n", obfd);
712 }
713 else
714 {
715 einfo ("%B: warning: multiple common of `%T'\n", nbfd, name);
716 if (obfd != NULL)
717 einfo ("%B: warning: previous common is here\n", obfd);
718 }
719 }
720
721 return true;
722}
723
724/* This is called when BFD has discovered a set element. H is the
725 entry in the linker hash table for the set. SECTION and VALUE
726 represent a value which should be added to the set. */
727
728/*ARGSUSED*/
729static boolean
730add_to_set (info, h, reloc, abfd, section, value)
731 struct bfd_link_info *info;
732 struct bfd_link_hash_entry *h;
733 bfd_reloc_code_real_type reloc;
734 bfd *abfd;
735 asection *section;
736 bfd_vma value;
737{
738 if (! config.build_constructors)
739 return true;
740
741 ldctor_add_set_entry (h, reloc, section, value);
742
743 if (h->type == bfd_link_hash_new)
744 {
745 h->type = bfd_link_hash_undefined;
746 h->u.undef.abfd = abfd;
747 /* We don't call bfd_link_add_undef to add this to the list of
748 undefined symbols because we are going to define it
749 ourselves. */
750 }
751
752 return true;
753}
754
755/* This is called when BFD has discovered a constructor. This is only
756 called for some object file formats--those which do not handle
757 constructors in some more clever fashion. This is similar to
758 adding an element to a set, but less general. */
759
760static boolean
761constructor_callback (info, constructor, name, abfd, section, value)
762 struct bfd_link_info *info;
763 boolean constructor;
764 const char *name;
765 bfd *abfd;
766 asection *section;
767 bfd_vma value;
768{
769 char *set_name;
770 char *s;
771 struct bfd_link_hash_entry *h;
772
773 if (! config.build_constructors)
774 return true;
775
776 /* Ensure that BFD_RELOC_CTOR exists now, so that we can give a
777 useful error message. */
778 if (bfd_reloc_type_lookup (output_bfd, BFD_RELOC_CTOR) == NULL)
779 einfo ("%P%F: BFD backend error: BFD_RELOC_CTOR unsupported");
780
781 set_name = (char *) alloca (1 + sizeof "__CTOR_LIST__");
782 s = set_name;
783 if (bfd_get_symbol_leading_char (abfd) != '\0')
784 *s++ = bfd_get_symbol_leading_char (abfd);
785 if (constructor)
786 strcpy (s, "__CTOR_LIST__");
787 else
788 strcpy (s, "__DTOR_LIST__");
789
790 if (config.map_file != (FILE *) NULL)
791 fprintf (config.map_file,
792 "Adding %s to constructor/destructor set %s\n", name, set_name);
793
794 h = bfd_link_hash_lookup (info->hash, set_name, true, true, true);
795 if (h == (struct bfd_link_hash_entry *) NULL)
796 einfo ("%P%F: bfd_link_hash_lookup failed: %E");
797 if (h->type == bfd_link_hash_new)
798 {
799 h->type = bfd_link_hash_undefined;
800 h->u.undef.abfd = abfd;
801 /* We don't call bfd_link_add_undef to add this to the list of
802 undefined symbols because we are going to define it
803 ourselves. */
804 }
805
806 ldctor_add_set_entry (h, BFD_RELOC_CTOR, section, value);
807 return true;
808}
809
810/* This is called when there is a reference to a warning symbol. */
811
812/*ARGSUSED*/
813static boolean
814warning_callback (info, warning)
815 struct bfd_link_info *info;
816 const char *warning;
817{
818 einfo ("%P: %s\n", warning);
819 return true;
820}
821
822/* This is called when an undefined symbol is found. */
823
824/*ARGSUSED*/
825static boolean
826undefined_symbol (info, name, abfd, section, address)
827 struct bfd_link_info *info;
828 const char *name;
829 bfd *abfd;
830 asection *section;
831 bfd_vma address;
832{
833 static char *error_name;
834 static unsigned int error_count;
835
836#define MAX_ERRORS_IN_A_ROW 5
837
838 if (config.warn_once)
839 {
840 static struct bfd_hash_table *hash;
841
842 /* Only warn once about a particular undefined symbol. */
843
844 if (hash == NULL)
845 {
846 hash = ((struct bfd_hash_table *)
847 xmalloc (sizeof (struct bfd_hash_table)));
848 if (! bfd_hash_table_init (hash, bfd_hash_newfunc))
849 einfo ("%F%P: bfd_hash_table_init failed: %E\n");
850 }
851
852 if (bfd_hash_lookup (hash, name, false, false) != NULL)
853 return true;
854
855 if (bfd_hash_lookup (hash, name, true, true) == NULL)
856 einfo ("%F%P: bfd_hash_lookup failed: %E\n");
857 }
858
859 /* We never print more than a reasonable number of errors in a row
860 for a single symbol. */
861 if (error_name != (char *) NULL
862 && strcmp (name, error_name) == 0)
863 ++error_count;
864 else
865 {
866 error_count = 0;
867 if (error_name != (char *) NULL)
868 free (error_name);
869 error_name = buystring (name);
870 }
871
872 if (section != NULL)
873 {
874 if (error_count < MAX_ERRORS_IN_A_ROW)
875 einfo ("%X%C: undefined reference to `%T'\n",
876 abfd, section, address, name);
877 else if (error_count == MAX_ERRORS_IN_A_ROW)
878 einfo ("%D: more undefined references to `%T' follow\n",
879 abfd, section, address, name);
880 }
881 else
882 {
883 if (error_count < MAX_ERRORS_IN_A_ROW)
884 einfo ("%X%B: undefined reference to `%T'\n",
885 abfd, name);
886 else if (error_count == MAX_ERRORS_IN_A_ROW)
887 einfo ("%B: more undefined references to `%T' follow\n",
888 abfd, name);
889 }
890
891 return true;
892}
893
894/* This is called when a reloc overflows. */
895
896/*ARGSUSED*/
897static boolean
898reloc_overflow (info, name, reloc_name, addend, abfd, section, address)
899 struct bfd_link_info *info;
900 const char *name;
901 const char *reloc_name;
902 bfd_vma addend;
903 bfd *abfd;
904 asection *section;
905 bfd_vma address;
906{
907 if (abfd == (bfd *) NULL)
908 einfo ("%P%X: generated");
909 else
910 einfo ("%X%C:", abfd, section, address);
911 einfo (" relocation truncated to fit: %s %T", reloc_name, name);
912 if (addend != 0)
913 einfo ("+%v", addend);
914 einfo ("\n");
915 return true;
916}
917
918/* This is called when a dangerous relocation is made. */
919
920/*ARGSUSED*/
921static boolean
922reloc_dangerous (info, message, abfd, section, address)
923 struct bfd_link_info *info;
924 const char *message;
925 bfd *abfd;
926 asection *section;
927 bfd_vma address;
928{
929 if (abfd == (bfd *) NULL)
930 einfo ("%P%X: generated");
931 else
932 einfo ("%X%C:", abfd, section, address);
933 einfo ("dangerous relocation: %s\n", message);
934 return true;
935}
936
937/* This is called when a reloc is being generated attached to a symbol
938 that is not being output. */
939
940/*ARGSUSED*/
941static boolean
942unattached_reloc (info, name, abfd, section, address)
943 struct bfd_link_info *info;
944 const char *name;
945 bfd *abfd;
946 asection *section;
947 bfd_vma address;
948{
949 if (abfd == (bfd *) NULL)
950 einfo ("%P%X: generated");
951 else
952 einfo ("%X%C:", abfd, section, address);
953 einfo (" reloc refers to symbol `%T' which is not being output\n", name);
954 return true;
955}
956
957/* This is called when a symbol in notice_hash is found. Symbols are
958 put in notice_hash using the -y option. */
959
960/*ARGSUSED*/
961static boolean
962notice_ysym (info, name, abfd, section, value)
963 struct bfd_link_info *info;
964 const char *name;
965 bfd *abfd;
966 asection *section;
967 bfd_vma value;
968{
969 einfo ("%B: %s %s\n", abfd,
970 bfd_is_und_section (section) ? "reference to" : "definition of",
971 name);
972 return true;
973}
This page took 0.024591 seconds and 4 git commands to generate.