[PATCH] D31505: Do not close STD* descriptors

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 30 12:43:25 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL299098: Following r297661, disable dup workaround to disable duplicate STDOUT fd… (authored by yrnkrn).

Changed prior to commit:
  https://reviews.llvm.org/D31505?vs=93521&id=93526#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31505

Files:
  llvm/trunk/lib/Support/raw_ostream.cpp


Index: llvm/trunk/lib/Support/raw_ostream.cpp
===================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp
+++ llvm/trunk/lib/Support/raw_ostream.cpp
@@ -473,7 +473,7 @@
     // possible.
     if (!(Flags & sys::fs::F_Text))
       sys::ChangeStdoutToBinary();
-    return dup(STDOUT_FILENO);
+    return STDOUT_FILENO;
   }
 
   int FD;
@@ -497,6 +497,13 @@
     ShouldClose = false;
     return;
   }
+  // We do not want to close STDOUT as there may have been several uses of it
+  // such as the case: llc %s -o=- -pass-remarks-output=- -filetype=asm
+  // which cause multiple closes of STDOUT_FILENO and/or use-after-close of it.
+  // Using dup() in getFD doesn't work as we end up with original STDOUT_FILENO
+  // open anyhow.
+  if (FD <= STDERR_FILENO)
+    ShouldClose = false;
 
   // Get the starting position.
   off_t loc = ::lseek(FD, 0, SEEK_CUR);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31505.93526.patch
Type: text/x-patch
Size: 916 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170330/9545c49f/attachment.bin>


More information about the llvm-commits mailing list