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