lto: Don't check format of IR dummy file

Message ID CAMe9rOooyG9+Uh7Ga=ZiA2nhUzEO8sBZT3vb1Bd5pTMAoxWWag@mail.gmail.com
State New
Headers
Series lto: Don't check format of IR dummy file |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

H.J. Lu Aug. 28, 2026, 1:19 a.m. UTC
  1. Don't check format of IR dummy file in lang_check.
2. Allow empty DESTLIST in lang_list_remove_tail.

PR ld/34572
* ldlang.c (lang_check): Don't check format of IR dummy file.
(debug_file_chain): New.
(debug_input_files): Use debug_file_chain.
(lang_list_remove_tail): Also check empty DESTLIST.
* testsuite/ld-plugin/dummy.s: Add .note.GNU-stack section.
* testsuite/ld-plugin/lto.exp: Add PR ld/34572 tests.
* testsuite/ld-plugin/pr34572.rd: New file.
* testsuite/ld-plugin/pr34572a.c: Likewise.
* testsuite/ld-plugin/pr34572b.c: Likewise.
  

Comments

Alan Modra Aug. 28, 2026, 5:35 a.m. UTC | #1
On Fri, Aug 28, 2026 at 09:19:26AM +0800, H.J. Lu wrote:
> 1. Don't check format of IR dummy file in lang_check.
> 2. Allow empty DESTLIST in lang_list_remove_tail.
> 
> 	PR ld/34572
> 	* ldlang.c (lang_check): Don't check format of IR dummy file.
> 	(debug_file_chain): New.
> 	(debug_input_files): Use debug_file_chain.
> 	(lang_list_remove_tail): Also check empty DESTLIST.
> 	* testsuite/ld-plugin/dummy.s: Add .note.GNU-stack section.
> 	* testsuite/ld-plugin/lto.exp: Add PR ld/34572 tests.
> 	* testsuite/ld-plugin/pr34572.rd: New file.
> 	* testsuite/ld-plugin/pr34572a.c: Likewise.
> 	* testsuite/ld-plugin/pr34572b.c: Likewise.

OK with a minor fix.

> +      /* Don't check format of IR dummy file.  */
> +      if ((input_bfd->flags &BFD_PLUGIN) != 0)

Formatting.
  
H.J. Lu Aug. 28, 2026, 6:03 a.m. UTC | #2
On Fri, Aug 28, 2026 at 1:35 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Fri, Aug 28, 2026 at 09:19:26AM +0800, H.J. Lu wrote:
> > 1. Don't check format of IR dummy file in lang_check.
> > 2. Allow empty DESTLIST in lang_list_remove_tail.
> >
> >       PR ld/34572
> >       * ldlang.c (lang_check): Don't check format of IR dummy file.
> >       (debug_file_chain): New.
> >       (debug_input_files): Use debug_file_chain.
> >       (lang_list_remove_tail): Also check empty DESTLIST.
> >       * testsuite/ld-plugin/dummy.s: Add .note.GNU-stack section.
> >       * testsuite/ld-plugin/lto.exp: Add PR ld/34572 tests.
> >       * testsuite/ld-plugin/pr34572.rd: New file.
> >       * testsuite/ld-plugin/pr34572a.c: Likewise.
> >       * testsuite/ld-plugin/pr34572b.c: Likewise.
>
> OK with a minor fix.
>
> > +      /* Don't check format of IR dummy file.  */
> > +      if ((input_bfd->flags &BFD_PLUGIN) != 0)

Fixed with

if ((input_bfd->flags & BFD_PLUGIN) != 0)

> Formatting.
>
> --
> Alan Modra

Thanks.
  
Alan Modra Aug. 28, 2026, 7:34 a.m. UTC | #3
I see testsuite failures on x86_64-w64-mingw32 with this.
  

Patch

From 63b667383c529a9c71b7a785b5825d0f373dd7fd Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Fri, 28 Aug 2026 09:08:39 +0800
Subject: [PATCH] lto: Don't check format of IR dummy file

1. Don't check format of IR dummy file in lang_check.
2. Allow empty DESTLIST in lang_list_remove_tail.

	PR ld/34572
	* ldlang.c (lang_check): Don't check format of IR dummy file.
	(debug_file_chain): New.
	(debug_input_files): Use debug_file_chain.
	(lang_list_remove_tail): Also check empty DESTLIST.
	* testsuite/ld-plugin/dummy.s: Add .note.GNU-stack section.
	* testsuite/ld-plugin/lto.exp: Add PR ld/34572 tests.
	* testsuite/ld-plugin/pr34572.rd: New file.
	* testsuite/ld-plugin/pr34572a.c: Likewise.
	* testsuite/ld-plugin/pr34572b.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
 ld/ldlang.c                       | 19 ++++++++---
 ld/testsuite/ld-plugin/dummy.s    |  2 +-
 ld/testsuite/ld-plugin/lto.exp    | 57 +++++++++++++++++++++++++++++++
 ld/testsuite/ld-plugin/pr34572.rd |  6 ++++
 ld/testsuite/ld-plugin/pr34572a.c |  8 +++++
 ld/testsuite/ld-plugin/pr34572b.c |  4 +++
 6 files changed, 91 insertions(+), 5 deletions(-)
 create mode 100644 ld/testsuite/ld-plugin/pr34572.rd
 create mode 100644 ld/testsuite/ld-plugin/pr34572a.c
 create mode 100644 ld/testsuite/ld-plugin/pr34572b.c

diff --git a/ld/ldlang.c b/ld/ldlang.c
index 65494acca00..c2807f3ee69 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -7617,6 +7617,9 @@  lang_check (void)
       if (file->flags.claimed)
 	continue;
       input_bfd = file->the_bfd;
+      /* Don't check format of IR dummy file.  */
+      if ((input_bfd->flags &BFD_PLUGIN) != 0)
+	continue;
       compatible
 	= bfd_arch_get_compatible (input_bfd, link_info.output_bfd,
 				   command_line.accept_unknown_input_arch);
@@ -7926,11 +7929,11 @@  lang_set_flags (lang_memory_region_type *ptr, const char *flags, int invert)
 }
 
 static void
-debug_input_files (void)
+debug_file_chain (lang_statement_list_type *chain)
 {
   lang_input_statement_type *f;
 
-  for (f = &input_file_chain.head->input_statement;
+  for (f = &chain->head->input_statement;
        f != NULL;
        f = f->next_real_file)
     if (f->the_bfd)
@@ -7939,6 +7942,12 @@  debug_input_files (void)
       fprintf (stderr, "input: %s\n", f->filename);
 }
 
+static void
+debug_input_files (void)
+{
+  debug_file_chain (&input_file_chain);
+}
+
 /* Call a function on each real input file.  This function will be
    called on an archive, but not on the elements.  */
 
@@ -8392,8 +8401,10 @@  lang_list_remove_tail (lang_statement_list_type *destlist,
 		       lang_statement_list_type *origlist)
 {
   union lang_statement_union **savetail;
-  /* Check that ORIGLIST really is an earlier state of DESTLIST.  */
-  ASSERT (origlist->head == destlist->head);
+  /* Check that ORIGLIST really is an earlier state of DESTLIST or an
+     empty list.  */
+  ASSERT ((origlist->head == NULL && origlist->tail == &destlist->head)
+	  || origlist->head == destlist->head);
   savetail = origlist->tail;
   origlist->head = *(savetail);
   origlist->tail = destlist->tail;
diff --git a/ld/testsuite/ld-plugin/dummy.s b/ld/testsuite/ld-plugin/dummy.s
index 8b137891791..0f5ab47ca42 100644
--- a/ld/testsuite/ld-plugin/dummy.s
+++ b/ld/testsuite/ld-plugin/dummy.s
@@ -1 +1 @@ 
-
+	.section	.note.GNU-stack,"",%progbits
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 476b605b721..8ad341293b5 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -1452,4 +1452,61 @@  if { [check_lto_fat_available] } {
     }
 }
 
+# Skip native x32 and i?86 targets since system LLVMgold.so may not be
+# compatible with native x32 and i?86 targets binutils.
+if { ![istarget "x86_64-*-linux*-gnux32"]
+     && ![istarget "i?86-*-*"]
+     && [info exists CLANG_FOR_TARGET]
+     && ![string match "" $llvm_plug_opt] } {
+    set CC_FOR_TARGET_saved "$CC_FOR_TARGET"
+    set CC_FOR_TARGET "$CLANG_FOR_TARGET"
+    run_cc_link_tests [list \
+	[list \
+	    "Build pr34572a.o" \
+	    "" \
+	    "-flto" \
+	    {pr34572a.c} \
+	] \
+	[list \
+	    "Build pr34572b.o" \
+	    "" \
+	    "-flto" \
+	    {pr34572b.c} \
+	] \
+	[list \
+	    "Build pr34572a.exe" \
+	    "-flto -Wl,--start-lib tmpdir/pr34572a.o -Wl,--end-lib" \
+	    "" \
+	    {dummy.s} \
+	    {} \
+	    "pr34572a.exe"
+	] \
+    ]
+
+    if { [isnative] } {
+	if {[file exists tmpdir/pr34572a.exe]} {
+	    set exec_output [run_host_cmd "tmpdir/pr34572a.exe" ""]
+	    if [string match "PASS\n" $exec_output] then {
+		pass "Run pr34572a.exe"
+	    } else {
+		fail "Run pr34572a.exe"
+	    }
+	}
+    }
+
+    run_ld_link_tests [list \
+	[list \
+	    "Build pr34572b.exe" \
+	    "$llvm_plug_opt --start-lib tmpdir/pr34572b.o --end-lib" \
+	    "" \
+	    "" \
+	    {dummy.s} \
+	    {{readelf {-sW} pr34572.rd}} \
+	    "pr34572b.exe" \
+	] \
+    ]
+
+    set CC_FOR_TARGET "$CC_FOR_TARGET_saved"
+}
+
 restore_notify
diff --git a/ld/testsuite/ld-plugin/pr34572.rd b/ld/testsuite/ld-plugin/pr34572.rd
new file mode 100644
index 00000000000..dcf0d108a83
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr34572.rd
@@ -0,0 +1,6 @@ 
+#...
+Symbol table '\.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[0-9a-f]+ +[0-9]+ +FUNC +GLOBAL +DEFAULT .*[0-9]+ _start
+#pass
diff --git a/ld/testsuite/ld-plugin/pr34572a.c b/ld/testsuite/ld-plugin/pr34572a.c
new file mode 100644
index 00000000000..4e63772629e
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr34572a.c
@@ -0,0 +1,8 @@ 
+#include <stdio.h>
+
+int
+main (void)
+{
+  printf ("PASS\n");
+  return 0;
+}
diff --git a/ld/testsuite/ld-plugin/pr34572b.c b/ld/testsuite/ld-plugin/pr34572b.c
new file mode 100644
index 00000000000..ca92bf15a24
--- /dev/null
+++ b/ld/testsuite/ld-plugin/pr34572b.c
@@ -0,0 +1,4 @@ 
+void
+_start (void)
+{
+}
-- 
2.55.0