diff --git a/lld/test/MachO/error-limit.test b/lld/test/MachO/error-limit.test --- a/lld/test/MachO/error-limit.test +++ b/lld/test/MachO/error-limit.test @@ -1,3 +1,7 @@ +## 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 --- a/lld/test/MachO/invalid/bad-archive.s +++ b/lld/test/MachO/invalid/bad-archive.s @@ -1,3 +1,7 @@ +## 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 "!" > %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 --- a/lld/test/MachO/invalid/cstring-dedup.s +++ b/lld/test/MachO/invalid/cstring-dedup.s @@ -1,3 +1,7 @@ +## 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 --- a/lld/test/MachO/invalid/lto-bitcode-nodatalayout.ll +++ b/lld/test/MachO/invalid/lto-bitcode-nodatalayout.ll @@ -1,3 +1,7 @@ +;; 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 --- a/lld/test/MachO/invalid/reserved-section-name.s +++ b/lld/test/MachO/invalid/reserved-section-name.s @@ -1,3 +1,7 @@ +## 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/time-trace.s b/lld/test/MachO/time-trace.s --- a/lld/test/MachO/time-trace.s +++ b/lld/test/MachO/time-trace.s @@ -1,3 +1,7 @@ +## When running main twice, we'll also output the time trace JSON twice, which +## breaks JSON parsing. +# XFAIL: main-run-twice + # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o diff --git a/lld/test/lit.cfg.py b/lld/test/lit.cfg.py --- a/lld/test/lit.cfg.py +++ b/lld/test/lit.cfg.py @@ -81,7 +81,22 @@ # Set a fake constant version so that we get consistent output. config.environment['LLD_VERSION'] = 'LLD 1.0' -config.environment['LLD_IN_TEST'] = '1' + +# LLD_IN_TEST determines how many times `main` is run inside each process, which +# lets us test that it's cleaning up after itself and resetting global state +# correctly (which is important for usage as a library). +run_lld_main_twice = lit_config.params.get('RUN_LLD_MAIN_TWICE', False) +if not run_lld_main_twice: + 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 + # unsupported in this mode. + config.available_features.add('main-run-twice') # Indirectly check if the mt.exe Microsoft utility exists by searching for # cvtres, which always accompanies it. Alternatively, check if we can use