11# Copyright (C) 2019 Intel Corporation. All rights reserved.
22# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33
4- cmake_minimum_required (VERSION 2.8 )
4+ cmake_minimum_required (VERSION 3.14 )
55
6- if (NOT DEFINED CMAKE_C_COMPILER )
7- set (CMAKE_C_COMPILER "clang" )
8- endif ()
9- if (NOT DEFINED CMAKE_CXX_COMPILER )
10- set (CMAKE_CXX_COMPILER "clang++" )
11- endif ()
6+ project (wasm_fuzzing LANGUAGES C CXX )
127
13- project (wasm_mutator)
8+ # Ensure Clang is used as the compiler
9+ if (NOT CMAKE_C_COMPILER_ID STREQUAL "Clang" OR NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
10+ message (FATAL_ERROR "Please use Clang as the C compiler for libFuzzer compatibility." )
11+ endif ()
1412
15- set (CMAKE_BUILD_TYPE Debug)
13+ set (CMAKE_BUILD_TYPE Debug)
14+ set (CMAKE_C_STANDARD 11)
15+ set (CMAKE_CXX_STANDARD 17)
1616
17- string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
17+ string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
1818
1919# Reset default linker flags
20- set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "" )
21- set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "" )
22-
23- set (CMAKE_C_STANDARD 11)
24- set (CMAKE_CXX_STANDARD 17)
25-
26- # Set WAMR_BUILD_TARGET, currently values supported:
27- # "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
28- # "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
29- if (NOT DEFINED WAMR_BUILD_TARGET)
30- if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)" )
31- set (WAMR_BUILD_TARGET "AARCH64" )
32- elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64" )
33- set (WAMR_BUILD_TARGET "RISCV64" )
34- elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
35- # Build as X86_64 by default in 64-bit platform
36- set (WAMR_BUILD_TARGET "X86_64" )
37- elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
38- # Build as X86_32 by default in 32-bit platform
39- set (WAMR_BUILD_TARGET "X86_32" )
40- else ()
20+ set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "" )
21+ set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "" )
22+
23+ # Determine WAMR_BUILD_TARGET based on system properties
24+ if (NOT DEFINED WAMR_BUILD_TARGET)
25+ if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)" )
26+ set (WAMR_BUILD_TARGET "AARCH64" )
27+ elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64" )
28+ set (WAMR_BUILD_TARGET "RISCV64" )
29+ elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
30+ set (WAMR_BUILD_TARGET "X86_64" )
31+ elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
32+ set (WAMR_BUILD_TARGET "X86_32" )
33+ else ()
4134 message (SEND_ERROR "Unsupported build target platform!" )
42- endif ()
43- endif ()
35+ endif ()
36+ endif ()
4437
45- if (APPLE )
38+ if (APPLE )
4639 add_definitions (-DBH_PLATFORM_DARWIN )
47- endif ()
48-
49- if (CUSTOM_MUTATOR EQUAL 1)
50- add_compile_definitions (CUSTOM_MUTATOR )
5140endif ()
5241
53- if (NOT DEFINED WAMR_BUILD_INTERP)
54- # Enable Interpreter by default
55- set (WAMR_BUILD_INTERP 1)
56- endif ()
57-
58- if (NOT DEFINED WAMR_BUILD_AOT)
59- # Enable AOT by default.
60- set (WAMR_BUILD_AOT 1)
61- endif ()
62-
63- if (NOT DEFINED WAMR_BUILD_JIT)
64- # Disable JIT by default.
65- set (WAMR_BUILD_JIT 0)
66- endif ()
67-
68- if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
69- # Disable libc builtin support by default
70- set (WAMR_BUILD_LIBC_BUILTIN 0)
71- endif ()
72-
73- if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
74- # Enable libc wasi support by default
75- set (WAMR_BUILD_LIBC_WASI 0)
76- endif ()
77-
78- if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
79- # Enable fast interpreter
80- set (WAMR_BUILD_FAST_INTERP 1)
81- endif ()
82-
83- if (NOT DEFINED WAMR_BUILD_MULTI_MODULE)
84- # Disable multiple modules
85- set (WAMR_BUILD_MULTI_MODULE 0)
86- endif ()
87-
88- if (NOT DEFINED WAMR_BUILD_LIB_PTHREAD)
89- # Disable pthread library by default
90- set (WAMR_BUILD_LIB_PTHREAD 0)
91- endif ()
92-
93- if (NOT DEFINED WAMR_BUILD_MINI_LOADER)
94- # Disable wasm mini loader by default
95- set (WAMR_BUILD_MINI_LOADER 0)
96- endif ()
97-
98- if (NOT DEFINED WAMR_BUILD_SIMD)
99- # Enable SIMD by default
100- set (WAMR_BUILD_SIMD 1)
101- endif ()
102-
103- if (NOT DEFINED WAMR_BUILD_REF_TYPES)
104- # Enable reference type by default
105- set (WAMR_BUILD_REF_TYPES 1)
106- endif ()
107-
108- if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP)
109- # Disable Debug feature by default
110- set (WAMR_BUILD_DEBUG_INTERP 0)
111- endif ()
112-
113- if (WAMR_BUILD_DEBUG_INTERP EQUAL 1)
114- set (WAMR_BUILD_FAST_INTERP 0)
115- set (WAMR_BUILD_MINI_LOADER 0)
116- set (WAMR_BUILD_SIMD 0)
117- endif ()
118-
119- # sanitizer may use kHandleSignalExclusive to handle SIGSEGV
120- # like `UBSAN_OPTIONS=handle_segv=2:...`
121- set (WAMR_DISABLE_HW_BOUND_CHECK 1)
122- # Enable aot validator
123- set (WAMR_BUILD_AOT_VALIDATOR 1)
124-
125- set (REPO_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR} /../../..)
126- message ([ceith]:REPO_ROOT_DIR, ${REPO_ROOT_DIR} )
127-
128- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} " )
129- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} " )
130-
131- add_definitions (-DWAMR_USE_MEM_POOL=0 -DWASM_ENABLE_FUZZ_TEST=1 )
42+ # Disable hardware bound check and enable AOT validator
43+ set (WAMR_DISABLE_HW_BOUND_CHECK 1)
44+ set (WAMR_BUILD_AOT_VALIDATOR 1)
45+
46+ set (REPO_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR} /../../..)
47+ message (STATUS "REPO_ROOT_DIR: ${REPO_ROOT_DIR} " )
48+
49+ set (LLVM_SRC_ROOT ${REPO_ROOT_DIR} /core/deps/llvm)
50+ set (LLVM_BUILD_ROOT ${LLVM_SRC_ROOT} /build)
51+ set (LLVM_DIR ${LLVM_BUILD_ROOT} /lib/cmake/llvm)
52+
53+ find_package (LLVM REQUIRED CONFIG )
54+
55+ message (STATUS "Found LLVM ${LLVM_PACKAGE_VERSION} " )
56+ message (STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR} " )
13257
13358# Enable fuzzer
59+ add_definitions (-DWASM_ENABLE_FUZZ_TEST=1 )
13460add_compile_options (-fsanitize=fuzzer )
13561add_link_options (-fsanitize=fuzzer )
13662
137- # if not calling from oss-fuzz helper, enable all support sanitizers
138- # oss-fuzz will define FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION in CFLAGS and CXXFLAGS
63+ # Enable sanitizers if not in oss-fuzz environment
13964set (CFLAGS_ENV $ENV{CFLAGS} )
14065string (FIND "${CFLAGS_ENV} " "-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" IN_OSS_FUZZ)
141- if (IN_OSS_FUZZ EQUAL -1)
142- message ("[ceith]: Enable ASan and UBSan in non-oss-fuzz environment" )
66+ if (IN_OSS_FUZZ EQUAL -1)
67+ message (STATUS " Enable ASan and UBSan in non-oss-fuzz environment" )
14368 add_compile_options (
14469 -fprofile-instr-generate -fcoverage-mapping
14570 -fno-sanitize-recover=all
14671 -fsanitize=address,undefined
147- # reference: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
148- # -fsanitize=undefined: All of the checks listed above other than float-divide-by-zero,
149- # unsigned-integer-overflow, implicit-conversion, local-bounds and
150- # the nullability-* group of checks.
151- #
152- # for now, we disable below from UBSan
153- # -alignment
154- # -implicit-conversion
155- #
15672 -fsanitize=float-divide-by-zero,unsigned-integer-overflow,local-bounds,nullability
15773 -fno-sanitize=alignment
15874 )
15975 add_link_options (-fsanitize=address -fprofile-instr-generate )
160- endif ()
161-
162- include (${REPO_ROOT_DIR} /core/shared/utils/uncommon/shared_uncommon.cmake )
163- include (${REPO_ROOT_DIR} /build-scripts/runtime_lib.cmake )
164-
165- add_library (vmlib ${WAMR_RUNTIME_LIB_SOURCE} )
166-
167- add_executable (wasm_mutator_fuzz wasm_mutator_fuzz.cc )
168- target_link_libraries (wasm_mutator_fuzz vmlib -lm )
169-
170- find_package (LLVM REQUIRED CONFIG )
171-
172- message (STATUS "Found LLVM ${LLVM_PACKAGE_VERSION} " )
173- message (STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR} " )
76+ endif ()
17477
175- include (${REPO_ROOT_DIR} /core/iwasm/compilation/iwasm_compl.cmake )
176- add_library (aotclib ${IWASM_COMPL_SOURCE} )
177- target_compile_definitions (aotclib PUBLIC -DWASM_ENABLE_WAMR_COMPILER=1 ${LLVM_DEFINITIONS} )
178- target_include_directories (aotclib PUBLIC ${LLVM_INCLUDE_DIRS} )
78+ add_subdirectory (wasm_mutator )
79+ add_subdirectory (aot_compiler )
0 commit comments