This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: Fix linker plugin support for gnu linker
"H.J. Lu" <hjl.tools@gmail.com> writes:
>> Please try commit bf235c35e8c2a386b13f034a8d3269b569b47acb
>> and let me know if it works for you.
>>
>
> Please use commit 5f61c105470197418bfc258ad9487a423e101bff.
That's better, thanks. crt0.o and the group files are being added
to the second link line now. However, crt0.o is being added as a
normal file whereas STARTUP allows a library-style search
(lang_input_file_is_search_file_enum). This means that the
second pass tries to open crt0.o in the current directory only.
Things seem to work with the additional patch below.
Tearing down and recreating the linker hash table also breaks
some assumptions in the MIPS backend, but those could be dealt
with separately.
To be clear, I don't really have an opinion on whether 1-pass
or 2-pass is better (or more specifically, whether one is better
than the other for the BFD linker). I just think that (a) we need
to consider this kind of -T usage when making the decision and
(b) the 2-pass approach does seem to solve the -T problem in a
fairly natural way.
Richard
* ldlang.c (lang_add_copy_of_input_file): New function.
(lang_startup): Add a search-file statement instead of a direct file.
(cmdline_get_stage2_input_files): Use lang_add_copy_of_input_file
to copy input statements.
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 43d8f4f..f93c3c8 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -1162,6 +1162,37 @@ lang_add_input_file (const char *name,
return new_afile (name, file_type, target, TRUE);
}
+static lang_input_statement_type *
+lang_add_copy_of_input_file (lang_input_statement_type *from)
+{
+ lang_input_statement_type *to;
+
+ to = (lang_input_statement_type *) new_stat (lang_input_statement, stat_ptr);
+ to->filename = from->filename;
+ to->local_sym_name = from->local_sym_name;
+ to->the_bfd = NULL;
+ to->next = NULL;
+ to->target = from->target;
+ to->maybe_archive = from->maybe_archive;
+ to->search_dirs_flag = from->search_dirs_flag;
+ to->sysrooted = from->sysrooted;
+ to->just_syms_flag = from->just_syms_flag;
+ to->dynamic = from->dynamic;
+ to->add_DT_NEEDED_for_dynamic = from->add_DT_NEEDED_for_dynamic;
+ to->add_DT_NEEDED_for_regular = from->add_DT_NEEDED_for_regular;
+ to->whole_archive = from->whole_archive;
+ to->stage1 = FALSE;
+ to->loaded = FALSE;
+ to->real = from->real;
+ to->missing_file = FALSE;
+ to->claimed = FALSE;
+
+ lang_statement_append (&input_file_chain,
+ (lang_statement_union_type *) to,
+ &to->next_real_file);
+ return to;
+}
+
struct out_section_hash_entry
{
struct bfd_hash_entry root;
@@ -6831,6 +6862,8 @@ lang_add_attribute (enum statement_enum attribute)
void
lang_startup (const char *name)
{
+ lang_input_statement_type *search;
+
if (startup_file != NULL)
{
einfo (_("%P%F: multiple STARTUP files\n"));
@@ -6840,7 +6873,8 @@ lang_startup (const char *name)
first_file->real = TRUE;
startup_file = name;
- cmdline_option_prepend (cmdline_is_file_enum, (void *) name);
+ search = new_afile (name, lang_input_file_is_search_file_enum, NULL, FALSE);
+ cmdline_option_prepend (cmdline_is_lang_input_statement_enum, search);
}
void
@@ -8162,18 +8196,7 @@ cmdline_get_stage2_input_files (void)
abort ();
case cmdline_is_lang_input_statement_enum:
if (!c->input_statement.input->claimed)
- {
- lang_input_statement_type *input;
- input = lang_add_input_file (c->input_statement.input->filename,
- lang_input_file_is_file_enum,
- NULL);
- input->add_DT_NEEDED_for_dynamic
- = c->input_statement.input->add_DT_NEEDED_for_dynamic;
- input->add_DT_NEEDED_for_regular
- = c->input_statement.input->add_DT_NEEDED_for_regular;
- input->whole_archive
- = c->input_statement.input->whole_archive;
- }
+ lang_add_copy_of_input_file (c->input_statement.input);
break;
case cmdline_is_file_enum:
lang_add_input_file (c->file.filename,