[ELF] -o -: suppress output if disableOutput

So that LLD_IN_TEST=2 ld.lld -o - a.o only writes the output once.
This commit is contained in:
Fangrui Song 2025-01-25 15:50:29 -08:00
parent 4f48048171
commit c7579bfba5
2 changed files with 7 additions and 4 deletions

View File

@ -381,9 +381,11 @@ template <class ELFT> void Writer<ELFT>::run() {
if (errCount(ctx))
return;
if (auto e = buffer->commit())
Err(ctx) << "failed to write output '" << buffer->getPath()
<< "': " << std::move(e);
if (!ctx.e.disableOutput) {
if (auto e = buffer->commit())
Err(ctx) << "failed to write output '" << buffer->getPath()
<< "': " << std::move(e);
}
if (!ctx.arg.cmseOutputLib.empty())
writeARMCmseImportLib<ELFT>(ctx);

View File

@ -1,7 +1,8 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: ld.lld %t.o -o - > %t1
## Test that we only write to "-" once.
# RUN: LLD_IN_TEST=2 ld.lld %t.o -o - > %t1
# RUN: llvm-objdump -d %t1 | FileCheck %s
# CHECK: nop