[lld] [lld] Support RUN_LLD_MAIN_TWICE for the ELF port (PR #124441)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 26 09:01:43 PST 2025
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/124441
>From f5180a757c880c626012d55da20e1cf2eaeb7eb7 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Mon, 18 Nov 2024 08:57:41 -0800
Subject: [PATCH] [lld] Change inTestOutputDisabled and support
RUN_LLD_MAIN_TWICE for the ELF port
This enables the LLD_IN_TEST=2 testing mode for
```
path/to/llvm-lit -sv --param RUN_LLD_MAIN_TWICE=1 lld/test/ELF
```
When `Fatal` is called, `RunSafely` will return false.
For the first invocation in LLD_IN_TEST=2 mode, `inTestOutputDisabled`
is true and lld will not write to stdout/stderr, making many tests fail.
(This essentially discourages `Fatal` calls in the source code.)
Add XFAIL: main-run-twice to these tests similar to
https://reviews.llvm.org/D112898 for Mach-O
```
xargs </tmp/0 sed -Ei '1s/(;|#|\/\/) REQUIRES: .*/\0\n\1 XFAIL: main-run-twice/;t;1s/^/# XFAIL: main-run-twice\n/'
```
---
lld/ELF/Writer.cpp | 2 +-
lld/test/MachO/cgprofile-icf.s | 1 +
lld/test/MachO/cgprofile-obj.s | 1 +
lld/test/MachO/cgprofile-orderfile.s | 1 +
lld/test/MachO/cgprofile-print.s | 1 +
lld/test/MachO/cspgo-gen.ll | 1 +
lld/test/MachO/cspgo-use.ll | 1 +
lld/test/MachO/error-limit.test | 4 ----
lld/test/MachO/invalid/bad-archive.s | 4 ----
lld/test/MachO/invalid/cstring-dedup.s | 4 ----
lld/test/MachO/invalid/lto-bitcode-nodatalayout.ll | 4 ----
lld/test/MachO/invalid/reserved-section-name.s | 4 ----
lld/test/MachO/load-hidden.s | 1 +
lld/test/MachO/lto-cache-warnings.ll | 1 +
lld/test/lit.cfg.py | 6 ++----
lld/tools/lld/lld.cpp | 6 +++---
16 files changed, 14 insertions(+), 28 deletions(-)
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index b7c4790655e8a0..b1fae1c4dc2264 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -381,7 +381,7 @@ template <class ELFT> void Writer<ELFT>::run() {
if (errCount(ctx))
return;
- if (!ctx.e.disableOutput) {
+ if (ctx.arg.outputFile != "-" || !ctx.e.disableOutput) {
if (auto e = buffer->commit())
Err(ctx) << "failed to write output '" << buffer->getPath()
<< "': " << std::move(e);
diff --git a/lld/test/MachO/cgprofile-icf.s b/lld/test/MachO/cgprofile-icf.s
index f9034ee32103a4..e5b78b57153768 100644
--- a/lld/test/MachO/cgprofile-icf.s
+++ b/lld/test/MachO/cgprofile-icf.s
@@ -1,4 +1,5 @@
# REQUIRES: x86
+# XFAIL: main-run-twice
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t
diff --git a/lld/test/MachO/cgprofile-obj.s b/lld/test/MachO/cgprofile-obj.s
index 97aaf2de8c18d2..ef270f2d25de2a 100644
--- a/lld/test/MachO/cgprofile-obj.s
+++ b/lld/test/MachO/cgprofile-obj.s
@@ -1,4 +1,5 @@
# REQUIRES: x86
+# XFAIL: main-run-twice
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: %lld -lSystem -e A -o %t.out %t.o
diff --git a/lld/test/MachO/cgprofile-orderfile.s b/lld/test/MachO/cgprofile-orderfile.s
index eb3a30b27e1bd8..33db4b2906bccd 100644
--- a/lld/test/MachO/cgprofile-orderfile.s
+++ b/lld/test/MachO/cgprofile-orderfile.s
@@ -1,4 +1,5 @@
# REQUIRES: x86
+# XFAIL: main-run-twice
# RUN: rm -rf %t; split-file %s %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
diff --git a/lld/test/MachO/cgprofile-print.s b/lld/test/MachO/cgprofile-print.s
index 9435891695c9d0..f9e27d7b1e5fde 100644
--- a/lld/test/MachO/cgprofile-print.s
+++ b/lld/test/MachO/cgprofile-print.s
@@ -1,4 +1,5 @@
# REQUIRES: x86
+# XFAIL: main-run-twice
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t
# RUN: %lld -e A %t -o %t2 --print-symbol-order=%t3
diff --git a/lld/test/MachO/cspgo-gen.ll b/lld/test/MachO/cspgo-gen.ll
index 00c86aeb0e55ff..06edbc07ec8547 100644
--- a/lld/test/MachO/cspgo-gen.ll
+++ b/lld/test/MachO/cspgo-gen.ll
@@ -1,4 +1,5 @@
; REQUIRES: x86
+; XFAIL: main-run-twice
; RUN: llvm-as %s -o %t.o
; RUN: %lld -dylib --cs-profile-generate --cs-profile-path=default_%m.profraw %t.o -o %t --lto-debug-pass-manager 2>&1 | FileCheck %s --implicit-check-not=PGOInstrumentation
diff --git a/lld/test/MachO/cspgo-use.ll b/lld/test/MachO/cspgo-use.ll
index 3d01cd58adaa96..739bd4de6f6ddf 100644
--- a/lld/test/MachO/cspgo-use.ll
+++ b/lld/test/MachO/cspgo-use.ll
@@ -1,4 +1,5 @@
; REQUIRES: x86
+; XFAIL: main-run-twice
; Create an empty profile
; RUN: echo > %t.proftext
diff --git a/lld/test/MachO/error-limit.test b/lld/test/MachO/error-limit.test
index 75f55084bbd59e..79eaa3d5223116 100644
--- a/lld/test/MachO/error-limit.test
+++ b/lld/test/MachO/error-limit.test
@@ -1,7 +1,3 @@
-## We're intentionally testing fatal errors, which isn't supported for testing
-## when main is run twice.
-XFAIL: main-run-twice
-
## Check that we only see 20 (the default error-limit) "cannot open" errors
RUN: not %lld A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 2>&1 | \
RUN: FileCheck -check-prefix=DEFAULT %s
diff --git a/lld/test/MachO/invalid/bad-archive.s b/lld/test/MachO/invalid/bad-archive.s
index 0a405ed8966534..24f7a5d6f83548 100644
--- a/lld/test/MachO/invalid/bad-archive.s
+++ b/lld/test/MachO/invalid/bad-archive.s
@@ -1,7 +1,3 @@
-## We're intentionally testing fatal errors (for malformed input files), and
-## fatal errors aren't supported for testing when main is run twice.
-# XFAIL: main-run-twice
-
# REQUIRES: x86
# RUN: echo "!<arch>" > %t.a
# RUN: echo "foo" >> %t.a
diff --git a/lld/test/MachO/invalid/cstring-dedup.s b/lld/test/MachO/invalid/cstring-dedup.s
index b6ef32531b66f4..b91e424afc2a6d 100644
--- a/lld/test/MachO/invalid/cstring-dedup.s
+++ b/lld/test/MachO/invalid/cstring-dedup.s
@@ -1,7 +1,3 @@
-## We're intentionally testing fatal errors (for malformed input files), and
-## fatal errors aren't supported for testing when main is run twice.
-# XFAIL: main-run-twice
-
# REQUIRES: x86
# RUN: rm -rf %t; split-file %s %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/not-terminated.s -o %t/not-terminated.o
diff --git a/lld/test/MachO/invalid/lto-bitcode-nodatalayout.ll b/lld/test/MachO/invalid/lto-bitcode-nodatalayout.ll
index f2ab80213a2c3c..5e1c43c928d912 100644
--- a/lld/test/MachO/invalid/lto-bitcode-nodatalayout.ll
+++ b/lld/test/MachO/invalid/lto-bitcode-nodatalayout.ll
@@ -1,7 +1,3 @@
-;; We're intentionally testing fatal errors (for malformed input files), and
-;; fatal errors aren't supported for testing when main is run twice.
-; XFAIL: main-run-twice
-
; REQUIRES: x86
; RUN: llvm-as %s -o %t.o
; RUN: not %lld %t.o -o /dev/null 2>&1 | FileCheck %s
diff --git a/lld/test/MachO/invalid/reserved-section-name.s b/lld/test/MachO/invalid/reserved-section-name.s
index 97dd4376c88f1b..7614a1001f16a0 100644
--- a/lld/test/MachO/invalid/reserved-section-name.s
+++ b/lld/test/MachO/invalid/reserved-section-name.s
@@ -1,7 +1,3 @@
-## We're intentionally testing fatal errors (for malformed input files), and
-## fatal errors aren't supported for testing when main is run twice.
-# XFAIL: main-run-twice
-
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: not %lld -o %t %t.o 2>&1 | FileCheck %s -DFILE=%t.o
diff --git a/lld/test/MachO/load-hidden.s b/lld/test/MachO/load-hidden.s
index 489571c29e7554..84342dbd56820b 100644
--- a/lld/test/MachO/load-hidden.s
+++ b/lld/test/MachO/load-hidden.s
@@ -1,4 +1,5 @@
# REQUIRES: x86
+# XFAIL: main-run-twice
# RUN: rm -rf %t; split-file %s %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/archive-foo.s -o %t/archive-foo.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/archive-baz.s -o %t/archive-baz.o
diff --git a/lld/test/MachO/lto-cache-warnings.ll b/lld/test/MachO/lto-cache-warnings.ll
index 50fa5c16a41b3f..f08a9b3541ef2b 100644
--- a/lld/test/MachO/lto-cache-warnings.ll
+++ b/lld/test/MachO/lto-cache-warnings.ll
@@ -1,4 +1,5 @@
; REQUIRES: x86, shell
+; XFAIL: main-run-twice
; RUN: rm -rf %t; split-file %s %t
; RUN: opt -module-hash -module-summary %t/foo.ll -o %t/foo.o
diff --git a/lld/test/lit.cfg.py b/lld/test/lit.cfg.py
index 859094e2b57dbc..9e6b0e839d9a8b 100644
--- a/lld/test/lit.cfg.py
+++ b/lld/test/lit.cfg.py
@@ -104,10 +104,8 @@
config.environment["LLD_IN_TEST"] = "1"
else:
config.environment["LLD_IN_TEST"] = "2"
- # Many ELF tests fail in this mode.
- config.excludes.append("ELF")
- # Some old Mach-O backend tests fail, and it's due for removal anyway.
- config.excludes.append("mach-o")
+ # Many wasm tests fail.
+ config.excludes.append("wasm")
# Some new Mach-O backend tests fail; give them a way to mark themselves
# unsupported in this mode.
config.available_features.add("main-run-twice")
diff --git a/lld/tools/lld/lld.cpp b/lld/tools/lld/lld.cpp
index d6800fa1eea4b9..dece6c39cbdb0d 100644
--- a/lld/tools/lld/lld.cpp
+++ b/lld/tools/lld/lld.cpp
@@ -96,9 +96,6 @@ int lld_main(int argc, char **argv, const llvm::ToolContext &) {
CrashRecoveryContext::Enable();
for (unsigned i = inTestVerbosity(); i > 0; --i) {
- // Disable stdout/stderr for all iterations but the last one.
- inTestOutputDisabled = (i != 1);
-
// Execute one iteration.
auto r = lldMain(args, llvm::outs(), llvm::errs(), LLD_ALL_DRIVERS);
if (!r.canRunAgain)
@@ -110,6 +107,9 @@ int lld_main(int argc, char **argv, const llvm::ToolContext &) {
// Exit now, to fail the tests if the result is different between runs.
return r.retCode;
}
+
+ // Disable stdout/stderr for all iterations but the first one.
+ inTestOutputDisabled = true;
}
return *mainRet;
}
More information about the llvm-commits
mailing list