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