[ELF] openAuxiliaryFile: open /dev/null if disableOutput and filename is "-"

So that LLD_IN_TEST=2 ld.lld --print-archive-stats=- a.o (and -Map -)
only writes the output once.
This commit is contained in:
Fangrui Song 2025-01-25 16:54:19 -08:00
parent 6b87f01aaa
commit a9e92beb25

View File

@ -105,6 +105,13 @@ llvm::raw_fd_ostream Ctx::openAuxiliaryFile(llvm::StringRef filename,
using namespace llvm::sys::fs;
OpenFlags flags =
auxiliaryFiles.insert(filename).second ? OF_None : OF_Append;
if (e.disableOutput && filename == "-") {
#ifdef _WIN32
filename = "NUL";
#else
filename = "/dev/null";
#endif
}
return {filename, ec, flags};
}