Turn stdout into binary mode during bitcode emission.
authorAnton Korobeynikov <asl@math.spbu.ru>
Fri, 6 Jun 2008 07:24:01 +0000 (07:24 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Fri, 6 Jun 2008 07:24:01 +0000 (07:24 +0000)
This is necessary on windows targets, since stdout is in text mode there.
Patch by Julien Lerouge!

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

lib/Bitcode/Writer/BitcodeWriter.cpp

index df644d00b925d11fb30ad984c997ffe9adfa0ac9..0030aca3bc5a6d97b44f00734921fe4ee6bf9350 100644 (file)
@@ -23,6 +23,7 @@
 #include "llvm/TypeSymbolTable.h"
 #include "llvm/ValueSymbolTable.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/System/Program.h"
 using namespace llvm;
 
 /// These are manifest constants used by the bitcode writer. They do not need to
@@ -1292,6 +1293,10 @@ void llvm::WriteBitcodeToFile(const Module *M, std::ostream &Out) {
   // Emit the module.
   WriteModule(M, Stream);
   
+  // If writing to stdout, set binary mode.
+  if (llvm::cout == Out)
+      sys::Program::ChangeStdoutToBinary();
+
   // Write the generated bitstream to "Out".
   Out.write((char*)&Buffer.front(), Buffer.size());