[llvm] r270912 - [LibFuzzer] Allow LibFuzzer to be built in modes other than RELEASE.

Dan Liew via llvm-commits llvm-commits at lists.llvm.org
Thu May 26 13:55:06 PDT 2016


Author: delcypher
Date: Thu May 26 15:55:05 2016
New Revision: 270912

URL: http://llvm.org/viewvc/llvm-project?rev=270912&view=rev
Log:
[LibFuzzer] Allow LibFuzzer to be built in modes other than RELEASE.

Previously the flags were only being set correctly when the
build type was "Release". Now the build should work properly
for all the supported build types. When building libFuzzer
the optimization level respects whatever is used for the
rest of LLVM but for the LibFuzzer tests we force -O0.

Differential Revision: http://reviews.llvm.org/D20558

Modified:
    llvm/trunk/lib/Fuzzer/CMakeLists.txt
    llvm/trunk/lib/Fuzzer/test/CMakeLists.txt
    llvm/trunk/lib/Fuzzer/test/dfsan/CMakeLists.txt
    llvm/trunk/lib/Fuzzer/test/trace-bb/CMakeLists.txt
    llvm/trunk/lib/Fuzzer/test/trace-pc/CMakeLists.txt
    llvm/trunk/lib/Fuzzer/test/ubsan/CMakeLists.txt
    llvm/trunk/lib/Fuzzer/test/uninstrumented/CMakeLists.txt

Modified: llvm/trunk/lib/Fuzzer/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/CMakeLists.txt?rev=270912&r1=270911&r2=270912&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/CMakeLists.txt Thu May 26 15:55:05 2016
@@ -1,6 +1,6 @@
-set(LIBFUZZER_FLAGS_BASE "${CMAKE_CXX_FLAGS_RELEASE}")
+set(LIBFUZZER_FLAGS_BASE "${CMAKE_CXX_FLAGS}")
 # Disable the coverage and sanitizer instrumentation for the fuzzer itself.
-set(CMAKE_CXX_FLAGS_RELEASE "${LIBFUZZER_FLAGS_BASE} -O2 -fno-sanitize=all -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters -Werror")
+set(CMAKE_CXX_FLAGS "${LIBFUZZER_FLAGS_BASE} -fno-sanitize=all -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters -Werror")
 if( LLVM_USE_SANITIZE_COVERAGE )
   add_library(LLVMFuzzerNoMainObjects OBJECT
     FuzzerCrossOver.cpp

Modified: llvm/trunk/lib/Fuzzer/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/CMakeLists.txt?rev=270912&r1=270911&r2=270912&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/CMakeLists.txt Thu May 26 15:55:05 2016
@@ -1,8 +1,31 @@
 # Build all these tests with -O0, otherwise optimizations may merge some
 # basic blocks and we'll fail to discover the targets.
-# Also enable the coverage instrumentation back (it is disabled
-# for the Fuzzer lib)
-set(CMAKE_CXX_FLAGS_RELEASE "${LIBFUZZER_FLAGS_BASE} -O0 -fsanitize-coverage=edge,indirect-calls")
+# We change the flags for every build type because we might be doing
+# a multi-configuration build (e.g. Xcode) where CMAKE_BUILD_TYPE doesn't
+# mean anything.
+set(variables_to_filter
+  CMAKE_CXX_FLAGS_RELEASE
+  CMAKE_CXX_FLAGS_DEBUG
+  CMAKE_CXX_FLAGS_RELWITHDEBINFO
+  CMAKE_CXX_FLAGS_MINSIZEREL
+  LIBFUZZER_FLAGS_BASE
+  )
+foreach (VARNAME ${variables_to_filter})
+  string(REPLACE " " ";" BUILD_FLAGS_AS_LIST "${${VARNAME}}")
+  set(new_flags "")
+  foreach (flag ${BUILD_FLAGS_AS_LIST})
+    # NOTE: Use of XX here is to avoid a CMake warning due to CMP0054
+    if (NOT ("XX${flag}" MATCHES "XX-O[0123s]"))
+      set(new_flags "${new_flags} ${flag}")
+    else()
+      set(new_flags "${new_flags} -O0")
+    endif()
+  endforeach()
+  set(${VARNAME} "${new_flags}")
+endforeach()
+
+# Enable the coverage instrumentation (it is disabled for the Fuzzer lib).
+set(CMAKE_CXX_FLAGS "${LIBFUZZER_FLAGS_BASE} -fsanitize-coverage=edge,indirect-calls")
 
 set(DFSanTests
   MemcmpTest

Modified: llvm/trunk/lib/Fuzzer/test/dfsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/dfsan/CMakeLists.txt?rev=270912&r1=270911&r2=270912&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/dfsan/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/dfsan/CMakeLists.txt Thu May 26 15:55:05 2016
@@ -1,7 +1,7 @@
 # These tests depend on both coverage and dfsan instrumentation.
 
-set(CMAKE_CXX_FLAGS_RELEASE
-  "${LIBFUZZER_FLAGS_BASE} -O0 -fno-sanitize=all -fsanitize=dataflow")
+set(CMAKE_CXX_FLAGS
+  "${LIBFUZZER_FLAGS_BASE} -fno-sanitize=all -fsanitize=dataflow")
 
 foreach(Test ${DFSanTests})
   add_executable(LLVMFuzzer-${Test}-DFSan

Modified: llvm/trunk/lib/Fuzzer/test/trace-bb/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/trace-bb/CMakeLists.txt?rev=270912&r1=270911&r2=270912&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/trace-bb/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/trace-bb/CMakeLists.txt Thu May 26 15:55:05 2016
@@ -1,6 +1,6 @@
 # These tests are not instrumented with coverage.
 
-set(CMAKE_CXX_FLAGS_RELEASE
+set(CMAKE_CXX_FLAGS
   "${LIBFUZZER_FLAGS_BASE} -fsanitize-coverage=edge,trace-bb")
 
 foreach(Test ${TraceBBTests})

Modified: llvm/trunk/lib/Fuzzer/test/trace-pc/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/trace-pc/CMakeLists.txt?rev=270912&r1=270911&r2=270912&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/trace-pc/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/trace-pc/CMakeLists.txt Thu May 26 15:55:05 2016
@@ -1,7 +1,7 @@
 # These tests are not instrumented with coverage.
 
-set(CMAKE_CXX_FLAGS_RELEASE
-  "${LIBFUZZER_FLAGS_BASE} -O0 -fno-sanitize-coverage=8bit-counters -fsanitize-coverage=trace-pc")
+set(CMAKE_CXX_FLAGS
+  "${LIBFUZZER_FLAGS_BASE} -fno-sanitize-coverage=8bit-counters -fsanitize-coverage=trace-pc")
 
 foreach(Test ${TracePCTests})
   add_executable(LLVMFuzzer-${Test}-TracePC

Modified: llvm/trunk/lib/Fuzzer/test/ubsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/ubsan/CMakeLists.txt?rev=270912&r1=270911&r2=270912&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/ubsan/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/ubsan/CMakeLists.txt Thu May 26 15:55:05 2016
@@ -1,7 +1,7 @@
 # These tests are instrumented with ubsan in non-recovery mode.
 
-set(CMAKE_CXX_FLAGS_RELEASE
-  "${LIBFUZZER_FLAGS_BASE} -O0 -fsanitize=undefined -fno-sanitize-recover=all")
+set(CMAKE_CXX_FLAGS
+  "${LIBFUZZER_FLAGS_BASE} -fsanitize=undefined -fno-sanitize-recover=all")
 
 foreach(Test ${UbsanTests})
   add_executable(LLVMFuzzer-${Test}-Ubsan

Modified: llvm/trunk/lib/Fuzzer/test/uninstrumented/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/uninstrumented/CMakeLists.txt?rev=270912&r1=270911&r2=270912&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/uninstrumented/CMakeLists.txt (original)
+++ llvm/trunk/lib/Fuzzer/test/uninstrumented/CMakeLists.txt Thu May 26 15:55:05 2016
@@ -1,7 +1,7 @@
 # These tests are not instrumented with coverage.
 
-set(CMAKE_CXX_FLAGS_RELEASE
-  "${LIBFUZZER_FLAGS_BASE} -O0 -fno-sanitize=all -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters")
+set(CMAKE_CXX_FLAGS
+  "${LIBFUZZER_FLAGS_BASE} -fno-sanitize=all -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters")
 
 foreach(Test ${UninstrumentedTests})
   add_executable(LLVMFuzzer-${Test}-Uninstrumented




More information about the llvm-commits mailing list