[lld] [lld] lld/ELF/Writer.cpp: write directly to outs when output is "-" (PR #72061)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 12 10:52:33 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld
Author: Keith Winstein (keithw)
<details>
<summary>Changes</summary>
This PR lets the LLD ELF driver write directly to outs (skipping the filesystem) when the output filename is "-".
This is a step towards being able to use LLD as a library without using an `open` syscall.
---
Full diff: https://github.com/llvm/llvm-project/pull/72061.diff
1 Files Affected:
- (modified) lld/ELF/Writer.cpp (+7)
``````````diff
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)));
``````````
</details>
https://github.com/llvm/llvm-project/pull/72061
More information about the llvm-commits
mailing list