[lld] [lld] Support RUN_LLD_MAIN_TWICE for the ELF port (PR #124441)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 27 09:57:25 PST 2025
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/124441
>From 65b33d0e6ecfdc2613226da2f37b193ddae53afc 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] 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
```
comment="This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice."
xargs </tmp/0 sed -Ei "1s/(;|#|\/\/) REQUIRES: .*/\0\n\1 "$comment"\n\1 XFAIL: main-run-twice/;t;1s/^/# "$comment"\n# XFAIL: main-run-twice\n/"
```
---
lld/test/ELF/archive-thin-missing-member.s | 2 ++
lld/test/ELF/arm-thumb-thunk-v6m-xo.s | 2 ++
lld/test/ELF/arm-thunk-section-too-large.s | 2 ++
lld/test/ELF/arm-thunk-toolargesection.s | 2 ++
lld/test/ELF/arm-v5-reloc-error.s | 2 ++
lld/test/ELF/bad-archive.s | 2 ++
lld/test/ELF/fatlto/fatlto.invalid.s | 2 ++
lld/test/ELF/invalid-cie-reference.s | 2 ++
lld/test/ELF/invalid/comdat-broken.test | 2 ++
lld/test/ELF/invalid/data-encoding.test | 2 ++
lld/test/ELF/invalid/dynamic-section-broken.test | 2 ++
lld/test/ELF/invalid/invalid-elf.test | 2 ++
lld/test/ELF/invalid/invalid-file-class.test | 2 ++
lld/test/ELF/invalid/sht-group-wrong-section.test | 2 ++
lld/test/ELF/invalid/sht-group.test | 2 ++
lld/test/ELF/invalid/symtab-sh-info.s | 2 ++
lld/test/ELF/invalid/verneed-shared.test | 2 ++
lld/test/ELF/lto/bitcode-nodatalayout.ll | 2 ++
lld/test/ELF/lto/bitcode-wrapper.ll | 2 ++
lld/test/ELF/unsupported-emachine.test | 2 ++
lld/test/lit.cfg.py | 6 ++----
21 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/lld/test/ELF/archive-thin-missing-member.s b/lld/test/ELF/archive-thin-missing-member.s
index 1d770451fcbe82..45fcd0e3caa23a 100644
--- a/lld/test/ELF/archive-thin-missing-member.s
+++ b/lld/test/ELF/archive-thin-missing-member.s
@@ -1,4 +1,6 @@
# REQUIRES: x86
+# This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+# XFAIL: main-run-twice
# RUN: rm -f %t-no-syms.a
# RUN: rm -f %t-syms.a
diff --git a/lld/test/ELF/arm-thumb-thunk-v6m-xo.s b/lld/test/ELF/arm-thumb-thunk-v6m-xo.s
index f1b6c0c194b38a..caee025ef52b2c 100644
--- a/lld/test/ELF/arm-thumb-thunk-v6m-xo.s
+++ b/lld/test/ELF/arm-thumb-thunk-v6m-xo.s
@@ -1,4 +1,6 @@
// REQUIRES: arm
+// This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+// XFAIL: main-run-twice
// RUN: rm -rf %t && split-file %s %t
// RUN: llvm-mc -arm-add-build-attributes -filetype=obj -triple=armv6m-none-eabi %t/a.s -o %t/a.o
// RUN: ld.lld --no-rosegment --script %t/a.t %t/a.o -o %t/a
diff --git a/lld/test/ELF/arm-thunk-section-too-large.s b/lld/test/ELF/arm-thunk-section-too-large.s
index c6c058085968d3..a2e8ff555eadc1 100644
--- a/lld/test/ELF/arm-thunk-section-too-large.s
+++ b/lld/test/ELF/arm-thunk-section-too-large.s
@@ -1,4 +1,6 @@
// REQUIRES: arm
+// This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+// XFAIL: main-run-twice
// RUN: llvm-mc %s -triple=armv7a-linux-gnueabihf -arm-add-build-attributes -filetype=obj -o %t.o
// RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
diff --git a/lld/test/ELF/arm-thunk-toolargesection.s b/lld/test/ELF/arm-thunk-toolargesection.s
index f91c4a49593153..88f8e6ba4cad34 100644
--- a/lld/test/ELF/arm-thunk-toolargesection.s
+++ b/lld/test/ELF/arm-thunk-toolargesection.s
@@ -1,4 +1,6 @@
// REQUIRES: arm
+// This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+// XFAIL: main-run-twice
// RUN: llvm-mc -filetype=obj -triple=thumbv7a-none-linux-gnueabi %s -o %t
// RUN: not ld.lld %t -o /dev/null 2>&1 | FileCheck %s
diff --git a/lld/test/ELF/arm-v5-reloc-error.s b/lld/test/ELF/arm-v5-reloc-error.s
index bd4b9ad68d10ac..85e66f1d3850f2 100644
--- a/lld/test/ELF/arm-v5-reloc-error.s
+++ b/lld/test/ELF/arm-v5-reloc-error.s
@@ -1,4 +1,6 @@
// REQUIRES: arm
+// This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+// XFAIL: main-run-twice
// RUN: llvm-mc -filetype=obj -triple=armv7a-linux-gnueabi %s -o %t
// RUN: echo "SECTIONS { \
// RUN: . = SIZEOF_HEADERS; \
diff --git a/lld/test/ELF/bad-archive.s b/lld/test/ELF/bad-archive.s
index ba6d674c2fa656..92aa1646f6c570 100644
--- a/lld/test/ELF/bad-archive.s
+++ b/lld/test/ELF/bad-archive.s
@@ -1,4 +1,6 @@
// REQUIRES: x86
+// This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+// XFAIL: main-run-twice
// Check bad archive error reporting with --whole-archive
// and without it.
diff --git a/lld/test/ELF/fatlto/fatlto.invalid.s b/lld/test/ELF/fatlto/fatlto.invalid.s
index a712b1dbb58b48..a0d5fd5597b767 100644
--- a/lld/test/ELF/fatlto/fatlto.invalid.s
+++ b/lld/test/ELF/fatlto/fatlto.invalid.s
@@ -1,4 +1,6 @@
# REQUIRES: x86
+# This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+# XFAIL: main-run-twice
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
# RUN: not ld.lld %t -o /dev/null --fat-lto-objects 2>&1 | FileCheck %s
diff --git a/lld/test/ELF/invalid-cie-reference.s b/lld/test/ELF/invalid-cie-reference.s
index 158fc4e935f28b..b2d3750ff1c7a8 100644
--- a/lld/test/ELF/invalid-cie-reference.s
+++ b/lld/test/ELF/invalid-cie-reference.s
@@ -1,4 +1,6 @@
// REQUIRES: x86
+// This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+// XFAIL: main-run-twice
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
// RUN: not ld.lld %t -o /dev/null 2>&1 | FileCheck %s
diff --git a/lld/test/ELF/invalid/comdat-broken.test b/lld/test/ELF/invalid/comdat-broken.test
index 02941070dc0d1b..60642722726360 100644
--- a/lld/test/ELF/invalid/comdat-broken.test
+++ b/lld/test/ELF/invalid/comdat-broken.test
@@ -1,4 +1,6 @@
# REQUIRES: x86
+# This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+# XFAIL: main-run-twice
# RUN: yaml2obj %s -o %t.o
# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
diff --git a/lld/test/ELF/invalid/data-encoding.test b/lld/test/ELF/invalid/data-encoding.test
index 94862af79c3cf4..361d53da1a862c 100644
--- a/lld/test/ELF/invalid/data-encoding.test
+++ b/lld/test/ELF/invalid/data-encoding.test
@@ -1,4 +1,6 @@
# REQUIRES: x86
+# This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+# XFAIL: main-run-twice
# The object in the archive has invalid data encoding.
# Check we report this.
diff --git a/lld/test/ELF/invalid/dynamic-section-broken.test b/lld/test/ELF/invalid/dynamic-section-broken.test
index 62f311470a2e57..01fe9a05b8a5f9 100644
--- a/lld/test/ELF/invalid/dynamic-section-broken.test
+++ b/lld/test/ELF/invalid/dynamic-section-broken.test
@@ -1,3 +1,5 @@
+# This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+# XFAIL: main-run-twice
## .dynamic section has invalid sh_entsize, check we report it.
# RUN: yaml2obj --docnum=1 %s -o %t.so
# RUN: not ld.lld %t.so -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR1
diff --git a/lld/test/ELF/invalid/invalid-elf.test b/lld/test/ELF/invalid/invalid-elf.test
index 848a430eb053c9..7282259b7305cc 100644
--- a/lld/test/ELF/invalid/invalid-elf.test
+++ b/lld/test/ELF/invalid/invalid-elf.test
@@ -1,3 +1,5 @@
+# This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+# XFAIL: main-run-twice
# RUN: rm -rf %t && mkdir -p %t
# RUN: echo > %t/empty.o
# RUN: llvm-ar --format=gnu cr %t/not-elf.a %t/empty.o
diff --git a/lld/test/ELF/invalid/invalid-file-class.test b/lld/test/ELF/invalid/invalid-file-class.test
index 3f547861b3793f..dda4648e255b6a 100644
--- a/lld/test/ELF/invalid/invalid-file-class.test
+++ b/lld/test/ELF/invalid/invalid-file-class.test
@@ -1,4 +1,6 @@
# REQUIRES: x86
+# This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+# XFAIL: main-run-twice
# RUN: rm -rf %t && mkdir -p %t
## In this test, we check that able to report objects with
diff --git a/lld/test/ELF/invalid/sht-group-wrong-section.test b/lld/test/ELF/invalid/sht-group-wrong-section.test
index 46209a213902c2..0eea432c1ee458 100644
--- a/lld/test/ELF/invalid/sht-group-wrong-section.test
+++ b/lld/test/ELF/invalid/sht-group-wrong-section.test
@@ -1,4 +1,6 @@
# REQUIRES: x86
+# This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+# XFAIL: main-run-twice
# RUN: yaml2obj %s -o %t.o
# RUN: not ld.lld %t.o %t.o -o /dev/null 2>&1 | FileCheck %s
# CHECK: error: {{.*}}.o: invalid section index in group: 12345
diff --git a/lld/test/ELF/invalid/sht-group.test b/lld/test/ELF/invalid/sht-group.test
index 9041bb61b3e952..d50fbe6a6ce75b 100644
--- a/lld/test/ELF/invalid/sht-group.test
+++ b/lld/test/ELF/invalid/sht-group.test
@@ -1,4 +1,6 @@
# REQUIRES: x86
+# This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+# XFAIL: main-run-twice
# RUN: yaml2obj %s -o %t.o
# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
# CHECK: invalid symbol index
diff --git a/lld/test/ELF/invalid/symtab-sh-info.s b/lld/test/ELF/invalid/symtab-sh-info.s
index 253bbf9e62d563..03570892c4628d 100644
--- a/lld/test/ELF/invalid/symtab-sh-info.s
+++ b/lld/test/ELF/invalid/symtab-sh-info.s
@@ -1,3 +1,5 @@
+# This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+# XFAIL: main-run-twice
## .symtab's sh_info contains zero value. First entry in a .symtab is a
## zero entry that must exist in a valid object, so sh_info can't be null.
## Check we report a proper error for that case.
diff --git a/lld/test/ELF/invalid/verneed-shared.test b/lld/test/ELF/invalid/verneed-shared.test
index 2e2ff494fb582f..fd107e4f09781c 100644
--- a/lld/test/ELF/invalid/verneed-shared.test
+++ b/lld/test/ELF/invalid/verneed-shared.test
@@ -1,4 +1,6 @@
## REQUIRES: x86
+# This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+# XFAIL: main-run-twice
## Test that we can parse SHT_GNU_verneed in a shared object and report certain errors.
# RUN: echo '.globl _start; _start:' | llvm-mc -filetype=obj -triple=x86_64 - -o %t.o
diff --git a/lld/test/ELF/lto/bitcode-nodatalayout.ll b/lld/test/ELF/lto/bitcode-nodatalayout.ll
index 7ddc1222672181..39e8263aa72877 100644
--- a/lld/test/ELF/lto/bitcode-nodatalayout.ll
+++ b/lld/test/ELF/lto/bitcode-nodatalayout.ll
@@ -1,4 +1,6 @@
; REQUIRES: x86
+; This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+; XFAIL: main-run-twice
; RUN: llvm-as %s -o %t.o
; RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
diff --git a/lld/test/ELF/lto/bitcode-wrapper.ll b/lld/test/ELF/lto/bitcode-wrapper.ll
index 183d8c28383b34..c76be4854cca39 100644
--- a/lld/test/ELF/lto/bitcode-wrapper.ll
+++ b/lld/test/ELF/lto/bitcode-wrapper.ll
@@ -1,4 +1,6 @@
; REQUIRES: x86
+; This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+; XFAIL: main-run-twice
;; The LLVM bitcode format allows for an optional wrapper header. This test
;; shows that LLD can handle bitcode wrapped in this way, and also that an
diff --git a/lld/test/ELF/unsupported-emachine.test b/lld/test/ELF/unsupported-emachine.test
index 43d907ea72d562..54a3402378bfbf 100644
--- a/lld/test/ELF/unsupported-emachine.test
+++ b/lld/test/ELF/unsupported-emachine.test
@@ -1,3 +1,5 @@
+# This test intentionally checks for fatal errors, and fatal errors aren't supported for testing when main is run twice.
+# XFAIL: main-run-twice
# RUN: yaml2obj %s -o %t.o
# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
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")
More information about the llvm-commits
mailing list