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