1 /* Main program of GNU linker.
2 Copyright (C) 1991-2014 Free Software Foundation, Inc.
3 Written by Steve Chamberlain steve@cygnus.com
4
5 This file is part of the GNU Binutils.
6
7 This program 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 3 of the License, or
10 (at your option) any later version.
11
12 This program 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 this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
21
22 #include "sysdep.h"
23 #include "bfd.h"
24 #include "safe-ctype.h"
25 #include "libiberty.h"
26 #include "progress.h"
27 #include "bfdlink.h"
28 #include "filenames.h"
29
30 #include "ld.h"
31 #include "ldmain.h"
32 #include "ldmisc.h"
33 #include "ldwrite.h"
34 #include "ldexp.h"
35 #include "ldlang.h"
36 #include <ldgram.h>
37 #include "ldlex.h"
38 #include "ldfile.h"
39 #include "ldemul.h"
40 #include "ldctor.h"
41 #ifdef ENABLE_PLUGINS
42 #include "plugin.h"
43 #include "plugin-api.h"
44 #include "libbfd.h"
45 #endif /* ENABLE_PLUGINS */
46
47 /* Somewhere above, sys/stat.h got included. */
48 #if !defined(S_ISDIR) && defined(S_IFDIR)
49 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
50 #endif
51
52 #include <string.h>
53
54 #ifdef HAVE_SBRK
55 #if !HAVE_DECL_SBRK
56 extern void *sbrk ();
57 #endif
58 #endif
59
60 #ifndef TARGET_SYSTEM_ROOT
61 #define TARGET_SYSTEM_ROOT ""
62 #endif
63
64 /* EXPORTS */
65
66 FILE *saved_script_handle = NULL;
67 FILE *previous_script_handle = NULL;
68 bfd_boolean force_make_executable = FALSE;
69
70 char *default_target;
71 const char *output_filename = "a.out";
72
73 /* Name this program was invoked by. */
74 char *program_name;
75
76 /* The prefix for system library directories. */
77 const char *ld_sysroot;
78
79 /* The canonical representation of ld_sysroot. */
80 char * ld_canon_sysroot;
81 int ld_canon_sysroot_len;
82
83 /* Set by -G argument, for targets like MIPS ELF. */
84 int g_switch_value = 8;
85
86 /* Nonzero means print names of input files as processed. */
87 bfd_boolean trace_files;
88
89 /* Nonzero means report actions taken by the linker, and describe the linker script in use. */
90 bfd_boolean verbose;
91
92 /* Nonzero means version number was printed, so exit successfully
93 instead of complaining if no input files are given. */
94 bfd_boolean version_printed;
95
96 /* TRUE if we should demangle symbol names. */
97 bfd_boolean demangling;
98
99 args_type command_line;
100
101 ld_config_type config;
102
103 sort_type sort_section;
104
105 static const char *get_sysroot
106 (int, char **);
107 static char *get_emulation
108 (int, char **);
109 static bfd_boolean add_archive_element
110 (struct bfd_link_info *, bfd *, const char *, bfd **);
111 static bfd_boolean multiple_definition
112 (struct bfd_link_info *, struct bfd_link_hash_entry *,
113 bfd *, asection *, bfd_vma);
114 static bfd_boolean multiple_common
115 (struct bfd_link_info *, struct bfd_link_hash_entry *,
116 bfd *, enum bfd_link_hash_type, bfd_vma);
117 static bfd_boolean add_to_set
118 (struct bfd_link_info *, struct bfd_link_hash_entry *,
119 bfd_reloc_code_real_type, bfd *, asection *, bfd_vma);
120 static bfd_boolean constructor_callback
121 (struct bfd_link_info *, bfd_boolean, const char *, bfd *,
122 asection *, bfd_vma);
123 static bfd_boolean warning_callback
124 (struct bfd_link_info *, const char *, const char *, bfd *,
125 asection *, bfd_vma);
126 static void warning_find_reloc
127 (bfd *, asection *, void *);
128 static bfd_boolean undefined_symbol
129 (struct bfd_link_info *, const char *, bfd *, asection *, bfd_vma,
130 bfd_boolean);
131 static bfd_boolean reloc_overflow
132 (struct bfd_link_info *, struct bfd_link_hash_entry *, const char *,
133 const char *, bfd_vma, bfd *, asection *, bfd_vma);
134 static bfd_boolean reloc_dangerous
135 (struct bfd_link_info *, const char *, bfd *, asection *, bfd_vma);
136 static bfd_boolean unattached_reloc
137 (struct bfd_link_info *, const char *, bfd *, asection *, bfd_vma);
138 static bfd_boolean notice
139 (struct bfd_link_info *, struct bfd_link_hash_entry *,
140 struct bfd_link_hash_entry *, bfd *, asection *, bfd_vma, flagword);
141
142 static struct bfd_link_callbacks link_callbacks =
143 {
144 add_archive_element,
145 multiple_definition,
146 multiple_common,
147 add_to_set,
148 constructor_callback,
149 warning_callback,
150 undefined_symbol,
151 reloc_overflow,
152 reloc_dangerous,
153 unattached_reloc,
154 notice,
155 einfo,
156 info_msg,
157 minfo,
158 ldlang_override_segment_assignment
159 };
160
161 static bfd_assert_handler_type default_bfd_assert_handler;
162
163 struct bfd_link_info link_info;
164
165 static void
ld_cleanup(void)166 ld_cleanup (void)
167 {
168 bfd_cache_close_all ();
169 #ifdef ENABLE_PLUGINS
170 plugin_call_cleanup ();
171 #endif
172 if (output_filename && delete_output_file_on_failure)
173 unlink_if_ordinary (output_filename);
174 }
175
176 /* If there's a BFD assertion, we'll notice and exit with an error
177 unless otherwise instructed. */
178
179 static void
ld_bfd_assert_handler(const char * fmt,const char * bfdver,const char * file,int line)180 ld_bfd_assert_handler (const char *fmt, const char *bfdver,
181 const char *file, int line)
182 {
183 (*default_bfd_assert_handler) (fmt, bfdver, file, line);
184 config.make_executable = FALSE;
185 }
186
187 int
main(int argc,char ** argv)188 main (int argc, char **argv)
189 {
190 char *emulation;
191 long start_time = get_run_time ();
192 #ifdef HAVE_SBRK
193 char *start_sbrk = (char *) sbrk (0);
194 #endif
195
196 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
197 setlocale (LC_MESSAGES, "");
198 #endif
199 #if defined (HAVE_SETLOCALE)
200 setlocale (LC_CTYPE, "");
201 #endif
202 bindtextdomain (PACKAGE, LOCALEDIR);
203 textdomain (PACKAGE);
204
205 program_name = argv[0];
206 xmalloc_set_program_name (program_name);
207
208 START_PROGRESS (program_name, 0);
209
210 expandargv (&argc, &argv);
211
212 bfd_init ();
213
214 bfd_set_error_program_name (program_name);
215
216 /* We want to notice and fail on those nasty BFD assertions which are
217 likely to signal incorrect output being generated but otherwise may
218 leave no trace. */
219 default_bfd_assert_handler = bfd_set_assert_handler (ld_bfd_assert_handler);
220
221 xatexit (ld_cleanup);
222
223 /* Set up the sysroot directory. */
224 ld_sysroot = get_sysroot (argc, argv);
225 if (*ld_sysroot)
226 {
227 if (*TARGET_SYSTEM_ROOT == 0)
228 {
229 einfo ("%P%F: this linker was not configured to use sysroots\n");
230 ld_sysroot = "";
231 }
232 else
233 ld_canon_sysroot = lrealpath (ld_sysroot);
234 }
235 if (ld_canon_sysroot)
236 ld_canon_sysroot_len = strlen (ld_canon_sysroot);
237 else
238 ld_canon_sysroot_len = -1;
239
240 /* Set the default BFD target based on the configured target. Doing
241 this permits the linker to be configured for a particular target,
242 and linked against a shared BFD library which was configured for
243 a different target. The macro TARGET is defined by Makefile. */
244 if (! bfd_set_default_target (TARGET))
245 {
246 einfo (_("%X%P: can't set BFD default target to `%s': %E\n"), TARGET);
247 xexit (1);
248 }
249
250 #if YYDEBUG
251 {
252 extern int yydebug;
253 yydebug = 1;
254 }
255 #endif
256
257 config.build_constructors = TRUE;
258 config.rpath_separator = ':';
259 config.split_by_reloc = (unsigned) -1;
260 config.split_by_file = (bfd_size_type) -1;
261 config.make_executable = TRUE;
262 config.magic_demand_paged = TRUE;
263 config.text_read_only = TRUE;
264 link_info.disable_target_specific_optimizations = -1;
265
266 command_line.warn_mismatch = TRUE;
267 command_line.warn_search_mismatch = TRUE;
268 command_line.check_section_addresses = -1;
269 command_line.warn_poison_system_directories =
270 #ifdef ENABLE_POISON_SYSTEM_DIRECTORIES
271 TRUE;
272 #else
273 FALSE;
274 #endif
275 command_line.error_poison_system_directories = FALSE;
276
277 /* We initialize DEMANGLING based on the environment variable
278 COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the
279 output of the linker, unless COLLECT_NO_DEMANGLE is set in the
280 environment. Acting the same way here lets us provide the same
281 interface by default. */
282 demangling = getenv ("COLLECT_NO_DEMANGLE") == NULL;
283
284 link_info.allow_undefined_version = TRUE;
285 link_info.keep_memory = TRUE;
286 link_info.combreloc = TRUE;
287 link_info.strip_discarded = TRUE;
288 link_info.emit_hash = TRUE;
289 link_info.callbacks = &link_callbacks;
290 link_info.input_bfds_tail = &link_info.input_bfds;
291 /* SVR4 linkers seem to set DT_INIT and DT_FINI based on magic _init
292 and _fini symbols. We are compatible. */
293 link_info.init_function = "_init";
294 link_info.fini_function = "_fini";
295 link_info.relax_pass = 1;
296 link_info.pei386_auto_import = -1;
297 link_info.spare_dynamic_tags = 5;
298 link_info.path_separator = ':';
299
300 ldfile_add_arch ("");
301 emulation = get_emulation (argc, argv);
302 ldemul_choose_mode (emulation);
303 default_target = ldemul_choose_target (argc, argv);
304 config.maxpagesize = bfd_emul_get_maxpagesize (default_target);
305 config.commonpagesize = bfd_emul_get_commonpagesize (default_target);
306 lang_init ();
307 ldemul_before_parse ();
308 lang_has_input_file = FALSE;
309 parse_args (argc, argv);
310
311 if (config.hash_table_size != 0)
312 bfd_hash_set_default_size (config.hash_table_size);
313
314 #ifdef ENABLE_PLUGINS
315 /* Now all the plugin arguments have been gathered, we can load them. */
316 plugin_load_plugins ();
317 #endif /* ENABLE_PLUGINS */
318
319 ldemul_set_symbols ();
320
321 /* If we have not already opened and parsed a linker script,
322 try the default script from command line first. */
323 if (saved_script_handle == NULL
324 && command_line.default_script != NULL)
325 {
326 ldfile_open_command_file (command_line.default_script);
327 parser_input = input_script;
328 yyparse ();
329 }
330
331 /* If we have not already opened and parsed a linker script
332 read the emulation's appropriate default script. */
333 if (saved_script_handle == NULL)
334 {
335 int isfile;
336 char *s = ldemul_get_script (&isfile);
337
338 if (isfile)
339 ldfile_open_default_command_file (s);
340 else
341 {
342 lex_string = s;
343 lex_redirect (s, _("built in linker script"), 1);
344 }
345 parser_input = input_script;
346 yyparse ();
347 lex_string = NULL;
348 }
349
350 if (verbose)
351 {
352 if (saved_script_handle)
353 info_msg (_("using external linker script:"));
354 else
355 info_msg (_("using internal linker script:"));
356 info_msg ("\n==================================================\n");
357
358 if (saved_script_handle)
359 {
360 static const int ld_bufsz = 8193;
361 size_t n;
362 char *buf = (char *) xmalloc (ld_bufsz);
363
364 rewind (saved_script_handle);
365 while ((n = fread (buf, 1, ld_bufsz - 1, saved_script_handle)) > 0)
366 {
367 buf[n] = 0;
368 info_msg (buf);
369 }
370 rewind (saved_script_handle);
371 free (buf);
372 }
373 else
374 {
375 int isfile;
376
377 info_msg (ldemul_get_script (&isfile));
378 }
379
380 info_msg ("\n==================================================\n");
381 }
382
383 if (command_line.print_output_format)
384 info_msg ("%s\n", lang_get_output_target ());
385
386 lang_final ();
387
388 /* If the only command line argument has been -v or --version or --verbose
389 then ignore any input files provided by linker scripts and exit now.
390 We do not want to create an output file when the linker is just invoked
391 to provide version information. */
392 if (argc == 2 && version_printed)
393 xexit (0);
394
395 if (!lang_has_input_file)
396 {
397 if (version_printed || command_line.print_output_format)
398 xexit (0);
399 einfo (_("%P%F: no input files\n"));
400 }
401
402 if (trace_files)
403 info_msg (_("%P: mode %s\n"), emulation);
404
405 ldemul_after_parse ();
406
407 if (config.map_filename)
408 {
409 if (strcmp (config.map_filename, "-") == 0)
410 {
411 config.map_file = stdout;
412 }
413 else
414 {
415 config.map_file = fopen (config.map_filename, FOPEN_WT);
416 if (config.map_file == (FILE *) NULL)
417 {
418 bfd_set_error (bfd_error_system_call);
419 einfo (_("%P%F: cannot open map file %s: %E\n"),
420 config.map_filename);
421 }
422 }
423 }
424
425 lang_process ();
426
427 /* Print error messages for any missing symbols, for any warning
428 symbols, and possibly multiple definitions. */
429 if (link_info.relocatable)
430 link_info.output_bfd->flags &= ~EXEC_P;
431 else
432 link_info.output_bfd->flags |= EXEC_P;
433
434 ldwrite ();
435
436 if (config.map_file != NULL)
437 lang_map ();
438 if (command_line.cref)
439 output_cref (config.map_file != NULL ? config.map_file : stdout);
440 if (nocrossref_list != NULL)
441 check_nocrossrefs ();
442 #if 0
443 {
444 struct bfd_link_hash_entry * h;
445
446 h = bfd_link_hash_lookup (link_info.hash, "__image_base__", 0,0,1);
447 fprintf (stderr, "lookup = %p val %lx\n", h, h ? h->u.def.value : 1);
448 }
449 #endif
450 lang_finish ();
451
452 /* Even if we're producing relocatable output, some non-fatal errors should
453 be reported in the exit status. (What non-fatal errors, if any, do we
454 want to ignore for relocatable output?) */
455 if (!config.make_executable && !force_make_executable)
456 {
457 if (trace_files)
458 einfo (_("%P: link errors found, deleting executable `%s'\n"),
459 output_filename);
460
461 /* The file will be removed by ld_cleanup. */
462 xexit (1);
463 }
464 else
465 {
466 if (! bfd_close (link_info.output_bfd))
467 einfo (_("%F%B: final close failed: %E\n"), link_info.output_bfd);
468
469 /* If the --force-exe-suffix is enabled, and we're making an
470 executable file and it doesn't end in .exe, copy it to one
471 which does. */
472 if (! link_info.relocatable && command_line.force_exe_suffix)
473 {
474 int len = strlen (output_filename);
475
476 if (len < 4
477 || (strcasecmp (output_filename + len - 4, ".exe") != 0
478 && strcasecmp (output_filename + len - 4, ".dll") != 0))
479 {
480 FILE *src;
481 FILE *dst;
482 const int bsize = 4096;
483 char *buf = (char *) xmalloc (bsize);
484 int l;
485 char *dst_name = (char *) xmalloc (len + 5);
486
487 strcpy (dst_name, output_filename);
488 strcat (dst_name, ".exe");
489 src = fopen (output_filename, FOPEN_RB);
490 dst = fopen (dst_name, FOPEN_WB);
491
492 if (!src)
493 einfo (_("%X%P: unable to open for source of copy `%s'\n"),
494 output_filename);
495 if (!dst)
496 einfo (_("%X%P: unable to open for destination of copy `%s'\n"),
497 dst_name);
498 while ((l = fread (buf, 1, bsize, src)) > 0)
499 {
500 int done = fwrite (buf, 1, l, dst);
501
502 if (done != l)
503 einfo (_("%P: Error writing file `%s'\n"), dst_name);
504 }
505
506 fclose (src);
507 if (fclose (dst) == EOF)
508 einfo (_("%P: Error closing file `%s'\n"), dst_name);
509 free (dst_name);
510 free (buf);
511 }
512 }
513 }
514
515 END_PROGRESS (program_name);
516
517 if (config.stats)
518 {
519 #ifdef HAVE_SBRK
520 char *lim = (char *) sbrk (0);
521 #endif
522 long run_time = get_run_time () - start_time;
523
524 fflush (stdout);
525 fprintf (stderr, _("%s: total time in link: %ld.%06ld\n"),
526 program_name, run_time / 1000000, run_time % 1000000);
527 #ifdef HAVE_SBRK
528 fprintf (stderr, _("%s: data size %ld\n"), program_name,
529 (long) (lim - start_sbrk));
530 #endif
531 fflush (stderr);
532 }
533
534 /* Prevent ld_cleanup from doing anything, after a successful link. */
535 output_filename = NULL;
536
537 xexit (0);
538 return 0;
539 }
540
541 /* If the configured sysroot is relocatable, try relocating it based on
542 default prefix FROM. Return the relocated directory if it exists,
543 otherwise return null. */
544
545 static char *
get_relative_sysroot(const char * from ATTRIBUTE_UNUSED)546 get_relative_sysroot (const char *from ATTRIBUTE_UNUSED)
547 {
548 #ifdef TARGET_SYSTEM_ROOT_RELOCATABLE
549 char *path;
550 struct stat s;
551
552 path = make_relative_prefix (program_name, from, TARGET_SYSTEM_ROOT);
553 if (path)
554 {
555 if (stat (path, &s) == 0 && S_ISDIR (s.st_mode))
556 return path;
557 free (path);
558 }
559 #endif
560 return 0;
561 }
562
563 /* Return the sysroot directory. Return "" if no sysroot is being used. */
564
565 static const char *
get_sysroot(int argc,char ** argv)566 get_sysroot (int argc, char **argv)
567 {
568 int i;
569 const char *path;
570
571 for (i = 1; i < argc; i++)
572 if (CONST_STRNEQ (argv[i], "--sysroot="))
573 return argv[i] + strlen ("--sysroot=");
574
575 path = get_relative_sysroot (BINDIR);
576 if (path)
577 return path;
578
579 path = get_relative_sysroot (TOOLBINDIR);
580 if (path)
581 return path;
582
583 return TARGET_SYSTEM_ROOT;
584 }
585
586 /* We need to find any explicitly given emulation in order to initialize the
587 state that's needed by the lex&yacc argument parser (parse_args). */
588
589 static char *
get_emulation(int argc,char ** argv)590 get_emulation (int argc, char **argv)
591 {
592 char *emulation;
593 int i;
594
595 emulation = getenv (EMULATION_ENVIRON);
596 if (emulation == NULL)
597 emulation = DEFAULT_EMULATION;
598
599 for (i = 1; i < argc; i++)
600 {
601 if (CONST_STRNEQ (argv[i], "-m"))
602 {
603 if (argv[i][2] == '\0')
604 {
605 /* -m EMUL */
606 if (i < argc - 1)
607 {
608 emulation = argv[i + 1];
609 i++;
610 }
611 else
612 einfo (_("%P%F: missing argument to -m\n"));
613 }
614 else if (strcmp (argv[i], "-mips1") == 0
615 || strcmp (argv[i], "-mips2") == 0
616 || strcmp (argv[i], "-mips3") == 0
617 || strcmp (argv[i], "-mips4") == 0
618 || strcmp (argv[i], "-mips5") == 0
619 || strcmp (argv[i], "-mips32") == 0
620 || strcmp (argv[i], "-mips32r2") == 0
621 || strcmp (argv[i], "-mips32r6") == 0
622 || strcmp (argv[i], "-mips64") == 0
623 || strcmp (argv[i], "-mips64r2") == 0
624 || strcmp (argv[i], "-mips64r6") == 0)
625 {
626 /* FIXME: The arguments -mips1, -mips2, -mips3, etc. are
627 passed to the linker by some MIPS compilers. They
628 generally tell the linker to use a slightly different
629 library path. Perhaps someday these should be
630 implemented as emulations; until then, we just ignore
631 the arguments and hope that nobody ever creates
632 emulations named ips1, ips2 or ips3. */
633 }
634 else if (strcmp (argv[i], "-m486") == 0)
635 {
636 /* FIXME: The argument -m486 is passed to the linker on
637 some Linux systems. Hope that nobody creates an
638 emulation named 486. */
639 }
640 else
641 {
642 /* -mEMUL */
643 emulation = &argv[i][2];
644 }
645 }
646 }
647
648 return emulation;
649 }
650
651 void
add_ysym(const char * name)652 add_ysym (const char *name)
653 {
654 if (link_info.notice_hash == NULL)
655 {
656 link_info.notice_hash =
657 (struct bfd_hash_table *) xmalloc (sizeof (struct bfd_hash_table));
658 if (!bfd_hash_table_init_n (link_info.notice_hash,
659 bfd_hash_newfunc,
660 sizeof (struct bfd_hash_entry),
661 61))
662 einfo (_("%P%F: bfd_hash_table_init failed: %E\n"));
663 }
664
665 if (bfd_hash_lookup (link_info.notice_hash, name, TRUE, TRUE) == NULL)
666 einfo (_("%P%F: bfd_hash_lookup failed: %E\n"));
667 }
668
669 void
add_ignoresym(struct bfd_link_info * info,const char * name)670 add_ignoresym (struct bfd_link_info *info, const char *name)
671 {
672 if (info->ignore_hash == NULL)
673 {
674 info->ignore_hash = xmalloc (sizeof (struct bfd_hash_table));
675 if (! bfd_hash_table_init_n (info->ignore_hash,
676 bfd_hash_newfunc,
677 sizeof (struct bfd_hash_entry),
678 61))
679 einfo (_("%P%F: bfd_hash_table_init failed: %E\n"));
680 }
681
682 if (bfd_hash_lookup (info->ignore_hash, name, TRUE, TRUE) == NULL)
683 einfo (_("%P%F: bfd_hash_lookup failed: %E\n"));
684 }
685
686 /* Record a symbol to be wrapped, from the --wrap option. */
687
688 void
add_wrap(const char * name)689 add_wrap (const char *name)
690 {
691 if (link_info.wrap_hash == NULL)
692 {
693 link_info.wrap_hash =
694 (struct bfd_hash_table *) xmalloc (sizeof (struct bfd_hash_table));
695 if (!bfd_hash_table_init_n (link_info.wrap_hash,
696 bfd_hash_newfunc,
697 sizeof (struct bfd_hash_entry),
698 61))
699 einfo (_("%P%F: bfd_hash_table_init failed: %E\n"));
700 }
701
702 if (bfd_hash_lookup (link_info.wrap_hash, name, TRUE, TRUE) == NULL)
703 einfo (_("%P%F: bfd_hash_lookup failed: %E\n"));
704 }
705
706 /* Handle the -retain-symbols-file option. */
707
708 void
add_keepsyms_file(const char * filename)709 add_keepsyms_file (const char *filename)
710 {
711 FILE *file;
712 char *buf;
713 size_t bufsize;
714 int c;
715
716 if (link_info.strip == strip_some)
717 einfo (_("%X%P: error: duplicate retain-symbols-file\n"));
718
719 file = fopen (filename, "r");
720 if (file == NULL)
721 {
722 bfd_set_error (bfd_error_system_call);
723 einfo ("%X%P: %s: %E\n", filename);
724 return;
725 }
726
727 link_info.keep_hash = (struct bfd_hash_table *)
728 xmalloc (sizeof (struct bfd_hash_table));
729 if (!bfd_hash_table_init (link_info.keep_hash, bfd_hash_newfunc,
730 sizeof (struct bfd_hash_entry)))
731 einfo (_("%P%F: bfd_hash_table_init failed: %E\n"));
732
733 bufsize = 100;
734 buf = (char *) xmalloc (bufsize);
735
736 c = getc (file);
737 while (c != EOF)
738 {
739 while (ISSPACE (c))
740 c = getc (file);
741
742 if (c != EOF)
743 {
744 size_t len = 0;
745
746 while (! ISSPACE (c) && c != EOF)
747 {
748 buf[len] = c;
749 ++len;
750 if (len >= bufsize)
751 {
752 bufsize *= 2;
753 buf = (char *) xrealloc (buf, bufsize);
754 }
755 c = getc (file);
756 }
757
758 buf[len] = '\0';
759
760 if (bfd_hash_lookup (link_info.keep_hash, buf, TRUE, TRUE) == NULL)
761 einfo (_("%P%F: bfd_hash_lookup for insertion failed: %E\n"));
762 }
763 }
764
765 if (link_info.strip != strip_none)
766 einfo (_("%P: `-retain-symbols-file' overrides `-s' and `-S'\n"));
767
768 free (buf);
769 link_info.strip = strip_some;
770 fclose (file);
771 }
772
773 /* Callbacks from the BFD linker routines. */
774
775 /* This is called when BFD has decided to include an archive member in
776 a link. */
777
778 static bfd_boolean
add_archive_element(struct bfd_link_info * info,bfd * abfd,const char * name,bfd ** subsbfd ATTRIBUTE_UNUSED)779 add_archive_element (struct bfd_link_info *info,
780 bfd *abfd,
781 const char *name,
782 bfd **subsbfd ATTRIBUTE_UNUSED)
783 {
784 lang_input_statement_type *input;
785 lang_input_statement_type orig_input;
786
787 input = (lang_input_statement_type *)
788 xcalloc (1, sizeof (lang_input_statement_type));
789 input->filename = abfd->filename;
790 input->local_sym_name = abfd->filename;
791 input->the_bfd = abfd;
792
793 /* Save the original data for trace files/tries below, as plugins
794 (if enabled) may possibly alter it to point to a replacement
795 BFD, but we still want to output the original BFD filename. */
796 orig_input = *input;
797 #ifdef ENABLE_PLUGINS
798 if (plugin_active_plugins_p () && !no_more_claiming)
799 {
800 /* We must offer this archive member to the plugins to claim. */
801 const char *filename = (bfd_my_archive (abfd) != NULL
802 ? bfd_my_archive (abfd)->filename : abfd->filename);
803 int fd = open (filename, O_RDONLY | O_BINARY);
804 if (fd >= 0)
805 {
806 struct ld_plugin_input_file file;
807
808 /* Offset and filesize must refer to the individual archive
809 member, not the whole file, and must exclude the header.
810 Fortunately for us, that is how the data is stored in the
811 origin field of the bfd and in the arelt_data. */
812 file.name = filename;
813 file.offset = abfd->origin;
814 file.filesize = arelt_size (abfd);
815 file.fd = fd;
816 plugin_maybe_claim (&file, input);
817 if (input->flags.claimed)
818 {
819 input->flags.claim_archive = TRUE;
820 *subsbfd = input->the_bfd;
821 }
822 }
823 }
824 #endif /* ENABLE_PLUGINS */
825
826 ldlang_add_file (input);
827
828 if (config.map_file != NULL)
829 {
830 static bfd_boolean header_printed;
831 struct bfd_link_hash_entry *h;
832 bfd *from;
833 int len;
834
835 h = bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE);
836
837 if (h == NULL)
838 from = NULL;
839 else
840 {
841 switch (h->type)
842 {
843 default:
844 from = NULL;
845 break;
846
847 case bfd_link_hash_defined:
848 case bfd_link_hash_defweak:
849 from = h->u.def.section->owner;
850 break;
851
852 case bfd_link_hash_undefined:
853 case bfd_link_hash_undefweak:
854 from = h->u.undef.abfd;
855 break;
856
857 case bfd_link_hash_common:
858 from = h->u.c.p->section->owner;
859 break;
860 }
861 }
862
863 if (! header_printed)
864 {
865 char buf[100];
866
867 sprintf (buf, _("Archive member included "
868 "to satisfy reference by file (symbol)\n\n"));
869 minfo ("%s", buf);
870 header_printed = TRUE;
871 }
872
873 if (bfd_my_archive (abfd) == NULL)
874 {
875 minfo ("%s", bfd_get_filename (abfd));
876 len = strlen (bfd_get_filename (abfd));
877 }
878 else
879 {
880 minfo ("%s(%s)", bfd_get_filename (bfd_my_archive (abfd)),
881 bfd_get_filename (abfd));
882 len = (strlen (bfd_get_filename (bfd_my_archive (abfd)))
883 + strlen (bfd_get_filename (abfd))
884 + 2);
885 }
886
887 if (len >= 29)
888 {
889 print_nl ();
890 len = 0;
891 }
892 while (len < 30)
893 {
894 print_space ();
895 ++len;
896 }
897
898 if (from != NULL)
899 minfo ("%B ", from);
900 if (h != NULL)
901 minfo ("(%T)\n", h->root.string);
902 else
903 minfo ("(%s)\n", name);
904 }
905
906 if (trace_files || verbose)
907 info_msg ("%I\n", &orig_input);
908 return TRUE;
909 }
910
911 /* This is called when BFD has discovered a symbol which is defined
912 multiple times. */
913
914 static bfd_boolean
multiple_definition(struct bfd_link_info * info,struct bfd_link_hash_entry * h,bfd * nbfd,asection * nsec,bfd_vma nval)915 multiple_definition (struct bfd_link_info *info,
916 struct bfd_link_hash_entry *h,
917 bfd *nbfd,
918 asection *nsec,
919 bfd_vma nval)
920 {
921 const char *name;
922 bfd *obfd;
923 asection *osec;
924 bfd_vma oval;
925
926 if (info->allow_multiple_definition)
927 return TRUE;
928
929 switch (h->type)
930 {
931 case bfd_link_hash_defined:
932 osec = h->u.def.section;
933 oval = h->u.def.value;
934 obfd = h->u.def.section->owner;
935 break;
936 case bfd_link_hash_indirect:
937 osec = bfd_ind_section_ptr;
938 oval = 0;
939 obfd = NULL;
940 break;
941 default:
942 abort ();
943 }
944
945 /* Ignore a redefinition of an absolute symbol to the
946 same value; it's harmless. */
947 if (h->type == bfd_link_hash_defined
948 && bfd_is_abs_section (osec)
949 && bfd_is_abs_section (nsec)
950 && nval == oval)
951 return TRUE;
952
953 /* If either section has the output_section field set to
954 bfd_abs_section_ptr, it means that the section is being
955 discarded, and this is not really a multiple definition at all.
956 FIXME: It would be cleaner to somehow ignore symbols defined in
957 sections which are being discarded. */
958 if ((osec->output_section != NULL
959 && ! bfd_is_abs_section (osec)
960 && bfd_is_abs_section (osec->output_section))
961 || (nsec->output_section != NULL
962 && ! bfd_is_abs_section (nsec)
963 && bfd_is_abs_section (nsec->output_section)))
964 return TRUE;
965
966 name = h->root.string;
967 if (nbfd == NULL)
968 {
969 nbfd = obfd;
970 nsec = osec;
971 nval = oval;
972 obfd = NULL;
973 }
974 einfo (_("%X%C: multiple definition of `%T'\n"),
975 nbfd, nsec, nval, name);
976 if (obfd != NULL)
977 einfo (_("%D: first defined here\n"), obfd, osec, oval);
978
979 if (RELAXATION_ENABLED_BY_USER)
980 {
981 einfo (_("%P: Disabling relaxation: it will not work with multiple definitions\n"));
982 DISABLE_RELAXATION;
983 }
984
985 return TRUE;
986 }
987
988 /* This is called when there is a definition of a common symbol, or
989 when a common symbol is found for a symbol that is already defined,
990 or when two common symbols are found. We only do something if
991 -warn-common was used. */
992
993 static bfd_boolean
multiple_common(struct bfd_link_info * info ATTRIBUTE_UNUSED,struct bfd_link_hash_entry * h,bfd * nbfd,enum bfd_link_hash_type ntype,bfd_vma nsize)994 multiple_common (struct bfd_link_info *info ATTRIBUTE_UNUSED,
995 struct bfd_link_hash_entry *h,
996 bfd *nbfd,
997 enum bfd_link_hash_type ntype,
998 bfd_vma nsize)
999 {
1000 const char *name;
1001 bfd *obfd;
1002 enum bfd_link_hash_type otype;
1003 bfd_vma osize;
1004
1005 if (!config.warn_common)
1006 return TRUE;
1007
1008 name = h->root.string;
1009 otype = h->type;
1010 if (otype == bfd_link_hash_common)
1011 {
1012 obfd = h->u.c.p->section->owner;
1013 osize = h->u.c.size;
1014 }
1015 else if (otype == bfd_link_hash_defined
1016 || otype == bfd_link_hash_defweak)
1017 {
1018 obfd = h->u.def.section->owner;
1019 osize = 0;
1020 }
1021 else
1022 {
1023 /* FIXME: It would nice if we could report the BFD which defined
1024 an indirect symbol, but we don't have anywhere to store the
1025 information. */
1026 obfd = NULL;
1027 osize = 0;
1028 }
1029
1030 if (ntype == bfd_link_hash_defined
1031 || ntype == bfd_link_hash_defweak
1032 || ntype == bfd_link_hash_indirect)
1033 {
1034 ASSERT (otype == bfd_link_hash_common);
1035 einfo (_("%B: warning: definition of `%T' overriding common\n"),
1036 nbfd, name);
1037 if (obfd != NULL)
1038 einfo (_("%B: warning: common is here\n"), obfd);
1039 }
1040 else if (otype == bfd_link_hash_defined
1041 || otype == bfd_link_hash_defweak
1042 || otype == bfd_link_hash_indirect)
1043 {
1044 ASSERT (ntype == bfd_link_hash_common);
1045 einfo (_("%B: warning: common of `%T' overridden by definition\n"),
1046 nbfd, name);
1047 if (obfd != NULL)
1048 einfo (_("%B: warning: defined here\n"), obfd);
1049 }
1050 else
1051 {
1052 ASSERT (otype == bfd_link_hash_common && ntype == bfd_link_hash_common);
1053 if (osize > nsize)
1054 {
1055 einfo (_("%B: warning: common of `%T' overridden by larger common\n"),
1056 nbfd, name);
1057 if (obfd != NULL)
1058 einfo (_("%B: warning: larger common is here\n"), obfd);
1059 }
1060 else if (nsize > osize)
1061 {
1062 einfo (_("%B: warning: common of `%T' overriding smaller common\n"),
1063 nbfd, name);
1064 if (obfd != NULL)
1065 einfo (_("%B: warning: smaller common is here\n"), obfd);
1066 }
1067 else
1068 {
1069 einfo (_("%B: warning: multiple common of `%T'\n"), nbfd, name);
1070 if (obfd != NULL)
1071 einfo (_("%B: warning: previous common is here\n"), obfd);
1072 }
1073 }
1074
1075 return TRUE;
1076 }
1077
1078 /* This is called when BFD has discovered a set element. H is the
1079 entry in the linker hash table for the set. SECTION and VALUE
1080 represent a value which should be added to the set. */
1081
1082 static bfd_boolean
add_to_set(struct bfd_link_info * info ATTRIBUTE_UNUSED,struct bfd_link_hash_entry * h,bfd_reloc_code_real_type reloc,bfd * abfd,asection * section,bfd_vma value)1083 add_to_set (struct bfd_link_info *info ATTRIBUTE_UNUSED,
1084 struct bfd_link_hash_entry *h,
1085 bfd_reloc_code_real_type reloc,
1086 bfd *abfd,
1087 asection *section,
1088 bfd_vma value)
1089 {
1090 if (config.warn_constructors)
1091 einfo (_("%P: warning: global constructor %s used\n"),
1092 h->root.string);
1093
1094 if (! config.build_constructors)
1095 return TRUE;
1096
1097 ldctor_add_set_entry (h, reloc, NULL, section, value);
1098
1099 if (h->type == bfd_link_hash_new)
1100 {
1101 h->type = bfd_link_hash_undefined;
1102 h->u.undef.abfd = abfd;
1103 /* We don't call bfd_link_add_undef to add this to the list of
1104 undefined symbols because we are going to define it
1105 ourselves. */
1106 }
1107
1108 return TRUE;
1109 }
1110
1111 /* This is called when BFD has discovered a constructor. This is only
1112 called for some object file formats--those which do not handle
1113 constructors in some more clever fashion. This is similar to
1114 adding an element to a set, but less general. */
1115
1116 static bfd_boolean
constructor_callback(struct bfd_link_info * info,bfd_boolean constructor,const char * name,bfd * abfd,asection * section,bfd_vma value)1117 constructor_callback (struct bfd_link_info *info,
1118 bfd_boolean constructor,
1119 const char *name,
1120 bfd *abfd,
1121 asection *section,
1122 bfd_vma value)
1123 {
1124 char *s;
1125 struct bfd_link_hash_entry *h;
1126 char set_name[1 + sizeof "__CTOR_LIST__"];
1127
1128 if (config.warn_constructors)
1129 einfo (_("%P: warning: global constructor %s used\n"), name);
1130
1131 if (! config.build_constructors)
1132 return TRUE;
1133
1134 /* Ensure that BFD_RELOC_CTOR exists now, so that we can give a
1135 useful error message. */
1136 if (bfd_reloc_type_lookup (info->output_bfd, BFD_RELOC_CTOR) == NULL
1137 && (info->relocatable
1138 || bfd_reloc_type_lookup (abfd, BFD_RELOC_CTOR) == NULL))
1139 einfo (_("%P%F: BFD backend error: BFD_RELOC_CTOR unsupported\n"));
1140
1141 s = set_name;
1142 if (bfd_get_symbol_leading_char (abfd) != '\0')
1143 *s++ = bfd_get_symbol_leading_char (abfd);
1144 if (constructor)
1145 strcpy (s, "__CTOR_LIST__");
1146 else
1147 strcpy (s, "__DTOR_LIST__");
1148
1149 h = bfd_link_hash_lookup (info->hash, set_name, TRUE, TRUE, TRUE);
1150 if (h == (struct bfd_link_hash_entry *) NULL)
1151 einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
1152 if (h->type == bfd_link_hash_new)
1153 {
1154 h->type = bfd_link_hash_undefined;
1155 h->u.undef.abfd = abfd;
1156 /* We don't call bfd_link_add_undef to add this to the list of
1157 undefined symbols because we are going to define it
1158 ourselves. */
1159 }
1160
1161 ldctor_add_set_entry (h, BFD_RELOC_CTOR, name, section, value);
1162 return TRUE;
1163 }
1164
1165 /* A structure used by warning_callback to pass information through
1166 bfd_map_over_sections. */
1167
1168 struct warning_callback_info
1169 {
1170 bfd_boolean found;
1171 const char *warning;
1172 const char *symbol;
1173 asymbol **asymbols;
1174 };
1175
1176 /* Look through the relocs to see if we can find a plausible address
1177 for SYMBOL in ABFD. Return TRUE if found. Otherwise return FALSE. */
1178
1179 static bfd_boolean
symbol_warning(const char * warning,const char * symbol,bfd * abfd)1180 symbol_warning (const char *warning, const char *symbol, bfd *abfd)
1181 {
1182 struct warning_callback_info cinfo;
1183
1184 if (!bfd_generic_link_read_symbols (abfd))
1185 einfo (_("%B%F: could not read symbols: %E\n"), abfd);
1186
1187 cinfo.found = FALSE;
1188 cinfo.warning = warning;
1189 cinfo.symbol = symbol;
1190 cinfo.asymbols = bfd_get_outsymbols (abfd);
1191 bfd_map_over_sections (abfd, warning_find_reloc, &cinfo);
1192 return cinfo.found;
1193 }
1194
1195 /* This is called when there is a reference to a warning symbol. */
1196
1197 static bfd_boolean
warning_callback(struct bfd_link_info * info ATTRIBUTE_UNUSED,const char * warning,const char * symbol,bfd * abfd,asection * section,bfd_vma address)1198 warning_callback (struct bfd_link_info *info ATTRIBUTE_UNUSED,
1199 const char *warning,
1200 const char *symbol,
1201 bfd *abfd,
1202 asection *section,
1203 bfd_vma address)
1204 {
1205 /* This is a hack to support warn_multiple_gp. FIXME: This should
1206 have a cleaner interface, but what? */
1207 if (! config.warn_multiple_gp
1208 && strcmp (warning, "using multiple gp values") == 0)
1209 return TRUE;
1210
1211 if (section != NULL)
1212 einfo ("%C: %s%s\n", abfd, section, address, _("warning: "), warning);
1213 else if (abfd == NULL)
1214 einfo ("%P: %s%s\n", _("warning: "), warning);
1215 else if (symbol == NULL)
1216 einfo ("%B: %s%s\n", abfd, _("warning: "), warning);
1217 else if (! symbol_warning (warning, symbol, abfd))
1218 {
1219 bfd *b;
1220 /* Search all input files for a reference to SYMBOL. */
1221 for (b = info->input_bfds; b; b = b->link.next)
1222 if (b != abfd && symbol_warning (warning, symbol, b))
1223 return TRUE;
1224 einfo ("%B: %s%s\n", abfd, _("warning: "), warning);
1225 }
1226
1227 return TRUE;
1228 }
1229
1230 /* This is called by warning_callback for each section. It checks the
1231 relocs of the section to see if it can find a reference to the
1232 symbol which triggered the warning. If it can, it uses the reloc
1233 to give an error message with a file and line number. */
1234
1235 static void
warning_find_reloc(bfd * abfd,asection * sec,void * iarg)1236 warning_find_reloc (bfd *abfd, asection *sec, void *iarg)
1237 {
1238 struct warning_callback_info *info = (struct warning_callback_info *) iarg;
1239 long relsize;
1240 arelent **relpp;
1241 long relcount;
1242 arelent **p, **pend;
1243
1244 if (info->found)
1245 return;
1246
1247 relsize = bfd_get_reloc_upper_bound (abfd, sec);
1248 if (relsize < 0)
1249 einfo (_("%B%F: could not read relocs: %E\n"), abfd);
1250 if (relsize == 0)
1251 return;
1252
1253 relpp = (arelent **) xmalloc (relsize);
1254 relcount = bfd_canonicalize_reloc (abfd, sec, relpp, info->asymbols);
1255 if (relcount < 0)
1256 einfo (_("%B%F: could not read relocs: %E\n"), abfd);
1257
1258 p = relpp;
1259 pend = p + relcount;
1260 for (; p < pend && *p != NULL; p++)
1261 {
1262 arelent *q = *p;
1263
1264 if (q->sym_ptr_ptr != NULL
1265 && *q->sym_ptr_ptr != NULL
1266 && strcmp (bfd_asymbol_name (*q->sym_ptr_ptr), info->symbol) == 0)
1267 {
1268 /* We found a reloc for the symbol we are looking for. */
1269 einfo ("%C: %s%s\n", abfd, sec, q->address, _("warning: "),
1270 info->warning);
1271 info->found = TRUE;
1272 break;
1273 }
1274 }
1275
1276 free (relpp);
1277 }
1278
1279 /* This is called when an undefined symbol is found. */
1280
1281 static bfd_boolean
undefined_symbol(struct bfd_link_info * info,const char * name,bfd * abfd,asection * section,bfd_vma address,bfd_boolean error)1282 undefined_symbol (struct bfd_link_info *info,
1283 const char *name,
1284 bfd *abfd,
1285 asection *section,
1286 bfd_vma address,
1287 bfd_boolean error)
1288 {
1289 static char *error_name;
1290 static unsigned int error_count;
1291
1292 #define MAX_ERRORS_IN_A_ROW 5
1293
1294 if (info->ignore_hash != NULL
1295 && bfd_hash_lookup (info->ignore_hash, name, FALSE, FALSE) != NULL)
1296 return TRUE;
1297
1298 if (config.warn_once)
1299 {
1300 /* Only warn once about a particular undefined symbol. */
1301 add_ignoresym (info, name);
1302 }
1303
1304 /* We never print more than a reasonable number of errors in a row
1305 for a single symbol. */
1306 if (error_name != NULL
1307 && strcmp (name, error_name) == 0)
1308 ++error_count;
1309 else
1310 {
1311 error_count = 0;
1312 if (error_name != NULL)
1313 free (error_name);
1314 error_name = xstrdup (name);
1315 }
1316
1317 if (section != NULL)
1318 {
1319 if (error_count < MAX_ERRORS_IN_A_ROW)
1320 {
1321 if (error)
1322 einfo (_("%X%C: undefined reference to `%T'\n"),
1323 abfd, section, address, name);
1324 else
1325 einfo (_("%C: warning: undefined reference to `%T'\n"),
1326 abfd, section, address, name);
1327 }
1328 else if (error_count == MAX_ERRORS_IN_A_ROW)
1329 {
1330 if (error)
1331 einfo (_("%X%D: more undefined references to `%T' follow\n"),
1332 abfd, section, address, name);
1333 else
1334 einfo (_("%D: warning: more undefined references to `%T' follow\n"),
1335 abfd, section, address, name);
1336 }
1337 else if (error)
1338 einfo ("%X");
1339 }
1340 else
1341 {
1342 if (error_count < MAX_ERRORS_IN_A_ROW)
1343 {
1344 if (error)
1345 einfo (_("%X%B: undefined reference to `%T'\n"),
1346 abfd, name);
1347 else
1348 einfo (_("%B: warning: undefined reference to `%T'\n"),
1349 abfd, name);
1350 }
1351 else if (error_count == MAX_ERRORS_IN_A_ROW)
1352 {
1353 if (error)
1354 einfo (_("%X%B: more undefined references to `%T' follow\n"),
1355 abfd, name);
1356 else
1357 einfo (_("%B: warning: more undefined references to `%T' follow\n"),
1358 abfd, name);
1359 }
1360 else if (error)
1361 einfo ("%X");
1362 }
1363
1364 return TRUE;
1365 }
1366
1367 /* Counter to limit the number of relocation overflow error messages
1368 to print. Errors are printed as it is decremented. When it's
1369 called and the counter is zero, a final message is printed
1370 indicating more relocations were omitted. When it gets to -1, no
1371 such errors are printed. If it's initially set to a value less
1372 than -1, all such errors will be printed (--verbose does this). */
1373
1374 int overflow_cutoff_limit = 10;
1375
1376 /* This is called when a reloc overflows. */
1377
1378 static bfd_boolean
reloc_overflow(struct bfd_link_info * info,struct bfd_link_hash_entry * entry,const char * name,const char * reloc_name,bfd_vma addend,bfd * abfd,asection * section,bfd_vma address)1379 reloc_overflow (struct bfd_link_info *info,
1380 struct bfd_link_hash_entry *entry,
1381 const char *name,
1382 const char *reloc_name,
1383 bfd_vma addend,
1384 bfd *abfd,
1385 asection *section,
1386 bfd_vma address)
1387 {
1388 if (overflow_cutoff_limit == -1)
1389 return TRUE;
1390
1391 einfo ("%X%H:", abfd, section, address);
1392
1393 if (overflow_cutoff_limit >= 0
1394 && overflow_cutoff_limit-- == 0)
1395 {
1396 einfo (_(" additional relocation overflows omitted from the output\n"));
1397 return TRUE;
1398 }
1399
1400 if (entry)
1401 {
1402 while (entry->type == bfd_link_hash_indirect
1403 || entry->type == bfd_link_hash_warning)
1404 entry = entry->u.i.link;
1405 switch (entry->type)
1406 {
1407 case bfd_link_hash_undefined:
1408 case bfd_link_hash_undefweak:
1409 einfo (_(" relocation truncated to fit: %s against undefined symbol `%T'"),
1410 reloc_name, entry->root.string);
1411 break;
1412 case bfd_link_hash_defined:
1413 case bfd_link_hash_defweak:
1414 einfo (_(" relocation truncated to fit: %s against symbol `%T' defined in %A section in %B"),
1415 reloc_name, entry->root.string,
1416 entry->u.def.section,
1417 entry->u.def.section == bfd_abs_section_ptr
1418 ? info->output_bfd : entry->u.def.section->owner);
1419 break;
1420 default:
1421 abort ();
1422 break;
1423 }
1424 }
1425 else
1426 einfo (_(" relocation truncated to fit: %s against `%T'"),
1427 reloc_name, name);
1428 if (addend != 0)
1429 einfo ("+%v", addend);
1430 einfo ("\n");
1431 return TRUE;
1432 }
1433
1434 /* This is called when a dangerous relocation is made. */
1435
1436 static bfd_boolean
reloc_dangerous(struct bfd_link_info * info ATTRIBUTE_UNUSED,const char * message,bfd * abfd,asection * section,bfd_vma address)1437 reloc_dangerous (struct bfd_link_info *info ATTRIBUTE_UNUSED,
1438 const char *message,
1439 bfd *abfd,
1440 asection *section,
1441 bfd_vma address)
1442 {
1443 einfo (_("%X%H: dangerous relocation: %s\n"),
1444 abfd, section, address, message);
1445 return TRUE;
1446 }
1447
1448 /* This is called when a reloc is being generated attached to a symbol
1449 that is not being output. */
1450
1451 static bfd_boolean
unattached_reloc(struct bfd_link_info * info ATTRIBUTE_UNUSED,const char * name,bfd * abfd,asection * section,bfd_vma address)1452 unattached_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED,
1453 const char *name,
1454 bfd *abfd,
1455 asection *section,
1456 bfd_vma address)
1457 {
1458 einfo (_("%X%H: reloc refers to symbol `%T' which is not being output\n"),
1459 abfd, section, address, name);
1460 return TRUE;
1461 }
1462
1463 /* This is called if link_info.notice_all is set, or when a symbol in
1464 link_info.notice_hash is found. Symbols are put in notice_hash
1465 using the -y option, while notice_all is set if the --cref option
1466 has been supplied, or if there are any NOCROSSREFS sections in the
1467 linker script; and if plugins are active, since they need to monitor
1468 all references from non-IR files. */
1469
1470 static bfd_boolean
notice(struct bfd_link_info * info,struct bfd_link_hash_entry * h,struct bfd_link_hash_entry * inh ATTRIBUTE_UNUSED,bfd * abfd,asection * section,bfd_vma value,flagword flags ATTRIBUTE_UNUSED)1471 notice (struct bfd_link_info *info,
1472 struct bfd_link_hash_entry *h,
1473 struct bfd_link_hash_entry *inh ATTRIBUTE_UNUSED,
1474 bfd *abfd,
1475 asection *section,
1476 bfd_vma value,
1477 flagword flags ATTRIBUTE_UNUSED)
1478 {
1479 const char *name;
1480
1481 if (h == NULL)
1482 {
1483 if (command_line.cref || nocrossref_list != NULL)
1484 return handle_asneeded_cref (abfd, (enum notice_asneeded_action) value);
1485 return TRUE;
1486 }
1487
1488 name = h->root.string;
1489 if (info->notice_hash != NULL
1490 && bfd_hash_lookup (info->notice_hash, name, FALSE, FALSE) != NULL)
1491 {
1492 if (bfd_is_und_section (section))
1493 einfo ("%B: reference to %s\n", abfd, name);
1494 else
1495 einfo ("%B: definition of %s\n", abfd, name);
1496 }
1497
1498 if (command_line.cref || nocrossref_list != NULL)
1499 add_cref (name, abfd, section, value);
1500
1501 return TRUE;
1502 }
1503