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