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