Skip to content

Commit 427d5e5

Browse files
committed
fix(build): update WAMR_ROOT_DIR to use CURRENT_LIST_DIR for correct path resolution
1 parent edae5b3 commit 427d5e5

File tree

9 files changed

+183
-52
lines changed

9 files changed

+183
-52
lines changed

build-scripts/version.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
if(NOT WAMR_ROOT_DIR)
55
# if from wamr-compiler
6-
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
6+
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
77
endif()
88

99
set(WAMR_VERSION_MAJOR 2)

core/iwasm/compilation/aot_llvm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2521,7 +2521,8 @@ aot_compiler_init(void)
25212521
LLVMInitializeCore(LLVMGetGlobalPassRegistry());
25222522
#endif
25232523

2524-
#if WASM_ENABLE_WAMR_COMPILER != 0
2524+
/* fuzzing only use host targets for simple */
2525+
#if WASM_ENABLE_WAMR_COMPILER != 0 && WASM_ENABLE_FUZZ_TEST == 0
25252526
/* Init environment of all targets for AOT compiler */
25262527
LLVMInitializeAllTargetInfos();
25272528
LLVMInitializeAllTargets();

tests/fuzz/wasm-mutator-fuzz/CMakeLists.txt

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33

44
cmake_minimum_required(VERSION 3.14)
55

6-
project(wasm_fuzzing LANGUAGES C CXX)
6+
project(wamr_fuzzing LANGUAGES ASM C CXX)
7+
8+
include(CMakePrintHelpers)
79

810
# Ensure Clang is used as the compiler
9-
if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang" OR NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
11+
if(NOT CMAKE_C_COMPILER_ID STREQUAL "Clang"
12+
OR NOT CMAKE_ASM_COMPILER_ID STREQUAL "Clang")
1013
message(FATAL_ERROR "Please use Clang as the C compiler for libFuzzer compatibility.")
1114
endif()
1215

@@ -46,15 +49,33 @@ set(WAMR_BUILD_AOT_VALIDATOR 1)
4649
set(REPO_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..)
4750
message(STATUS "REPO_ROOT_DIR: ${REPO_ROOT_DIR}")
4851

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+
# Use LLVM_DIR from command line if defined
53+
# LLVM_DIR should be something like /path/to/llvm/build/lib/cmake/llvm
54+
if(DEFINED LLVM_DIR)
55+
set(LLVM_DIR $ENV{LLVM_DIR})
56+
else()
57+
set(LLVM_SRC_ROOT ${REPO_ROOT_DIR}/core/deps/llvm)
58+
set(LLVM_BUILD_ROOT ${LLVM_SRC_ROOT}/build)
59+
set(LLVM_DIR ${LLVM_BUILD_ROOT}/lib/cmake/llvm)
60+
endif()
61+
62+
# if LLVM_DIR is an existing directory, use it
63+
if(NOT EXISTS ${LLVM_DIR})
64+
message(FATAL_ERROR "LLVM_DIR not found: ${LLVM_DIR}")
65+
endif()
5266

5367
find_package(LLVM REQUIRED CONFIG)
5468

5569
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
5670
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
5771

72+
include_directories(${LLVM_INCLUDE_DIRS})
73+
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
74+
add_definitions(${LLVM_DEFINITIONS_LIST})
75+
76+
set(SHARED_DIR ${REPO_ROOT_DIR}/core/shared)
77+
set(IWASM_DIR ${REPO_ROOT_DIR}/core/iwasm)
78+
5879
# Enable fuzzer
5980
add_definitions(-DWASM_ENABLE_FUZZ_TEST=1)
6081
add_compile_options(-fsanitize=fuzzer)
@@ -75,5 +96,5 @@ if(IN_OSS_FUZZ EQUAL -1)
7596
add_link_options(-fsanitize=address -fprofile-instr-generate)
7697
endif()
7798

78-
add_subdirectory(wasm_mutator)
79-
add_subdirectory(aot_compiler)
99+
add_subdirectory(aot-compiler)
100+
add_subdirectory(wasm-mutator)

tests/fuzz/wasm-mutator-fuzz/README.md

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# WAMR fuzz test framework
22

3-
## install wasm-tools
3+
## Install wasm-tools
44

55
```bash
66
1.git clone https://github.com/bytecodealliance/wasm-tools
@@ -13,32 +13,44 @@ $ wasm-tools --version
1313
$ wasm-tools help
1414
```
1515

16+
## Install clang Toolchain
17+
18+
Refer to: https://apt.llvm.org/ and Make sure you have clang installed.
19+
20+
```bash
21+
$ which clang
22+
23+
$ which clang++
24+
25+
```
26+
1627
## Build
1728

1829
```bash
19-
mkdir build && cd build
2030
# Without custom mutator (libfuzzer modify the buffer randomly)
21-
cmake ..
22-
# TODO: TBC. `wasm-tools mutate` is not supported yet
23-
# With custom mutator (wasm-tools mutate)
24-
cmake .. -DCUSTOM_MUTATOR=1
25-
make -j$(nproc)
31+
$ cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=./clang_toolchain.cmake
32+
33+
# TBC: if `wasm-tools mutate` is supported or not
34+
# Or With custom mutator (wasm-tools mutate)
35+
$ cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=./clang_toolchain.cmake -DCUSTOM_MUTATOR=1
36+
37+
$ cmake --build build
2638
```
2739

2840
## Manually generate wasm file in build
2941

30-
```bash
42+
````bash
3143
# wasm-tools smith generate some valid wasm file
3244
# The generated wasm file is in corpus_dir under build
3345
# N - Number of files to be generated
34-
./smith_wasm.sh N
46+
$ ./smith_wasm.sh N
3547

3648
# running
3749
``` bash
38-
cd build
39-
./wasm-mutate-fuzz CORPUS_DIR
40-
41-
```
50+
$ ./build/wasm-mutator/wasm_mutator_fuzz ./build/CORPUS_DIR
51+
52+
$ ./build/aot-compiler/aot_compiler_fuzz ./build/CORPUS_DIR
53+
````
4254
4355
## Fuzzing Server
4456
@@ -49,20 +61,20 @@ $ pip install -r requirements.txt
4961

5062
2. Database Migration
5163
$ python3 app/manager.py db init
52-
$ python3 app/manager.py db migrate
53-
$ python3 app/manager.py db upgrade
64+
$ python3 app/manager.py db migrate
65+
$ python3 app/manager.py db upgrade
5466

5567
3. Change localhost to your machine's IP address
56-
$ cd ../portal
68+
$ cd ../portal
5769
$ vim .env # Change localhost to your machine's IP address # http://<ip>:16667
5870

5971
4. Run Server and Portal
6072
$ cd .. # Switch to the original directory
6173
If you want to customize the front-end deployment port: # defaut 9999
62-
$ vim .env # Please change the portal_port to the port you want to use
74+
$ vim .env # Please change the portal_port to the port you want to use
6375

6476
The server is deployed on port 16667 by default, If you want to change the server deployment port:
65-
$ vim .env # Please change the server_port to the port you want to use
77+
$ vim .env # Please change the server_port to the port you want to use
6678
$ vim portal/.env # Please change the VITE_SERVER_URL to the port you want to use # http://ip:<port>
6779

6880

tests/fuzz/wasm-mutator-fuzz/aot_compiler/CMakeLists.txt renamed to tests/fuzz/wasm-mutator-fuzz/aot-compiler/CMakeLists.txt

Lines changed: 93 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
# Copyright (C) 2019 Intel Corporation. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

4-
project(aot_compiler_fuzzing LANGUAGES ASM C CXX)
5-
6-
set(SHARED_DIR ${REPO_ROOT_DIR}/core/shared)
7-
set(IWASM_DIR ${REPO_ROOT_DIR}/core/iwasm)
8-
94
# Set default build options with the ability to override from the command line
105
if(NOT WAMR_BUILD_INTERP)
116
set(WAMR_BUILD_INTERP 1)
127
endif()
138

149
set(WAMR_BUILD_WAMR_COMPILER 1)
15-
set(WAMR_BUILD_INTERP 1)
1610
set(WAMR_BUILD_AOT 1)
11+
set(WAMR_BUILD_INTERP 1)
12+
set(WAMR_BUILD_JIT 0)
1713

1814
include(${SHARED_DIR}/platform/${WAMR_BUILD_PLATFORM}/shared_platform.cmake)
1915
include(${SHARED_DIR}/mem-alloc/mem_alloc.cmake)
@@ -28,7 +24,7 @@ include(${IWASM_DIR}/aot/iwasm_aot.cmake)
2824
include(${IWASM_DIR}/compilation/iwasm_compl.cmake)
2925
include(${REPO_ROOT_DIR}/build-scripts/version.cmake)
3026

31-
add_library(aotclib
27+
add_library(aotclib
3228
${PLATFORM_SHARED_SOURCE}
3329
${MEM_ALLOC_SHARED_SOURCE}
3430
${UTILS_SHARED_SOURCE}
@@ -41,9 +37,9 @@ add_library(aotclib
4137
${IWASM_COMPL_SOURCE}
4238
)
4339

44-
target_compile_definitions(aotclib
45-
PUBLIC
46-
-DWASM_ENABLE_WAMR_COMPILER=1
40+
target_compile_definitions(aotclib
41+
PUBLIC
42+
-DWASM_ENABLE_WAMR_COMPILER=1
4743
-DWASM_ENABLE_FAST_INTERP=0
4844
-DWASM_ENABLE_INTERP=1
4945
-DWASM_ENABLE_BULK_MEMORY=1
@@ -62,12 +58,95 @@ target_compile_definitions(aotclib
6258
${LLVM_DEFINITIONS}
6359
)
6460

65-
target_include_directories(aotclib PUBLIC
66-
${LLVM_INCLUDE_DIRS}
61+
target_include_directories(aotclib PUBLIC
6762
${IWASM_DIR}/include
6863
${SHARED_DIR}/include
6964
)
70-
target_link_libraries(aotclib PUBLIC ${LLVM_AVAILABLE_LIBS})
65+
66+
target_link_directories(aotclib PUBLIC ${LLVM_LIBRARY_DIR})
67+
68+
target_link_libraries(aotclib
69+
PUBLIC
70+
LLVMDemangle
71+
LLVMSupport
72+
LLVMTableGen
73+
LLVMTableGenGlobalISel
74+
LLVMCore
75+
LLVMFuzzerCLI
76+
LLVMFuzzMutate
77+
LLVMFileCheck
78+
LLVMInterfaceStub
79+
LLVMIRReader
80+
LLVMCodeGen
81+
LLVMSelectionDAG
82+
LLVMAsmPrinter
83+
LLVMMIRParser
84+
LLVMGlobalISel
85+
LLVMBinaryFormat
86+
LLVMBitReader
87+
LLVMBitWriter
88+
LLVMBitstreamReader
89+
LLVMDWARFLinker
90+
LLVMExtensions
91+
LLVMFrontendOpenACC
92+
LLVMFrontendOpenMP
93+
LLVMTransformUtils
94+
LLVMInstrumentation
95+
LLVMAggressiveInstCombine
96+
LLVMInstCombine
97+
LLVMScalarOpts
98+
LLVMipo
99+
LLVMVectorize
100+
LLVMObjCARCOpts
101+
LLVMCoroutines
102+
LLVMCFGuard
103+
LLVMLinker
104+
LLVMAnalysis
105+
LLVMLTO
106+
LLVMMC
107+
LLVMMCParser
108+
LLVMMCDisassembler
109+
LLVMMCA
110+
LLVMObjCopy
111+
LLVMObject
112+
LLVMObjectYAML
113+
LLVMOption
114+
LLVMRemarks
115+
LLVMDebuginfod
116+
LLVMDebugInfoDWARF
117+
LLVMDebugInfoGSYM
118+
LLVMDebugInfoMSF
119+
LLVMDebugInfoCodeView
120+
LLVMDebugInfoPDB
121+
LLVMSymbolize
122+
LLVMDWP
123+
LLVMExecutionEngine
124+
LLVMInterpreter
125+
LLVMJITLink
126+
LLVMMCJIT
127+
LLVMOrcJIT
128+
LLVMOrcShared
129+
LLVMOrcTargetProcess
130+
LLVMRuntimeDyld
131+
LLVMTarget
132+
LLVMX86CodeGen
133+
LLVMX86AsmParser
134+
LLVMX86Disassembler
135+
LLVMX86TargetMCA
136+
LLVMX86Desc
137+
LLVMX86Info
138+
LLVMAsmParser
139+
LLVMLineEditor
140+
LLVMProfileData
141+
LLVMCoverage
142+
LLVMPasses
143+
LLVMTextAPI
144+
LLVMDlltoolDriver
145+
LLVMLibDriver
146+
LLVMXRay
147+
LLVMWindowsDriver
148+
LLVMWindowsManifest
149+
)
71150

72151
add_executable(aot_compiler_fuzz aot_compiler_fuzz.cc)
73-
target_link_libraries(aot_compiler_fuzz PRIVATE aotclib m)
152+
target_link_libraries(aot_compiler_fuzz PRIVATE stdc++ aotclib)

tests/fuzz/wasm-mutator-fuzz/aot_compiler/aot_compiler_fuzz.cc renamed to tests/fuzz/wasm-mutator-fuzz/aot-compiler/aot_compiler_fuzz.cc

File renamed without changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
# Check for Clang C compiler
5+
find_program(CLANG_C_COMPILER NAMES clang)
6+
if(NOT CLANG_C_COMPILER)
7+
message(FATAL_ERROR "Clang C compiler not found. Please install Clang.")
8+
else()
9+
message(STATUS "Clang C compiler found: ${CLANG_C_COMPILER}")
10+
set(CMAKE_C_COMPILER ${CLANG_C_COMPILER})
11+
endif()
12+
13+
# Check for Clang C++ compiler
14+
find_program(CLANG_CXX_COMPILER NAMES clang++)
15+
if(NOT CLANG_CXX_COMPILER)
16+
message(FATAL_ERROR "Clang C++ compiler not found. Please install Clang.")
17+
else()
18+
message(STATUS "Clang C++ compiler found: ${CLANG_CXX_COMPILER}")
19+
set(CMAKE_CXX_COMPILER ${CLANG_CXX_COMPILER})
20+
endif()
21+
22+
# Check for Clang assembler
23+
find_program(CLANG_ASM_COMPILER NAMES clang)
24+
if(NOT CLANG_ASM_COMPILER)
25+
message(FATAL_ERROR "Clang assembler not found. Please install Clang.")
26+
else()
27+
message(STATUS "Clang assembler found: ${CLANG_ASM_COMPILER}")
28+
set(CMAKE_ASM_COMPILER ${CLANG_ASM_COMPILER})
29+
endif()

tests/fuzz/wasm-mutator-fuzz/wasm_mutator/CMakeLists.txt renamed to tests/fuzz/wasm-mutator-fuzz/wasm-mutator/CMakeLists.txt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Copyright (C) 2019 Intel Corporation. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

4-
project(wasm_mutator_fuzzing LANGUAGES ASM C CXX)
5-
64
if(CUSTOM_MUTATOR EQUAL 1)
75
add_compile_definitions(CUSTOM_MUTATOR)
86
endif()
@@ -57,12 +55,3 @@ target_link_directories(vmlib PUBLIC ${RUNTIME_LIB_LINK_LIST})
5755

5856
add_executable(wasm_mutator_fuzz wasm_mutator_fuzz.cc)
5957
target_link_libraries(wasm_mutator_fuzz PRIVATE vmlib m)
60-
61-
# Copyright (C) 2019 Intel Corporation. All rights reserved.
62-
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
63-
64-
project(wasm_mutator_fuzzing LANGUAGES ASM C CXX)
65-
66-
if(CUSTOM_MUTATOR EQUAL 1)
67-
add_compile_definitions(CUSTOM_MUTATOR)
68-
endif()

tests/fuzz/wasm-mutator-fuzz/wasm_mutator/wasm_mutator_fuzz.cc renamed to tests/fuzz/wasm-mutator-fuzz/wasm-mutator/wasm_mutator_fuzz.cc

File renamed without changes.

0 commit comments

Comments
 (0)