This is an archive of the discontinued LLVM Phabricator instance.

[libFuzzer][MSVC] Enable building libFuzzer with MSVC
ClosedPublic

Authored by metzman on Jan 9 2019, 12:54 PM.

Details

Summary

Enable building libFuzzer with MSVC.

Make the following changes to allow this:

  • Don't try to include <endian.h> in FuzzerSHA1.cpp. MSVC doesn't have this header, and WINDOWS is always little endian (even on ARM)
  • Remove unneeded cast.
  • Account for long being 32 bit on x86 Windows to avoid

warnings.

  • Use /Ehsc to silence warnings.
  • Don't use macros to redefine thread_local since MSVC

complains about it, and it isn't necessary in Windows builds.

Diff Detail

Repository
rL LLVM

Event Timeline

metzman created this revision.Jan 9 2019, 12:54 PM
metzman updated this revision to Diff 180911.Jan 9 2019, 12:55 PM
  • undo changes possibly affecting x86 Linux
metzman updated this revision to Diff 182940.Jan 22 2019, 9:59 AM

Fix compile error

metzman added a subscriber: rnk.

Matt or Vitaly can you please take a look?

This is change enables building libFuzzer with MSVC and fixes any outstanding issues and warnings.

cc @rnk

This revision is now accepted and ready to land.Jan 22 2019, 10:54 AM
metzman edited the summary of this revision. (Show Details)Jan 22 2019, 10:58 AM
metzman edited the summary of this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.
rnk added inline comments.Jan 22 2019, 4:45 PM
compiler-rt/trunk/lib/fuzzer/CMakeLists.txt
77

Are you sure we want to enable exceptional destructor cleanups in libfuzzer targets? I don't think it will hurt, but what warnings are we hitting? Does libfuzzer actually use try/catch? If so, yes, this makes sense.

metzman marked an inline comment as done.Jan 22 2019, 7:00 PM
metzman added inline comments.
compiler-rt/trunk/lib/fuzzer/CMakeLists.txt
77

Are you sure we want to enable exceptional destructor cleanups in libfuzzer targets?

Not particularly, I did it to silence the warnings.

but what warnings are we hitting?

We get about 30 of these warnings:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428\include\xlocale(315): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc

I think the problem is with FuzzerDefs.h which is included by almost every file.

Does libfuzzer actually use try/catch?

I think it doens't do so explicitly but I assumed it did implicitly by including a system header that uses try/catch.

Maybe we should just get rid of this change and ignore the warning.

rnk added a comment.Jan 23 2019, 2:14 PM

I think that means you need to pass -D_HAS_EXCEPTIONS=0 to suppress try / catch usage in the Visual C++ STL headers. Usually /EHs-c- /D_HAS_EXCEPTIONS=0 go together as the canonical "disable exceptions" flags.

In D56510#1368480, @rnk wrote:

I think that means you need to pass -D_HAS_EXCEPTIONS=0 to suppress try / catch usage in the Visual C++ STL headers. Usually /EHs-c- /D_HAS_EXCEPTIONS=0 go together as the canonical "disable exceptions" flags.

OK. I opened https://reviews.llvm.org/D57119 to address this.