On windows, the standard output is not set to binary mode by default so
all '\n' characters are replaced with '\r\n'. This is a pain for any
command using stdout, like "llvm-as < input.ll > out.bc", because out.bc
is then most likely corrupted.
This is an old story, fixed a while ago:
And here is the thread on LLVMDev:
Unfortunately, this bug is back. ChangeStdoutToBinary is never called in
the current LLVM tree. I guess the call was lost during the
The attached patches fix that by calling ChangeStdoutToBinary in
WriteBitcodeToFile if the output stream is llvm::cout. This works for
all the LLVM tools, because they use llvm::cout, but it doesn't work for
llvm-gcc for example, because it is creating a new ostream from stdout,
so I have another patch for the llvm-backend.
Is there a canonical / portable way to check if an ostream is the
standard output ?
Hope this helps,
llvm-bin-output.diff (792 Bytes)
llvm-gcc-bin-output.diff (1.08 KB)