diff options
-rw-r--r-- | lld/test/ELF/stdout.s | 12 | ||||
-rw-r--r-- | llvm/lib/Support/FileOutputBuffer.cpp | 10 |
2 files changed, 22 insertions, 0 deletions
diff --git a/lld/test/ELF/stdout.s b/lld/test/ELF/stdout.s new file mode 100644 index 00000000000..331167e3f7b --- /dev/null +++ b/lld/test/ELF/stdout.s @@ -0,0 +1,12 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld %t.o -o - > %t +# RUN: llvm-objdump -d %t | FileCheck %s + +# CHECK: 0000000000201000 _start: +# CHECK: 201000: 90 nop + +.globl _start +_start: + nop diff --git a/llvm/lib/Support/FileOutputBuffer.cpp b/llvm/lib/Support/FileOutputBuffer.cpp index 8a2bb6c0651..cf21cc19c01 100644 --- a/llvm/lib/Support/FileOutputBuffer.cpp +++ b/llvm/lib/Support/FileOutputBuffer.cpp @@ -87,6 +87,12 @@ public: size_t getBufferSize() const override { return Buffer.size(); } Error commit() override { + if (FinalPath == "-") { + llvm::outs() << StringRef((const char *)Buffer.base(), Buffer.size()); + llvm::outs().flush(); + return Error::success(); + } + using namespace sys::fs; int FD; std::error_code EC; @@ -149,6 +155,10 @@ createOnDiskBuffer(StringRef Path, size_t Size, unsigned Mode) { // Create an instance of FileOutputBuffer. Expected<std::unique_ptr<FileOutputBuffer>> FileOutputBuffer::create(StringRef Path, size_t Size, unsigned Flags) { + // Handle "-" as stdout just like llvm::raw_ostream does. + if (Path == "-") + return createInMemoryBuffer("-", Size, /*Mode=*/0); + unsigned Mode = fs::all_read | fs::all_write; if (Flags & F_executable) Mode |= fs::all_exe; |