/* Linker file opening and searching.
- Copyright (C) 1991-2023 Free Software Foundation, Inc.
+ Copyright (C) 1991-2024 Free Software Foundation, Inc.
This file is part of the GNU Binutils.
#include "plugin.h"
#endif /* BFD_SUPPORTS_PLUGINS */
-bool ldfile_assumed_script = false;
-const char *ldfile_output_machine_name = "";
-unsigned long ldfile_output_machine;
-enum bfd_architecture ldfile_output_architecture;
-search_dirs_type *search_head;
-
#ifdef VMS
static char *slash = "";
#else
struct search_arch *next;
} search_arch_type;
+bool ldfile_assumed_script = false;
+const char * ldfile_output_machine_name = "";
+unsigned long ldfile_output_machine;
+enum bfd_architecture ldfile_output_architecture;
+search_dirs_type * search_head;
+
static search_dirs_type **search_tail_ptr = &search_head;
static search_arch_type *search_arch_head;
static search_arch_type **search_arch_tail_ptr = &search_arch_head;
}
/* Adds NAME to the library search path.
- Makes a copy of NAME using xmalloc(). */
+ Makes a copy of NAME using xmalloc().
+ Returns a pointer to the newly created search_dirs_type structure
+ or NULL if there was a problem. */
-void
-ldfile_add_library_path (const char *name, bool cmdline)
+search_dirs_type *
+ldfile_add_library_path (const char *name, enum search_dir_source source)
{
search_dirs_type *new_dirs;
- if (!cmdline && config.only_cmd_line_lib_dirs)
- return;
+ if (source != search_dir_cmd_line && config.only_cmd_line_lib_dirs)
+ return NULL;
new_dirs = (search_dirs_type *) xmalloc (sizeof (search_dirs_type));
- new_dirs->next = NULL;
- new_dirs->cmdline = cmdline;
- *search_tail_ptr = new_dirs;
- search_tail_ptr = &new_dirs->next;
+ new_dirs->source = source;
/* If a directory is marked as honoring sysroot, prepend the sysroot path
now. */
new_dirs->name = concat (ld_sysroot, name + strlen ("$SYSROOT"), (const char *) NULL);
else
new_dirs->name = xstrdup (name);
+
+ /* Accumulate script and command line sourced
+ search paths at the end of the current list. */
+#if BFD_SUPPORTS_PLUGINS
+ /* PR 31904: But put plugin sourced paths at the start of the list. */
+ if (source == search_dir_plugin)
+ {
+ new_dirs->next = search_head;
+ search_head = new_dirs;
+ }
+ else
+#endif
+ {
+ new_dirs->next = NULL;
+ *search_tail_ptr = new_dirs;
+ search_tail_ptr = &new_dirs->next;
+ }
+
+ return new_dirs;
}
/* Try to open a BFD for a lang_input_statement. */
return false;
}
- /* PR 30568: Do not track lto generated temporary object files. */
+ /* PR 30568: Do not track plugin generated object files. */
#if BFD_SUPPORTS_PLUGINS
- if (!entry->flags.lto_output)
+ if (entry->plugin != NULL)
#endif
track_dependency_files (attempt);
entry->the_bfd->is_linker_input = 1;
#if BFD_SUPPORTS_PLUGINS
- if (entry->flags.lto_output)
+ if (entry->plugin != NULL)
entry->the_bfd->lto_output = 1;
#endif
{
char *string;
+#if BFD_SUPPORTS_PLUGINS
+ /* PR 31904: Only check a plugin sourced search
+ directory if the file is from the same plugin. */
+ if (search->source == search_dir_plugin
+ && entry->plugin != search->plugin)
+ continue;
+#endif
+
if (entry->flags.dynamic && !bfd_link_relocatable (&link_info))
{
if (ldemul_open_dynamic_archive (arch, search, entry))
result = fopen (name, "r");
if (result != NULL)
- *sysrooted = is_sysrooted_pathname (name);
+ {
+ *sysrooted = is_sysrooted_pathname (name);
+ track_dependency_files (name);
+ }
if (verbose)
{
{
search_dirs_type **save_tail_ptr = search_tail_ptr;
search_tail_ptr = &script_search;
- ldfile_add_library_path (script_dir, true);
+ (void) ldfile_add_library_path (script_dir, search_dir_cmd_line);
search_tail_ptr = save_tail_ptr;
}
}
search != NULL;
search = search->next)
{
+#if BFD_SUPPORTS_PLUGINS
+ /* Do not search for linker commands in plugin sourced search directories. */
+ if (search->source == search_dir_plugin)
+ continue;
+#endif
path = concat (search->name, slash, name, (const char *) NULL);
result = try_open (path, sysrooted);
free (path);
return result;
}
-enum script_open_style {
- script_nonT,
- script_T,
- script_defaultT
-};
-
-struct script_name_list
-{
- struct script_name_list *next;
- enum script_open_style open_how;
- char name[1];
-};
-
+struct script_name_list *processed_scripts = NULL;
/* Open command file NAME. */
static void
{
FILE *ldlex_input_stack;
bool sysrooted;
- static struct script_name_list *processed_scripts = NULL;
struct script_name_list *script;
size_t len;
return;
}
- track_dependency_files (name);
-
lex_push_file (ldlex_input_stack, name, sysrooted);
lineno = 1;