ldfile.c 20 KB

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