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
// possible.
if (!(Flags & sys::fs::F_Text))
sys::ChangeStdoutToBinary();
- return dup(STDOUT_FILENO);
+ return STDOUT_FILENO;
}
int FD;
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);