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

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 25 16:54:34 PST 2025


Author: Fangrui Song
Date: 2025-01-25T16:54:19-08:00
New Revision: a9e92beb253d4bbd7636d99f100940534f3a7f36

URL: https://github.com/llvm/llvm-project/commit/a9e92beb253d4bbd7636d99f100940534f3a7f36
DIFF: https://github.com/llvm/llvm-project/commit/a9e92beb253d4bbd7636d99f100940534f3a7f36.diff

LOG: [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.

Added: 
    

Modified: 
    lld/ELF/Driver.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 13e8f8ce6df207..c0a27b3939a54a 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -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};
 }
 


        


More information about the llvm-commits mailing list