]> granicus.if.org Git - llvm/commitdiff
Following r297661, disable dup workaround to disable duplicate STDOUT fd closing...
authorYaron Keren <yaron.keren@gmail.com>
Thu, 30 Mar 2017 19:30:51 +0000 (19:30 +0000)
committerYaron Keren <yaron.keren@gmail.com>
Thu, 30 Mar 2017 19:30:51 +0000 (19:30 +0000)
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.

reviewed by Rafael Espindola

Differential Revision: https://reviews.llvm.org/D31505

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@299098 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/raw_ostream.cpp

index 5deab5de4f6a583f60bc81511b093cb15c56df56..d804a006824c2e6335267c24892a9fbf79bae533 100644 (file)
@@ -473,7 +473,7 @@ static int getFD(StringRef Filename, std::error_code &EC,
     // possible.
     if (!(Flags & sys::fs::F_Text))
       sys::ChangeStdoutToBinary();
-    return dup(STDOUT_FILENO);
+    return STDOUT_FILENO;
   }
 
   int FD;
@@ -497,6 +497,13 @@ raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered)
     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);