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