Change regcache list to be an hash map
[deliverable/binutils-gdb.git] / ld / ldfile.c
CommitLineData
a9998805 1/* Linker file opening and searching.
b3adc24a 2 Copyright (C) 1991-2020 Free Software Foundation, Inc.
252b5132 3
f96b4a7b 4 This file is part of the GNU Binutils.
252b5132 5
f96b4a7b 6 This program is free software; you can redistribute it and/or modify
3fe38064 7 it under the terms of the GNU General Public License as published by
f96b4a7b
NC
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
252b5132 10
f96b4a7b 11 This program is distributed in the hope that it will be useful,
3fe38064
NC
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.
252b5132 15
3fe38064 16 You should have received a copy of the GNU General Public License
f96b4a7b
NC
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
252b5132 20
252b5132 21#include "sysdep.h"
3db64b00 22#include "bfd.h"
252b5132 23#include "bfdlink.h"
1ff6de03 24#include "ctf-api.h"
3882b010 25#include "safe-ctype.h"
252b5132
RH
26#include "ld.h"
27#include "ldmisc.h"
28#include "ldexp.h"
29#include "ldlang.h"
30#include "ldfile.h"
31#include "ldmain.h"
df2a7313 32#include <ldgram.h>
252b5132
RH
33#include "ldlex.h"
34#include "ldemul.h"
d1b2b2dc 35#include "libiberty.h"
3fe38064 36#include "filenames.h"
0381901e 37#if BFD_SUPPORTS_PLUGINS
5d3236ee
DK
38#include "plugin-api.h"
39#include "plugin.h"
0381901e 40#endif /* BFD_SUPPORTS_PLUGINS */
252b5132 41
0aa7f586
AM
42bfd_boolean ldfile_assumed_script = FALSE;
43const char *ldfile_output_machine_name = "";
252b5132
RH
44unsigned long ldfile_output_machine;
45enum bfd_architecture ldfile_output_architecture;
0aa7f586 46search_dirs_type *search_head;
252b5132 47
252b5132 48#ifdef VMS
0aa7f586 49static char *slash = "";
252b5132 50#else
0aa7f586
AM
51#if defined (_WIN32) && !defined (__CYGWIN32__)
52static char *slash = "\\";
252b5132 53#else
0aa7f586 54static char *slash = "/";
252b5132
RH
55#endif
56#endif
252b5132 57
3fe38064
NC
58typedef struct search_arch
59{
4de2d33d 60 char *name;
252b5132
RH
61 struct search_arch *next;
62} search_arch_type;
63
3fe38064 64static search_dirs_type **search_tail_ptr = &search_head;
252b5132
RH
65static search_arch_type *search_arch_head;
66static search_arch_type **search_arch_tail_ptr = &search_arch_head;
4de2d33d 67
3fe38064
NC
68/* Test whether a pathname, after canonicalization, is the same or a
69 sub-directory of the sysroot directory. */
70
71static bfd_boolean
f4a23d42 72is_sysrooted_pathname (const char *name)
3fe38064 73{
66be1055 74 char *realname;
3fe38064
NC
75 int len;
76 bfd_boolean result;
77
66be1055 78 if (ld_canon_sysroot == NULL)
3fe38064 79 return FALSE;
5e2f1575 80
66be1055 81 realname = lrealpath (name);
3fe38064 82 len = strlen (realname);
66be1055 83 result = FALSE;
f4a23d42
AM
84 if (len > ld_canon_sysroot_len
85 && IS_DIR_SEPARATOR (realname[ld_canon_sysroot_len]))
66be1055 86 {
66be1055 87 realname[ld_canon_sysroot_len] = '\0';
f4a23d42 88 result = FILENAME_CMP (ld_canon_sysroot, realname) == 0;
66be1055 89 }
3fe38064 90
66be1055 91 free (realname);
3fe38064
NC
92 return result;
93}
252b5132 94
5ed6aba4
NC
95/* Adds NAME to the library search path.
96 Makes a copy of NAME using xmalloc(). */
97
252b5132 98void
1579bae1 99ldfile_add_library_path (const char *name, bfd_boolean cmdline)
252b5132 100{
d3ce72d0 101 search_dirs_type *new_dirs;
252b5132 102
361b220e
CD
103 if (!cmdline && config.only_cmd_line_lib_dirs)
104 return;
105
d3ce72d0
NC
106 new_dirs = (search_dirs_type *) xmalloc (sizeof (search_dirs_type));
107 new_dirs->next = NULL;
108 new_dirs->cmdline = cmdline;
109 *search_tail_ptr = new_dirs;
110 search_tail_ptr = &new_dirs->next;
9c8ebd6a
DJ
111
112 /* If a directory is marked as honoring sysroot, prepend the sysroot path
113 now. */
5ed6aba4 114 if (name[0] == '=')
f4a23d42 115 new_dirs->name = concat (ld_sysroot, name + 1, (const char *) NULL);
3aa2d05a
NC
116 else if (CONST_STRNEQ (name, "$SYSROOT"))
117 new_dirs->name = concat (ld_sysroot, name + strlen ("$SYSROOT"), (const char *) NULL);
e3f2db7f 118 else
f4a23d42 119 new_dirs->name = xstrdup (name);
252b5132
RH
120}
121
122/* Try to open a BFD for a lang_input_statement. */
123
b34976b6 124bfd_boolean
1579bae1
AM
125ldfile_try_open_bfd (const char *attempt,
126 lang_input_statement_type *entry)
252b5132
RH
127{
128 entry->the_bfd = bfd_openr (attempt, entry->target);
129
cd6f1cf3 130 if (verbose)
252b5132
RH
131 {
132 if (entry->the_bfd == NULL)
133 info_msg (_("attempt to open %s failed\n"), attempt);
134 else
135 info_msg (_("attempt to open %s succeeded\n"), attempt);
136 }
137
b90d1146 138 if (entry->the_bfd == NULL)
252b5132
RH
139 {
140 if (bfd_get_error () == bfd_error_invalid_target)
141 einfo (_("%F%P: invalid BFD target `%s'\n"), entry->target);
b34976b6 142 return FALSE;
252b5132 143 }
b90d1146 144
f37b21b4
RM
145 track_dependency_files (attempt);
146
4a114e3e
L
147 /* Linker needs to decompress sections. */
148 entry->the_bfd->flags |= BFD_DECOMPRESS;
149
f6fe1ccd
L
150 /* This is a linker input BFD. */
151 entry->the_bfd->is_linker_input = 1;
152
0381901e 153#if BFD_SUPPORTS_PLUGINS
ce875075
AM
154 if (entry->flags.lto_output)
155 entry->the_bfd->lto_output = 1;
156#endif
157
b90d1146
ILT
158 /* If we are searching for this file, see if the architecture is
159 compatible with the output file. If it isn't, keep searching.
160 If we can't open the file as an object file, stop the search
6c0c5b1e 161 here. If we are statically linking, ensure that we don't link
5d3236ee
DK
162 a dynamic object.
163
164 In the code below, it's OK to exit early if the check fails,
165 closing the checked BFD and returning FALSE, but if the BFD
166 checks out compatible, do not exit early returning TRUE, or
167 the plugins will not get a chance to claim the file. */
b90d1146 168
66be1055 169 if (entry->flags.search_dirs || !entry->flags.dynamic)
b90d1146
ILT
170 {
171 bfd *check;
172
173 if (bfd_check_format (entry->the_bfd, bfd_archive))
174 check = bfd_openr_next_archived_file (entry->the_bfd, NULL);
175 else
176 check = entry->the_bfd;
177
a9998805 178 if (check != NULL)
b90d1146 179 {
0aa7f586 180 if (!bfd_check_format (check, bfd_object))
599917b8
JJ
181 {
182 if (check == entry->the_bfd
66be1055 183 && entry->flags.search_dirs
599917b8 184 && bfd_get_error () == bfd_error_file_not_recognized
0aa7f586 185 && !ldemul_unrecognized_file (entry))
599917b8
JJ
186 {
187 int token, skip = 0;
188 char *arg, *arg1, *arg2, *arg3;
189 extern FILE *yyin;
190
191 /* Try to interpret the file as a linker script. */
82d7a6f4 192 ldfile_open_command_file (attempt);
b34976b6
AM
193
194 ldfile_assumed_script = TRUE;
599917b8
JJ
195 parser_input = input_selected;
196 ldlex_both ();
197 token = INPUT_SCRIPT;
198 while (token != 0)
199 {
200 switch (token)
201 {
202 case OUTPUT_FORMAT:
203 if ((token = yylex ()) != '(')
204 continue;
205 if ((token = yylex ()) != NAME)
206 continue;
207 arg1 = yylval.name;
208 arg2 = NULL;
209 arg3 = NULL;
210 token = yylex ();
211 if (token == ',')
212 {
213 if ((token = yylex ()) != NAME)
214 {
215 free (arg1);
216 continue;
217 }
218 arg2 = yylval.name;
219 if ((token = yylex ()) != ','
220 || (token = yylex ()) != NAME)
221 {
222 free (arg1);
223 free (arg2);
224 continue;
225 }
226 arg3 = yylval.name;
227 token = yylex ();
228 }
229 if (token == ')')
230 {
231 switch (command_line.endian)
232 {
233 default:
234 case ENDIAN_UNSET:
235 arg = arg1; break;
236 case ENDIAN_BIG:
237 arg = arg2 ? arg2 : arg1; break;
238 case ENDIAN_LITTLE:
239 arg = arg3 ? arg3 : arg1; break;
240 }
241 if (strcmp (arg, lang_get_output_target ()) != 0)
242 skip = 1;
243 }
244 free (arg1);
5e2ab612
AM
245 free (arg2);
246 free (arg3);
599917b8
JJ
247 break;
248 case NAME:
249 case LNAME:
250 case VERS_IDENTIFIER:
251 case VERS_TAG:
252 free (yylval.name);
253 break;
254 case INT:
5e2ab612 255 free (yylval.bigint.str);
599917b8 256 break;
5e2f1575 257 }
599917b8
JJ
258 token = yylex ();
259 }
4f39e302 260 ldlex_popstate ();
b34976b6 261 ldfile_assumed_script = FALSE;
599917b8
JJ
262 fclose (yyin);
263 yyin = NULL;
264 if (skip)
265 {
fe7929ce
AM
266 if (command_line.warn_search_mismatch)
267 einfo (_("%P: skipping incompatible %s "
268 "when searching for %s\n"),
269 attempt, entry->local_sym_name);
599917b8
JJ
270 bfd_close (entry->the_bfd);
271 entry->the_bfd = NULL;
b34976b6 272 return FALSE;
599917b8
JJ
273 }
274 }
5d3236ee 275 goto success;
599917b8 276 }
f1f0d9ab 277
66be1055 278 if (!entry->flags.dynamic && (entry->the_bfd->flags & DYNAMIC) != 0)
6c0c5b1e
AM
279 {
280 einfo (_("%F%P: attempted static link of dynamic object `%s'\n"),
281 attempt);
282 bfd_close (entry->the_bfd);
283 entry->the_bfd = NULL;
284 return FALSE;
285 }
286
66be1055 287 if (entry->flags.search_dirs
f13a99db 288 && !bfd_arch_get_compatible (check, link_info.output_bfd,
6c0c5b1e 289 command_line.accept_unknown_input_arch)
312b768e 290 /* XCOFF archives can have 32 and 64 bit objects. */
0aa7f586
AM
291 && !(bfd_get_flavour (check) == bfd_target_xcoff_flavour
292 && (bfd_get_flavour (link_info.output_bfd)
293 == bfd_target_xcoff_flavour)
294 && bfd_check_format (entry->the_bfd, bfd_archive)))
a9998805 295 {
fe7929ce
AM
296 if (command_line.warn_search_mismatch)
297 einfo (_("%P: skipping incompatible %s "
298 "when searching for %s\n"),
299 attempt, entry->local_sym_name);
a9998805
ILT
300 bfd_close (entry->the_bfd);
301 entry->the_bfd = NULL;
b34976b6 302 return FALSE;
a9998805 303 }
b90d1146
ILT
304 }
305 }
dc1e8a47 306 success:
0381901e 307#if BFD_SUPPORTS_PLUGINS
5d3236ee
DK
308 /* If plugins are active, they get first chance to claim
309 any successfully-opened input file. We skip archives
310 here; the plugin wants us to offer it the individual
311 members when we enumerate them, not the whole file. We
312 also ignore corefiles, because that's just weird. It is
313 a needed side-effect of calling bfd_check_format with
314 bfd_object that it sets the bfd's arch and mach, which
315 will be needed when and if we want to bfd_create a new
316 one using this one as a template. */
1d5b29cf
L
317 if (link_info.lto_plugin_active
318 && !no_more_claiming
319 && bfd_check_format (entry->the_bfd, bfd_object))
35a1e5f3 320 plugin_maybe_claim (entry);
0381901e 321#endif /* BFD_SUPPORTS_PLUGINS */
b90d1146 322
5d3236ee
DK
323 /* It opened OK, the format checked out, and the plugins have had
324 their chance to claim it, so this is success. */
b34976b6 325 return TRUE;
252b5132
RH
326}
327
328/* Search for and open the file specified by ENTRY. If it is an
329 archive, use ARCH, LIB and SUFFIX to modify the file name. */
330
b34976b6 331bfd_boolean
1579bae1
AM
332ldfile_open_file_search (const char *arch,
333 lang_input_statement_type *entry,
334 const char *lib,
335 const char *suffix)
252b5132
RH
336{
337 search_dirs_type *search;
338
339 /* If this is not an archive, try to open it in the current
340 directory first. */
0aa7f586 341 if (!entry->flags.maybe_archive)
252b5132 342 {
66be1055 343 if (entry->flags.sysrooted && IS_ABSOLUTE_PATH (entry->filename))
e3f2db7f
AO
344 {
345 char *name = concat (ld_sysroot, entry->filename,
346 (const char *) NULL);
347 if (ldfile_try_open_bfd (name, entry))
348 {
349 entry->filename = name;
350 return TRUE;
351 }
352 free (name);
353 }
354 else if (ldfile_try_open_bfd (entry->filename, entry))
f4a23d42 355 return TRUE;
3fe38064
NC
356
357 if (IS_ABSOLUTE_PATH (entry->filename))
358 return FALSE;
252b5132
RH
359 }
360
1579bae1 361 for (search = search_head; search != NULL; search = search->next)
252b5132
RH
362 {
363 char *string;
364
0e1862bb 365 if (entry->flags.dynamic && !bfd_link_relocatable (&link_info))
252b5132
RH
366 {
367 if (ldemul_open_dynamic_archive (arch, search, entry))
f4a23d42 368 return TRUE;
252b5132
RH
369 }
370
d4ae5fb0 371 if (entry->flags.maybe_archive && !entry->flags.full_name_provided)
a26cc967
AM
372 string = concat (search->name, slash, lib, entry->filename,
373 arch, suffix, (const char *) NULL);
252b5132 374 else
a26cc967
AM
375 string = concat (search->name, slash, entry->filename,
376 (const char *) 0);
252b5132
RH
377
378 if (ldfile_try_open_bfd (string, entry))
379 {
b90d1146 380 entry->filename = string;
b34976b6 381 return TRUE;
252b5132
RH
382 }
383
384 free (string);
385 }
386
b34976b6 387 return FALSE;
252b5132
RH
388}
389
c4b78195
NC
390/* Open the input file specified by ENTRY.
391 PR 4437: Do not stop on the first missing file, but
392 continue processing other input files in case there
393 are more errors to report. */
252b5132
RH
394
395void
1579bae1 396ldfile_open_file (lang_input_statement_type *entry)
252b5132
RH
397{
398 if (entry->the_bfd != NULL)
399 return;
400
0aa7f586 401 if (!entry->flags.search_dirs)
252b5132
RH
402 {
403 if (ldfile_try_open_bfd (entry->filename, entry))
404 return;
c4b78195 405
42627821 406 if (filename_cmp (entry->filename, entry->local_sym_name) != 0)
c4b78195 407 einfo (_("%P: cannot find %s (%s): %E\n"),
252b5132
RH
408 entry->filename, entry->local_sym_name);
409 else
c4b78195
NC
410 einfo (_("%P: cannot find %s: %E\n"), entry->local_sym_name);
411
66be1055
AM
412 entry->flags.missing_file = TRUE;
413 input_flags.missing_file = TRUE;
252b5132
RH
414 }
415 else
416 {
417 search_arch_type *arch;
b34976b6 418 bfd_boolean found = FALSE;
252b5132 419
16171946 420 /* If extra_search_path is set, entry->filename is a relative path.
f37b21b4
RM
421 Search the directory of the current linker script before searching
422 other paths. */
16171946 423 if (entry->extra_search_path)
f37b21b4
RM
424 {
425 char *path = concat (entry->extra_search_path, slash, entry->filename,
426 (const char *)0);
427 if (ldfile_try_open_bfd (path, entry))
428 {
429 entry->filename = path;
430 entry->flags.search_dirs = FALSE;
431 return;
432 }
16171946
FS
433
434 free (path);
f37b21b4 435 }
16171946
FS
436
437 /* Try to open <filename><suffix> or lib<filename><suffix>.a. */
1579bae1 438 for (arch = search_arch_head; arch != NULL; arch = arch->next)
252b5132 439 {
78f85fd7
L
440 found = ldfile_open_file_search (arch->name, entry, "lib", ".a");
441 if (found)
442 break;
252b5132 443#ifdef VMS
78f85fd7
L
444 found = ldfile_open_file_search (arch->name, entry, ":lib", ".a");
445 if (found)
446 break;
252b5132 447#endif
78f85fd7
L
448 found = ldemul_find_potential_libraries (arch->name, entry);
449 if (found)
450 break;
252b5132 451 }
4de2d33d 452
78f85fd7
L
453 /* If we have found the file, we don't need to search directories
454 again. */
455 if (found)
66be1055 456 entry->flags.search_dirs = FALSE;
c4b78195
NC
457 else
458 {
66be1055 459 if (entry->flags.sysrooted
3fe38064
NC
460 && ld_sysroot
461 && IS_ABSOLUTE_PATH (entry->local_sym_name))
c4b78195
NC
462 einfo (_("%P: cannot find %s inside %s\n"),
463 entry->local_sym_name, ld_sysroot);
464 else
465 einfo (_("%P: cannot find %s\n"), entry->local_sym_name);
77bf7b53
NC
466
467 /* PR 25747: Be kind to users who forgot to add the
468 "lib" prefix to their library when it was created. */
469 for (arch = search_arch_head; arch != NULL; arch = arch->next)
470 {
471 if (ldfile_open_file_search (arch->name, entry, "", ".a"))
472 {
473 const char * base = lbasename (entry->filename);
474
4f5bd885 475 einfo (_("%P: note to link with %s use -l:%s or rename it to lib%s\n"),
77bf7b53
NC
476 entry->filename, base, base);
477 bfd_close (entry->the_bfd);
478 entry->the_bfd = NULL;
479 break;
480 }
481 }
66be1055
AM
482 entry->flags.missing_file = TRUE;
483 input_flags.missing_file = TRUE;
c4b78195 484 }
252b5132
RH
485 }
486}
487
f4a23d42 488/* Try to open NAME. */
252b5132
RH
489
490static FILE *
f4a23d42 491try_open (const char *name, bfd_boolean *sysrooted)
252b5132
RH
492{
493 FILE *result;
252b5132
RH
494
495 result = fopen (name, "r");
4de2d33d 496
f4a23d42
AM
497 if (result != NULL)
498 *sysrooted = is_sysrooted_pathname (name);
499
cd6f1cf3 500 if (verbose)
252b5132
RH
501 {
502 if (result == NULL)
503 info_msg (_("cannot find script file %s\n"), name);
504 else
505 info_msg (_("opened script file %s\n"), name);
506 }
507
252b5132
RH
508 return result;
509}
510
a8caa245
AM
511/* Return TRUE iff directory DIR contains an "ldscripts" subdirectory. */
512
513static bfd_boolean
514check_for_scripts_dir (char *dir)
515{
516 char *buf;
517 struct stat s;
518 bfd_boolean res;
519
520 buf = concat (dir, "/ldscripts", (const char *) NULL);
521 res = stat (buf, &s) == 0 && S_ISDIR (s.st_mode);
522 free (buf);
523 return res;
524}
525
526/* Return the default directory for finding script files.
527 We look for the "ldscripts" directory in:
528
529 SCRIPTDIR (passed from Makefile)
530 (adjusted according to the current location of the binary)
c38b10fa 531 the dir where this program is (for using it from the build tree). */
a8caa245
AM
532
533static char *
534find_scripts_dir (void)
535{
c38b10fa 536 char *dir;
a8caa245
AM
537
538 dir = make_relative_prefix (program_name, BINDIR, SCRIPTDIR);
539 if (dir)
540 {
541 if (check_for_scripts_dir (dir))
542 return dir;
543 free (dir);
544 }
545
546 dir = make_relative_prefix (program_name, TOOLBINDIR, SCRIPTDIR);
547 if (dir)
548 {
549 if (check_for_scripts_dir (dir))
550 return dir;
551 free (dir);
552 }
553
a8caa245 554 /* Look for "ldscripts" in the dir where our binary is. */
c38b10fa
AM
555 dir = make_relative_prefix (program_name, ".", ".");
556 if (dir)
557 {
558 if (check_for_scripts_dir (dir))
559 return dir;
560 free (dir);
561 }
a8caa245 562
a8caa245
AM
563 return NULL;
564}
565
8c3e16f4
L
566/* If DEFAULT_ONLY is false, try to open NAME; if that fails, look for
567 it in directories specified with -L, then in the default script
f4a23d42
AM
568 directory. If DEFAULT_ONLY is true, the search is restricted to
569 the default script location. */
252b5132 570
279e75dc 571static FILE *
f4a23d42
AM
572ldfile_find_command_file (const char *name,
573 bfd_boolean default_only,
574 bfd_boolean *sysrooted)
252b5132
RH
575{
576 search_dirs_type *search;
32252ac1 577 FILE *result = NULL;
f4a23d42 578 char *path;
a8caa245 579 static search_dirs_type *script_search;
252b5132 580
8c3e16f4
L
581 if (!default_only)
582 {
583 /* First try raw name. */
f4a23d42 584 result = try_open (name, sysrooted);
8c3e16f4
L
585 if (result != NULL)
586 return result;
587 }
a8caa245
AM
588
589 if (!script_search)
1c64c4ed 590 {
a8caa245
AM
591 char *script_dir = find_scripts_dir ();
592 if (script_dir)
1c64c4ed 593 {
a8caa245
AM
594 search_dirs_type **save_tail_ptr = search_tail_ptr;
595 search_tail_ptr = &script_search;
596 ldfile_add_library_path (script_dir, TRUE);
597 search_tail_ptr = save_tail_ptr;
1c64c4ed 598 }
a8caa245
AM
599 }
600
7d24f02c
KH
601 /* Temporarily append script_search to the path list so that the
602 paths specified with -L will be searched first. */
603 *search_tail_ptr = script_search;
604
a8caa245 605 /* Try now prefixes. */
7d24f02c
KH
606 for (search = default_only ? script_search : search_head;
607 search != NULL;
608 search = search->next)
a8caa245 609 {
f4a23d42
AM
610 path = concat (search->name, slash, name, (const char *) NULL);
611 result = try_open (path, sysrooted);
612 free (path);
a8caa245
AM
613 if (result)
614 break;
252b5132 615 }
4de2d33d 616
7d24f02c
KH
617 /* Restore the original path list. */
618 *search_tail_ptr = NULL;
619
252b5132
RH
620 return result;
621}
622
82d7a6f4
AM
623enum script_open_style {
624 script_nonT,
625 script_T,
626 script_defaultT
627};
628
629struct script_name_list
630{
631 struct script_name_list *next;
632 enum script_open_style open_how;
633 char name[1];
634};
635
7d24f02c
KH
636/* Open command file NAME. */
637
638static void
82d7a6f4 639ldfile_open_command_file_1 (const char *name, enum script_open_style open_how)
252b5132
RH
640{
641 FILE *ldlex_input_stack;
f4a23d42 642 bfd_boolean sysrooted;
82d7a6f4
AM
643 static struct script_name_list *processed_scripts = NULL;
644 struct script_name_list *script;
645 size_t len;
f4a23d42 646
82d7a6f4
AM
647 /* PR 24576: Catch the case where the user has accidentally included
648 the same linker script twice. */
649 for (script = processed_scripts; script != NULL; script = script->next)
6ec6968b 650 {
82d7a6f4
AM
651 if ((open_how != script_nonT || script->open_how != script_nonT)
652 && strcmp (name, script->name) == 0)
6ec6968b 653 {
82d7a6f4
AM
654 einfo (_("%F%P: error: linker script file '%s'"
655 " appears multiple times\n"), name);
656 return;
6ec6968b 657 }
6ec6968b
NC
658 }
659
82d7a6f4
AM
660 /* FIXME: This memory is never freed, but that should not really matter.
661 It will be released when the linker exits, and it is unlikely to ever
662 be more than a few tens of bytes. */
663 len = strlen (name);
664 script = xmalloc (sizeof (*script) + len);
665 script->next = processed_scripts;
666 script->open_how = open_how;
667 memcpy (script->name, name, len + 1);
668 processed_scripts = script;
669
670 ldlex_input_stack = ldfile_find_command_file (name,
671 open_how == script_defaultT,
672 &sysrooted);
1579bae1 673 if (ldlex_input_stack == NULL)
1c64c4ed
NC
674 {
675 bfd_set_error (bfd_error_system_call);
df5f2391 676 einfo (_("%F%P: cannot open linker script file %s: %E\n"), name);
3ab6909a 677 return;
1c64c4ed 678 }
4de2d33d 679
f37b21b4
RM
680 track_dependency_files (name);
681
f4a23d42 682 lex_push_file (ldlex_input_stack, name, sysrooted);
4de2d33d 683
252b5132 684 lineno = 1;
b7a26f91 685
b9a8de1e 686 saved_script_handle = ldlex_input_stack;
252b5132
RH
687}
688
7d24f02c
KH
689/* Open command file NAME in the current directory, -L directories,
690 the default script location, in that order. */
691
692void
693ldfile_open_command_file (const char *name)
694{
82d7a6f4 695 ldfile_open_command_file_1 (name, script_nonT);
6ec6968b
NC
696}
697
698void
699ldfile_open_script_file (const char *name)
700{
82d7a6f4 701 ldfile_open_command_file_1 (name, script_T);
7d24f02c
KH
702}
703
704/* Open command file NAME at the default script location. */
705
706void
707ldfile_open_default_command_file (const char *name)
708{
82d7a6f4 709 ldfile_open_command_file_1 (name, script_defaultT);
7d24f02c
KH
710}
711
252b5132 712void
1579bae1 713ldfile_add_arch (const char *in_name)
252b5132 714{
d1b2b2dc 715 char *name = xstrdup (in_name);
0aa7f586
AM
716 search_arch_type *new_arch
717 = (search_arch_type *) xmalloc (sizeof (search_arch_type));
252b5132
RH
718
719 ldfile_output_machine_name = in_name;
720
d3ce72d0
NC
721 new_arch->name = name;
722 new_arch->next = NULL;
252b5132
RH
723 while (*name)
724 {
3882b010 725 *name = TOLOWER (*name);
252b5132
RH
726 name++;
727 }
d3ce72d0
NC
728 *search_arch_tail_ptr = new_arch;
729 search_arch_tail_ptr = &new_arch->next;
252b5132
RH
730
731}
252b5132 732
89cdebba
KH
733/* Set the output architecture. */
734
252b5132 735void
5e2f1575 736ldfile_set_output_arch (const char *string, enum bfd_architecture defarch)
252b5132 737{
1c64c4ed
NC
738 const bfd_arch_info_type *arch = bfd_scan_arch (string);
739
740 if (arch)
741 {
742 ldfile_output_architecture = arch->arch;
743 ldfile_output_machine = arch->mach;
744 ldfile_output_machine_name = arch->printable_name;
745 }
5e2f1575
AM
746 else if (defarch != bfd_arch_unknown)
747 ldfile_output_architecture = defarch;
1c64c4ed 748 else
df5f2391 749 einfo (_("%F%P: cannot represent machine `%s'\n"), string);
252b5132 750}
This page took 0.901152 seconds and 4 git commands to generate.