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