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