[COMMITTED, PATCH] ld: Run clang tests only if supported

"H.J. Lu" <[email protected]>
Newsgroups gmane.comp.gnu.binutils
Message-ID <CAMe9rOpwbQjXEWDdo2b4dB5ki-21NOt=xxjqnLS_6niMTkfYDA@mail.gmail.com>
On Fri, Aug 28, 2026 at 4:11 PM H.J. Lu <[email protected]> wrote:
>
> Since Clang doesn't support all GCC options, PR ld/34570 tests fail to
> compile if GCC specific options are used to build binutils.  Add
> llvm_lto_tests to lto.exp and don't run PR ld/34576 tests if Clang fails
> to compile them.
>
> PR ld/34576
> * testsuite/ld-plugin/lto.exp (llvm_lto_tests): New.
> Use it.
>
> --
> H.J.

This is the patch I am checking in.

-- 
H.J.
---
Since Clang doesn't support all GCC options, PR ld/34570 tests fail to
compile if GCC specific options are used to build binutils.  Add
llvm_lto_tests to lto.exp and don't run PR ld/34570 tests if Clang fails
to compile them.

PR ld/34576
PR ld/34570
* testsuite/ld-plugin/lto.exp (llvm_lto_tests): New.
Use it.
0001-ld-Run-clang-tests-only-if-supported.patch (application/x-patch, 2.2 KB)
From 3ceec55a654c28b4d5988eb28b54c32a843e8930 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <[email protected]>
Date: Fri, 28 Aug 2026 16:02:11 +0800
Subject: [PATCH] ld: Run clang tests only if supported

Since Clang doesn't support all GCC options, PR ld/34570 tests fail to
compile if GCC specific options are used to build binutils.  Add
llvm_lto_tests to lto.exp and don't run PR ld/34570 tests if Clang fails
to compile them.

	PR ld/34576
	PR ld/34570
	* testsuite/ld-plugin/lto.exp (llvm_lto_tests): New.
	Use it.

Signed-off-by: H.J. Lu <[email protected]>
---
 ld/testsuite/ld-plugin/lto.exp | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index 8ad341293b5..0144ae8f70a 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -1452,12 +1452,20 @@ 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] } {
+proc llvm_lto_tests {} {
+    global CC_FOR_TARGET
+    global CLANG_FOR_TARGET
+    global llvm_plug_opt
+
+    # 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] } {
+	return
+    }
+
     set CC_FOR_TARGET_saved "$CC_FOR_TARGET"
     set CC_FOR_TARGET "$CLANG_FOR_TARGET"
     run_cc_link_tests [list \
@@ -1473,6 +1481,14 @@ if { ![istarget "x86_64-*-linux*-gnux32"]
 	    "-flto" \
 	    {pr34572b.c} \
 	] \
+    ]
+
+   if {![file exists tmpdir/pr34572a.o]
+       || ![file exists tmpdir/pr34572b.o]} {
+	return
+    }
+
+    run_cc_link_tests [list \
 	[list \
 	    "Build pr34572a.exe" \
 	    "-flto -Wl,--start-lib tmpdir/pr34572a.o -Wl,--end-lib" \
@@ -1509,4 +1525,6 @@ if { ![istarget "x86_64-*-linux*-gnux32"]
     set CC_FOR_TARGET "$CC_FOR_TARGET_saved"
 }
 
+llvm_lto_tests
+
 restore_notify
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.