From 161719466ac9ea5f186514312f6bce842181804f Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 22 Apr 2020 16:20:02 +0100 Subject: For relative paths in INPUT() and GROUP(), search the directory of the current linker script before searching other paths. PR ld/25806 * ldlang.h (struct lang_input_statement_struct): Add extra_search_path. * ldlang.c (current_input_file): New. (ldirname): New. (new_afile): Add from_filename parameter. Set extra_search_path. (lang_add_input_file): Pass current_input_file to new_afile. (load_symbols): Set current_input_file. --- ld/ldfile.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'ld/ldfile.c') diff --git a/ld/ldfile.c b/ld/ldfile.c index d98429d..53112c8 100644 --- a/ld/ldfile.c +++ b/ld/ldfile.c @@ -416,7 +416,24 @@ ldfile_open_file (lang_input_statement_type *entry) search_arch_type *arch; bfd_boolean found = FALSE; - /* Try to open or lib.a */ + /* If extra_search_path is set, entry->filename is a relative path. + Search the directory of the current linker script before searching + other paths. */ + if (entry->extra_search_path) + { + char *path = concat (entry->extra_search_path, slash, entry->filename, + (const char *)0); + if (ldfile_try_open_bfd (path, entry)) + { + entry->filename = path; + entry->flags.search_dirs = FALSE; + return; + } + + free (path); + } + + /* Try to open or lib.a. */ for (arch = search_arch_head; arch != NULL; arch = arch->next) { found = ldfile_open_file_search (arch->name, entry, "lib", ".a"); -- cgit v1.1