Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lld] Support RUN_LLD_MAIN_TWICE for the ELF port #124441

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Jan 26, 2025

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/'

@llvmbot
Copy link
Member

llvmbot commented Jan 26, 2025

@llvm/pr-subscribers-lld-macho
@llvm/pr-subscribers-lld-elf

@llvm/pr-subscribers-lld

Author: Fangrui Song (MaskRay)

Changes

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 &lt;/tmp/0 sed -Ei '1s/(;|#|\/\/) REQUIRES: .*/\0\n\1 XFAIL: main-run-twice/;t;1s/^/# XFAIL: main-run-twice\n/'

Full diff: https://github.com/llvm/llvm-project/pull/124441.diff

23 Files Affected:

  • (modified) lld/test/ELF/archive-thin-missing-member.s (+1)
  • (modified) lld/test/ELF/arm-thumb-thunk-v6m-xo.s (+1)
  • (modified) lld/test/ELF/arm-thunk-section-too-large.s (+1)
  • (modified) lld/test/ELF/arm-thunk-toolargesection.s (+1)
  • (modified) lld/test/ELF/arm-v5-reloc-error.s (+1)
  • (modified) lld/test/ELF/bad-archive.s (+1)
  • (modified) lld/test/ELF/fatlto/fatlto.invalid.s (+1)
  • (modified) lld/test/ELF/invalid-cie-reference.s (+1)
  • (modified) lld/test/ELF/invalid/comdat-broken.test (+1)
  • (modified) lld/test/ELF/invalid/common-symbol-alignment.test (+1)
  • (modified) lld/test/ELF/invalid/data-encoding.test (+1)
  • (modified) lld/test/ELF/invalid/dynamic-section-broken.test (+1)
  • (modified) lld/test/ELF/invalid/invalid-elf.test (+1)
  • (modified) lld/test/ELF/invalid/invalid-file-class.test (+1)
  • (modified) lld/test/ELF/invalid/invalid-soname.test (+1)
  • (modified) lld/test/ELF/invalid/sht-group-wrong-section.test (+1)
  • (modified) lld/test/ELF/invalid/sht-group.test (+1)
  • (modified) lld/test/ELF/invalid/symtab-sh-info.s (+1)
  • (modified) lld/test/ELF/invalid/verneed-shared.test (+1)
  • (modified) lld/test/ELF/lto/bitcode-nodatalayout.ll (+1)
  • (modified) lld/test/ELF/lto/bitcode-wrapper.ll (+1)
  • (modified) lld/test/ELF/unsupported-emachine.test (+1)
  • (modified) lld/test/lit.cfg.py (-2)
diff --git a/lld/test/ELF/archive-thin-missing-member.s b/lld/test/ELF/archive-thin-missing-member.s
index 1d770451fcbe82..603f20225de6de 100644
--- a/lld/test/ELF/archive-thin-missing-member.s
+++ b/lld/test/ELF/archive-thin-missing-member.s
@@ -1,4 +1,5 @@
 # REQUIRES: x86
+# 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..0b98418940412e 100644
--- a/lld/test/ELF/arm-thumb-thunk-v6m-xo.s
+++ b/lld/test/ELF/arm-thumb-thunk-v6m-xo.s
@@ -1,4 +1,5 @@
 // REQUIRES: arm
+// 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..882afc573b9ce3 100644
--- a/lld/test/ELF/arm-thunk-section-too-large.s
+++ b/lld/test/ELF/arm-thunk-section-too-large.s
@@ -1,4 +1,5 @@
 // REQUIRES: arm
+// 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..805b59c304bc8b 100644
--- a/lld/test/ELF/arm-thunk-toolargesection.s
+++ b/lld/test/ELF/arm-thunk-toolargesection.s
@@ -1,4 +1,5 @@
 // REQUIRES: arm
+// 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..e3366a8b9cd99d 100644
--- a/lld/test/ELF/arm-v5-reloc-error.s
+++ b/lld/test/ELF/arm-v5-reloc-error.s
@@ -1,4 +1,5 @@
 // REQUIRES: arm
+// 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..654970eb1d9b10 100644
--- a/lld/test/ELF/bad-archive.s
+++ b/lld/test/ELF/bad-archive.s
@@ -1,4 +1,5 @@
 // REQUIRES: x86
+// 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..f37c4054fefd16 100644
--- a/lld/test/ELF/fatlto/fatlto.invalid.s
+++ b/lld/test/ELF/fatlto/fatlto.invalid.s
@@ -1,4 +1,5 @@
 # REQUIRES: x86
+# 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..2ca570ac11c0e7 100644
--- a/lld/test/ELF/invalid-cie-reference.s
+++ b/lld/test/ELF/invalid-cie-reference.s
@@ -1,4 +1,5 @@
 // REQUIRES: x86
+// 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..3867dd272e5b08 100644
--- a/lld/test/ELF/invalid/comdat-broken.test
+++ b/lld/test/ELF/invalid/comdat-broken.test
@@ -1,4 +1,5 @@
 # REQUIRES: x86
+# 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/common-symbol-alignment.test b/lld/test/ELF/invalid/common-symbol-alignment.test
index 2e6d1f10242eb8..a0983d36e352cc 100644
--- a/lld/test/ELF/invalid/common-symbol-alignment.test
+++ b/lld/test/ELF/invalid/common-symbol-alignment.test
@@ -1,3 +1,4 @@
+# XFAIL: main-run-twice
 ## If an object contains a common symbol with zero alignment,
 ## check we report it.
 # RUN: yaml2obj --docnum=1 %s -o %t1.o
diff --git a/lld/test/ELF/invalid/data-encoding.test b/lld/test/ELF/invalid/data-encoding.test
index 94862af79c3cf4..21e23a3262629e 100644
--- a/lld/test/ELF/invalid/data-encoding.test
+++ b/lld/test/ELF/invalid/data-encoding.test
@@ -1,4 +1,5 @@
 # REQUIRES: x86
+# 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..873ec656eff5dd 100644
--- a/lld/test/ELF/invalid/dynamic-section-broken.test
+++ b/lld/test/ELF/invalid/dynamic-section-broken.test
@@ -1,3 +1,4 @@
+# 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..42bff8f0bf059a 100644
--- a/lld/test/ELF/invalid/invalid-elf.test
+++ b/lld/test/ELF/invalid/invalid-elf.test
@@ -1,3 +1,4 @@
+# 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..e69fe4279540cb 100644
--- a/lld/test/ELF/invalid/invalid-file-class.test
+++ b/lld/test/ELF/invalid/invalid-file-class.test
@@ -1,4 +1,5 @@
 # REQUIRES: x86
+# 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/invalid-soname.test b/lld/test/ELF/invalid/invalid-soname.test
index fdf61e66b0089a..5af8acd858b667 100644
--- a/lld/test/ELF/invalid/invalid-soname.test
+++ b/lld/test/ELF/invalid/invalid-soname.test
@@ -1,4 +1,5 @@
 # REQUIRES: x86
+# XFAIL: main-run-twice
 # RUN: yaml2obj %s -o %t.so
 # RUN: not ld.lld %t.so -o /dev/null 2>&1 | FileCheck %s
 
diff --git a/lld/test/ELF/invalid/sht-group-wrong-section.test b/lld/test/ELF/invalid/sht-group-wrong-section.test
index 46209a213902c2..bfecabec770551 100644
--- a/lld/test/ELF/invalid/sht-group-wrong-section.test
+++ b/lld/test/ELF/invalid/sht-group-wrong-section.test
@@ -1,4 +1,5 @@
 # REQUIRES: x86
+# 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..9f0c00a48e7cac 100644
--- a/lld/test/ELF/invalid/sht-group.test
+++ b/lld/test/ELF/invalid/sht-group.test
@@ -1,4 +1,5 @@
 # REQUIRES: x86
+# 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..d7962fb8b46ae0 100644
--- a/lld/test/ELF/invalid/symtab-sh-info.s
+++ b/lld/test/ELF/invalid/symtab-sh-info.s
@@ -1,3 +1,4 @@
+# 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..8ada17f3526864 100644
--- a/lld/test/ELF/invalid/verneed-shared.test
+++ b/lld/test/ELF/invalid/verneed-shared.test
@@ -1,4 +1,5 @@
 ## REQUIRES: x86
+# 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..61a10560ea1433 100644
--- a/lld/test/ELF/lto/bitcode-nodatalayout.ll
+++ b/lld/test/ELF/lto/bitcode-nodatalayout.ll
@@ -1,4 +1,5 @@
 ; REQUIRES: x86
+; 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..9b589853cc1bd9 100644
--- a/lld/test/ELF/lto/bitcode-wrapper.ll
+++ b/lld/test/ELF/lto/bitcode-wrapper.ll
@@ -1,4 +1,5 @@
 ; REQUIRES: x86
+; 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..13431dc29fe752 100644
--- a/lld/test/ELF/unsupported-emachine.test
+++ b/lld/test/ELF/unsupported-emachine.test
@@ -1,3 +1,4 @@
+# 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..a3bd1581f4a731 100644
--- a/lld/test/lit.cfg.py
+++ b/lld/test/lit.cfg.py
@@ -104,8 +104,6 @@
     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")
     # Some new Mach-O backend tests fail; give them a way to mark themselves

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/'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants