[lld] [lld] lld/ELF/Writer.cpp: write directly to outs when output is "-" (PR #72061)

Keith Winstein via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 13 18:39:39 PST 2023


https://github.com/keithw updated https://github.com/llvm/llvm-project/pull/72061

>From cb96e84f82c2057f9372bd0051d7639fb7c0ca04 Mon Sep 17 00:00:00 2001
From: Yuhan Deng <yhdeng at stanford.edu>
Date: Thu, 2 Feb 2023 14:16:14 -0800
Subject: [PATCH] [lld] lld/ELF/Writer.cpp: write directly to outs when output
 is "-"

Co-authored-by: Keith Winstein <keithw at cs.stanford.edu>
---
 lld/ELF/Writer.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index a84e4864ab0e5a5..b5d0c0cafd230dd 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -652,6 +652,13 @@ template <class ELFT> void Writer<ELFT>::run() {
     if (errorCount())
       return;
 
+    if (config->outputFile == "-") {
+      lld::outs() << StringRef((const char *)buffer->getBufferStart(),
+                               buffer->getBufferSize());
+      lld::outs().flush();
+      return;
+    }
+
     if (auto e = buffer->commit())
       fatal("failed to write output '" + buffer->getPath() +
             "': " + toString(std::move(e)));



More information about the llvm-commits mailing list