Index: lld/test/ELF/stdout.s =================================================================== --- /dev/null +++ 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 Index: llvm/lib/Support/FileOutputBuffer.cpp =================================================================== --- llvm/lib/Support/FileOutputBuffer.cpp +++ llvm/lib/Support/FileOutputBuffer.cpp @@ -88,6 +88,11 @@ size_t getBufferSize() const override { return Buffer.size(); } Error commit() override { + if (FinalPath == "-") { + llvm::outs() << StringRef((const char *)Buffer.base(), Buffer.size()); + return Error::success(); + } + using namespace sys::fs; int FD; std::error_code EC; @@ -150,6 +155,10 @@ // Create an instance of FileOutputBuffer. Expected> FileOutputBuffer::create(StringRef Path, size_t Size, unsigned Flags) { + // Handle "-" as stdout just like llvm::raw_ostream does. + if (Path == "-") + return createInMemoryBuffer(Path, Size, 0); + unsigned Mode = fs::all_read | fs::all_write; if (Flags & F_executable) Mode |= fs::all_exe;