[PATCH] Fix object file writing in llvm-lto on Windows

Greg Bedwell greg_bedwell at sn.scee.net
Fri Oct 4 01:29:33 PDT 2013

gbedwell added you to the CC list for the revision "Fix object file writing in llvm-lto on Windows ".


This is a patch for the llvm-lto tool when running on Windows.  Windows makes a distinction between files written in text mode and files written in binary mode.  In text mode newlines will automatically be converted to Windows format with spurious CR characters being inserted which obviously will wreak havoc if it is really a binary file being written.  By default raw_fd_ostream will write files in text mode, so when the output object file was being written by llvm-lto.exe the resulting file was corrupted resulting in the existing LTO test failing at the point at which that file was read.  This change re-enables the test for Windows and explicitly specifies that the output file should be written as a binary file.  This matches the existing behaviour in LTOCodeGenerator::writeMergedModules.

Please commit for me if this is good to go.


Greg Bedwell
SN Systems - Sony Computer Entertainment Group



Index: test/LTO/cfi_endproc.ll
--- test/LTO/cfi_endproc.ll
+++ test/LTO/cfi_endproc.ll
@@ -4,9 +4,6 @@
 ; RUN: llvm-lto -o %t3 -exported-symbol=main %t1
 ; RUN: llvm-nm %t3 | FileCheck %s -check-prefix=EXPORT
-; FIXME: we can now build LTO on windows, debug why this fails.
-; XFAIL: win32
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
Index: test/LTO/lit.local.cfg
--- test/LTO/lit.local.cfg
+++ test/LTO/lit.local.cfg
@@ -2,5 +2,5 @@
 if not 'X86' in targets:
   config.unsupported = True
-if config.root.host_os in ['Cygwin', 'MingW', 'Windows']:
+if config.root.host_os in ['Cygwin']:
   config.unsupported = True
Index: tools/llvm-lto/llvm-lto.cpp
--- tools/llvm-lto/llvm-lto.cpp
+++ tools/llvm-lto/llvm-lto.cpp
@@ -136,7 +136,8 @@
       return 1;
-    raw_fd_ostream FileStream(OutputFilename.c_str(), ErrorInfo);
+    raw_fd_ostream FileStream(OutputFilename.c_str(), ErrorInfo,
+                              sys::fs::F_Binary);
     if (!ErrorInfo.empty()) {
       errs() << argv[0] << ": error opening the file '" << OutputFilename
              << "': " << ErrorInfo << "\n";
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1833.1.patch
Type: text/x-patch
Size: 1477 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131004/4d5a8973/attachment.bin>

More information about the llvm-commits mailing list