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