aboutsummaryrefslogtreecommitdiff
path: root/ld/ldfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'ld/ldfile.c')
-rw-r--r--ld/ldfile.c83
1 files changed, 43 insertions, 40 deletions
diff --git a/ld/ldfile.c b/ld/ldfile.c
index 75fd360..bed04fb 100644
--- a/ld/ldfile.c
+++ b/ld/ldfile.c
@@ -35,10 +35,8 @@
#include "libiberty.h"
#include "filenames.h"
#include <fnmatch.h>
-#if BFD_SUPPORTS_PLUGINS
-#include "plugin-api.h"
+#include "same-inode.h"
#include "plugin.h"
-#endif /* BFD_SUPPORTS_PLUGINS */
bool ldfile_assumed_script = false;
const char *ldfile_output_machine_name = "";
@@ -366,9 +364,7 @@ ldfile_try_open_bfd (const char *attempt,
}
/* PR 30568: Do not track lto generated temporary object files. */
-#if BFD_SUPPORTS_PLUGINS
if (!entry->flags.lto_output)
-#endif
track_dependency_files (attempt);
/* Linker needs to decompress sections. */
@@ -377,10 +373,8 @@ ldfile_try_open_bfd (const char *attempt,
/* This is a linker input BFD. */
entry->the_bfd->is_linker_input = 1;
-#if BFD_SUPPORTS_PLUGINS
if (entry->flags.lto_output)
entry->the_bfd->lto_output = 1;
-#endif
/* If we are searching for this file, see if the architecture is
compatible with the output file. If it isn't, keep searching.
@@ -518,7 +512,6 @@ ldfile_try_open_bfd (const char *attempt,
}
}
success:
-#if BFD_SUPPORTS_PLUGINS
/* If plugins are active, they get first chance to claim
any successfully-opened input file. We skip archives
here; the plugin wants us to offer it the individual
@@ -534,7 +527,6 @@ ldfile_try_open_bfd (const char *attempt,
plugin_maybe_claim (entry);
else
cmdline_check_object_only_section (entry->the_bfd, false);
-#endif /* BFD_SUPPORTS_PLUGINS */
/* It opened OK, the format checked out, and the plugins have had
their chance to claim it, so this is success. */
@@ -829,19 +821,26 @@ find_scripts_dir (void)
static FILE *
ldfile_find_command_file (const char *name,
- bool default_only,
+ enum script_open_style open_how,
bool *sysrooted)
{
search_dirs_type *search;
FILE *result = NULL;
- char *path;
+ char *path = NULL;
+ const char *filename = NULL;
+ struct script_name_list *script;
+ size_t len;
+ struct stat sbuf1;
- if (!default_only)
+ if (open_how != script_defaultT)
{
/* First try raw name. */
result = try_open (name, sysrooted);
if (result != NULL)
- return result;
+ {
+ filename = name;
+ goto success;
+ }
}
if (!script_search)
@@ -862,20 +861,47 @@ ldfile_find_command_file (const char *name,
*search_tail_ptr = script_search;
/* Try now prefixes. */
- for (search = default_only ? script_search : search_head;
+ for (search = open_how == script_defaultT ? script_search : search_head;
search != NULL;
search = search->next)
{
path = concat (search->name, slash, name, (const char *) NULL);
result = try_open (path, sysrooted);
- free (path);
if (result)
- break;
+ {
+ filename = path;
+ break;
+ }
}
/* Restore the original path list. */
*search_tail_ptr = NULL;
+ success:
+ /* PR 24576: Catch the case where the user has accidentally included
+ the same linker script twice. */
+ if (stat (filename, &sbuf1) == 0)
+ {
+ struct stat sbuf2;
+ for (script = processed_scripts;
+ script != NULL;
+ script = script->next)
+ if ((open_how != script_nonT || script->open_how != script_nonT)
+ && stat (script->name, &sbuf2) == 0
+ && SAME_INODE (sbuf1, sbuf2))
+ fatal (_("%P: error: linker script file '%s (%s)'"
+ " appears multiple times\n"), filename, script->name);
+ }
+
+ len = strlen (filename);
+ script = xmalloc (sizeof (*script) + len);
+ script->next = processed_scripts;
+ script->open_how = open_how;
+ memcpy (script->name, filename, len + 1);
+ processed_scripts = script;
+
+ free (path);
+
return result;
}
@@ -887,31 +913,8 @@ ldfile_open_command_file_1 (const char *name, enum script_open_style open_how)
{
FILE *ldlex_input_stack;
bool sysrooted;
- struct script_name_list *script;
- size_t len;
-
- /* PR 24576: Catch the case where the user has accidentally included
- the same linker script twice. */
- for (script = processed_scripts; script != NULL; script = script->next)
- {
- if ((open_how != script_nonT || script->open_how != script_nonT)
- && strcmp (name, script->name) == 0)
- {
- fatal (_("%P: error: linker script file '%s'"
- " appears multiple times\n"), name);
- return;
- }
- }
-
- len = strlen (name);
- script = xmalloc (sizeof (*script) + len);
- script->next = processed_scripts;
- script->open_how = open_how;
- memcpy (script->name, name, len + 1);
- processed_scripts = script;
- ldlex_input_stack = ldfile_find_command_file (name,
- open_how == script_defaultT,
+ ldlex_input_stack = ldfile_find_command_file (name, open_how,
&sysrooted);
if (ldlex_input_stack == NULL)
{