public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: Another fix for EFI generation with LTO enabled
@ 2023-01-31 11:30 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-01-31 11:30 UTC (permalink / raw)
  To: binutils; +Cc: Nick Clifton

Revert 1c66b8a03989 and instead fix the broken list pointer.

I verified that the PR testcase is fixed.  We likely would have run
into this bug much sooner except that crtn.o is usually linked last,
which always results in an insertion earlier in the list.

	PR 29998
	* pe-dll.c (build_filler_bfd): Revert last change.
	* ldlang.c (lang_process): When rescanning archives for lto,
	fix file_chain.tail pointer if the insert point happens to be
	at the end of the list.

diff --git a/ld/ldlang.c b/ld/ldlang.c
index b66d8c6bc1d..84a2914fc26 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -8017,6 +8017,8 @@ lang_process (void)
 	      *insert = &files.head->input_statement;
 	      files.head = (lang_statement_union_type *) *iter;
 	      *iter = temp;
+	      if (file_chain.tail == (lang_statement_union_type **) insert)
+		file_chain.tail = (lang_statement_union_type **) iter;
 	      if (my_arch != NULL)
 		{
 		  lang_input_statement_type *parent = bfd_usrdata (my_arch);
diff --git a/ld/pe-dll.c b/ld/pe-dll.c
index 49544babf11..2956eef1ca9 100644
--- a/ld/pe-dll.c
+++ b/ld/pe-dll.c
@@ -1082,22 +1082,6 @@ build_filler_bfd (bool include_edata)
 
   bfd_set_section_size (reloc_s, 0);
 
-  /* FIXME: I am not sure if this is the right way to solve PR 29998.
-     It might be better to change ldlang.c:lang_statement_append() so that it
-     checks to see if *(list->tail) is non-NULL and if so, set element->next
-     to its contents.
-
-     The issue is that this function is called after lang_process().
-     lang_process () will have gone through any input archives, and if the
-     last input file is an archive then it will have left file_chain.tail
-     pointing to the last used element of that archive.  Calling
-     ldlang_add_file() here then blows aaway the link to that archive element,
-     effectively deleting it from the input.  In order to prevent this, the
-     assignment below fills in the next field of the statement that is about
-     to appended to the file chain.  */
-  if (file_chain.tail != NULL)
-    filler_file->next = & (* file_chain.tail)->input_statement;
-
   ldlang_add_file (filler_file);
 }
 

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-31 11:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-31 11:30 Another fix for EFI generation with LTO enabled Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).