[PATCH] D56940: FileOutputBuffer: Treat "-" as the stdout.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 18 16:27:37 PST 2019


ruiu updated this revision to Diff 182634.
ruiu added a comment.

- simplify


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56940/new/

https://reviews.llvm.org/D56940

Files:
  lld/test/ELF/stdout.s
  llvm/lib/Support/FileOutputBuffer.cpp


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<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(Path, Size, 0);
+
   unsigned Mode = fs::all_read | fs::all_write;
   if (Flags & F_executable)
     Mode |= fs::all_exe;
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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56940.182634.patch
Type: text/x-patch
Size: 1359 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190119/47149df5/attachment.bin>


More information about the llvm-commits mailing list