Skip to content

Commit

Permalink
Following r297661, disable dup workaround to disable duplicate STDOUT…
Browse files Browse the repository at this point in the history
… fd closing and instead directly prevent closing of STD* file descriptors.

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

llvm-svn: 299098
  • Loading branch information
yrnkrn committed Mar 30, 2017
1 parent b876020 commit 9d27c47
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion llvm/lib/Support/raw_ostream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 9d27c47

Please sign in to comment.