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);