-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lld] lld/ELF/Writer.cpp: write directly to outs when output is "-" #72061
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-lld-elf Author: Keith Winstein (keithw) ChangesThis PR lets the LLD ELF driver write directly to outs (skipping the filesystem) when the output filename is "-". Full diff: https://github.com/llvm/llvm-project/pull/72061.diff 1 Files Affected:
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)));
|
@llvm/pr-subscribers-lld Author: Keith Winstein (keithw) ChangesThis PR lets the LLD ELF driver write directly to outs (skipping the filesystem) when the output filename is "-". Full diff: https://github.com/llvm/llvm-project/pull/72061.diff 1 Files Affected:
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)));
|
Co-authored-by: Keith Winstein <keithw@cs.stanford.edu>
1e16e4a
to
cb96e84
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ld.lld a.o -o -
already writes to stdout. See https://reviews.llvm.org/D56940
Yeah -- unfortunately that writes to Maybe there's a cleaner way to do this? I couldn't think of any that didn't involve a much bigger change (e.g. I guess we could think about changing the FileOutputBuffer in lld/ELF/Writer.cpp and changing the signature to |
Ah, thanks for the explanation. The description can mention
I think this is still fine but we need a unittest in |
This PR lets the LLD ELF driver write directly to lld::outs() (the
stdoutOS
argument tolld::elf::link()
), when the output filename is "-".This lets the LLD ELF driver be used as a library with its output written to an in-memory buffer.