cassanova updated this revision to Diff 443362.
cassanova edited the summary of this revision.
cassanova added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Building the expression evaluator fuzzer is now conditional on the
CLANG_ENABLE_PROTO_FUZZER CMake variable being enabled.
Copying the source and header files from is no longer being done in the
top-level CMake file, this is instead added to the subdirectories of the clang
fuzzer.
The fuzzer uses Clang's CMake modules for libprotobuf_mutator instead of
copying the module into LLDB.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D129377/new/
https://reviews.llvm.org/D129377
Files:
clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
Index: lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
===================================================================
--- lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
+++ lldb/tools/lldb-fuzzer/lldb-expression-fuzzer/CMakeLists.txt
@@ -1,89 +1,50 @@
-set(LLVM_LINK_COMPONENTS
- Support
- )
-
-add_llvm_fuzzer(lldb-expression-fuzzer
- EXCLUDE_FROM_ALL
- lldb-expression-fuzzer.cpp
- )
-
-if(TARGET lldb-expression-fuzzer)
- target_include_directories(lldb-expression-fuzzer PRIVATE ..)
-
- # Generate the necessary source and header files for using protobufs
- find_package(Protobuf REQUIRED)
- add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI)
- include_directories(${PROTOBUF_INCLUDE_DIRS})
- include_directories(${CMAKE_CURRENT_BINARY_DIR})
- protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS cxx_proto.proto)
- protobuf_generate_cpp(LOOP_PROTO_SRCS LOOP_PROTO_HDRS cxx_loop_proto.proto)
- set(LLVM_OPTIONAL_SOURCES ${LLVM_OPTIONAL_SOURCES} ${PROTO_SRCS})
-
- # Place the source and header files into a library for use by LLDB's expression fuzzer
- # FIXME: It would be better to use add_lldb_library, but using this will cause an error
- # during cmake's file generation phase
- add_library(lldbCXXProto
- ${PROTO_SRCS}
- ${PROTO_HDRS}
- )
-
- # Build and include the libprotobuf-mutator repository
- include(ProtobufMutator)
- include_directories(${ProtobufMutator_INCLUDE_DIRS})
-
- # Create a variable for the libraries generated by protobuf and protobuf mutator
- set(COMMON_PROTO_FUZZ_LIBRARIES
- ${ProtobufMutator_LIBRARIES}
- ${PROTOBUF_LIBRARIES}
- )
-
- # Link the protobuf libraries as well as the clang libraries used to
- # convert protobufs to C/C++
- target_link_libraries(lldb-expression-fuzzer
- PRIVATE
- ${COMMON_PROTO_FUZZ_LIBRARIES}
- clangHandleCXX
- lldbCXXProto
- clangProtoToCXX
- liblldb
+if(CLANG_ENABLE_PROTO_FUZZER)
+ set(LLVM_LINK_COMPONENTS
+ Support
)
- # The target for this fuzzer needs to depend on the protobuf mutator
- # repository
- add_dependencies(lldb-expression-fuzzer lldb_protobuf_mutator)
-
- add_custom_command(TARGET lldb-expression-fuzzer PRE_BUILD
-
- # FIXME: Copying the source and header files is not the preferred way to implement these libraries
- # on the LLDB side. It would be preferable to have the libraries for protobuf fuzzers be located
- # in a more central location
-
- # Create directories to store the files for handle-cxx and proto-to-cxx since the protobuf mutator
- # depends on them
- COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/handle-cxx
- COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/proto-to-cxx
-
- # Copy the header and source files for handle-cxx from clang
- COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../../../../clang/tools/clang-fuzzer/handle-cxx/handle_cxx.h ${CMAKE_CURRENT_BINARY_DIR}/handle-cxx
- COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../../../../clang/tools/clang-fuzzer/handle-cxx/handle_cxx.cpp ${CMAKE_CURRENT_BINARY_DIR}/handle-cxx
-
- # Copy the header and source files for proto-to-cxx from clang
- COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../../../../clang/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h ${CMAKE_CURRENT_BINARY_DIR}/proto-to-cxx
- COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../../../../clang/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.cpp ${CMAKE_CURRENT_BINARY_DIR}/proto-to-cxx
- COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../../../../clang/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx_main.cpp ${CMAKE_CURRENT_BINARY_DIR}/proto-to-cxx
-
- # Create and compile a simple C program using the command line. This is
- # needed because LLDB's expression evaluator needs a legitmate target
- # instead of a dummy target
- COMMAND echo 'int main (int argc, char** argv) { return 0\; }' | clang -o main.out -xc -
+ add_llvm_fuzzer(lldb-expression-fuzzer
+ EXCLUDE_FROM_ALL
+ lldb-expression-fuzzer.cpp
)
- # Create a directory for storing the fuzzer's artifacts and run the fuzzer with arguments that will
- # not attempt to reduce the size of the inputs being generated
- add_custom_target(fuzz-lldb-expression
- COMMENT "Running the LLDB expression evaluator fuzzer..."
- WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/fuzzer-artifacts/expression-artifacts
- COMMAND $<TARGET_FILE:lldb-expression-fuzzer> -artifact_prefix=expression- -reduce_inputs=0
- USES_TERMINAL
- )
-endif()
+ if(TARGET lldb-expression-fuzzer)
+ target_include_directories(lldb-expression-fuzzer PRIVATE ..)
+
+ set(CLANG_CMAKE_MODULE_PATH
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../../clang/cmake/module)
+
+ set(CMAKE_MODULE_PATH
+ ${CMAKE_MODULE_PATH}
+ ${CLANG_CMAKE_MODULE_PATH})
+
+ include(ProtobufMutator)
+ include_directories(${ProtobufMutator_INCLUDE_DIRS})
+
+ target_link_libraries(lldb-expression-fuzzer
+ PRIVATE
+ ${ProtobufMutator_LIBRARIES}
+ ${LLVM_LIB_FUZZING_ENGINE}
+ clangHandleCXX
+ clangCXXProto
+ clangProtoToCXX
+ liblldb
+ )
+
+ add_custom_command(TARGET lldb-expression-fuzzer PRE_BUILD
+ # Create and compile a simple C program using the command line. This is
+ # needed because LLDB's expression evaluator needs a legitmate target
+ # instead of a dummy target
+ COMMAND echo 'int main (int argc, char** argv) { return 0\; }' | clang -o main.out -xc -
+ )
+
+ # Create a directory for storing the fuzzer's artifacts and run the fuzzer with arguments that will
+ # not attempt to reduce the size of the inputs being generated
+ add_custom_target(fuzz-lldb-expression
+ COMMENT "Running the LLDB expression evaluator fuzzer..."
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/fuzzer-artifacts/expression-artifacts
+ COMMAND $<TARGET_FILE:lldb-expression-fuzzer> -artifact_prefix=expression- -reduce_inputs=0
+ USES_TERMINAL
+ )
+ endif()
+endif
Index: clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
===================================================================
--- clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
+++ clang/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
@@ -14,6 +14,8 @@
DEPENDS clangCXXLoopProto
LINK_LIBS clangCXXLoopProto ${PROTOBUF_LIBRARIES}
)
+target_include_directories(clangProtoToCXX PUBLIC .)
+target_include_directories(clangLoopProtoToCXX PUBLIC .)
add_clang_executable(clang-proto-to-cxx proto_to_cxx_main.cpp)
add_clang_executable(clang-loop-proto-to-cxx loop_proto_to_cxx_main.cpp)
Index: clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
===================================================================
--- clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
+++ clang/tools/clang-fuzzer/handle-cxx/CMakeLists.txt
@@ -11,3 +11,5 @@
clangSerialization
clangTooling
)
+
+target_include_directories(clangHandleCXX PUBLIC .)
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits