[Compiler-rt] Fix InstrProfilingFile writing on Windows

Johan Engelen via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 14 15:01:13 PST 2015


Hello,
  I recently started using compiler-rt/lib/profile for
Instrumentation-based PGO in LDC (LLVM D Compiler), but ran into two issues
with the code on Windows:
(1) The code does not compile with MSVC because of "__attribute__"
(2) The file written by InstrProfilingFile.c is in a corrupt format on
Windows


(1) is easily fixed, and I will submit a patch in a second email.


(2) The file is corrupt because the file is opened in text mode with
fopen(..., "a"), instead of in binary mode fopen(..., "ab"). With MSVC,
this means that fwrite will silently add bytes to "fix" line-endings (i.e.
0x0A --> 0x0D 0x0A) !
The bug fix is trivial: open the file explicitly in binary mode.

I have attached a patch for the release_37 branch (I much appreciate it if
it can be committed, because I currently use this version of /lib/profile
successfully for PGO in LDC), and I have also attached a patch for trunk.

(btw, thanks for the work on /lib/profile! It made it very easy to add PGO
to LDC and worked flawlessly on OS X and Ubuntu!)

Cheers,
  Johan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151215/c8ff3d85/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TRUNK_profile_openfilebinary.patch
Type: application/octet-stream
Size: 449 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151215/c8ff3d85/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: RELEASE37_profile_openfilebinary.patch
Type: application/octet-stream
Size: 449 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151215/c8ff3d85/attachment-0001.obj>


More information about the llvm-commits mailing list