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