Skip to content

Commit 072829e

Browse files
committed
add required lib if UMF_BUILD_FUZZTESTS is set
1 parent 58ceb32 commit 072829e

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

.github/workflows/nightly.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,20 @@ jobs:
3636
sudo apt-get update
3737
sudo apt-get install -y cmake hwloc libhwloc-dev libnuma-dev libtbb-dev
3838
39+
- name: Find Clang fuzzer lib
40+
run: |
41+
CLANG_LIBS_DIR=$(find /usr/lib -name "libclang_rt.fuzzer_no_main-x86_64.a" -exec dirname {} \; | head -n 1)
42+
echo "CLANG_LIBS_DIR=${CLANG_LIBS_DIR}" >> $GITHUB_ENV
43+
3944
- name: Configure CMake
4045
run: >
4146
cmake
4247
-B ${{github.workspace}}/build
48+
-DCMAKE_PREFIX_PATH=${{env.CLANG_LIBS_DIR}}
4349
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
4450
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
4551
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
52+
-DUMF_BUILD_SHARED_LIBRARY=ON
4653
-DUMF_TESTS_FAIL_ON_SKIP=ON
4754
-DUMF_DEVELOPER_MODE=ON
4855
-DUMF_BUILD_FUZZTESTS=ON

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,12 +579,29 @@ if(UMF_USE_MSAN)
579579
"prevent reporting false-positives")
580580
add_sanitizer_flag(memory)
581581
endif()
582+
582583
# Fuzzer instrumentation for the whole library
583584
if(UMF_BUILD_FUZZTESTS
584585
AND CMAKE_CXX_COMPILER_ID MATCHES "Clang"
585586
AND LINUX)
586587
add_compile_options("-fsanitize=fuzzer-no-link")
587588
add_link_options("-fsanitize=fuzzer-no-link")
589+
590+
# We need to find the fuzzer lib in the LLVM installation dir and link it
591+
# statically as UMF does not define the main function used by fuzzer as
592+
# well as __sancov_* functions
593+
find_library(
594+
FUZZER_NO_MAIN_LIB
595+
NAMES libclang_rt.fuzzer_no_main-x86_64.a
596+
)
597+
598+
if(FUZZER_NO_MAIN_LIB)
599+
message(STATUS "Found fuzzer lib: ${FUZZER_NO_MAIN_LIB}")
600+
# Fuzzer lib requires libstdc++
601+
link_libraries(${FUZZER_NO_MAIN_LIB} "stdc++")
602+
else()
603+
message(FATAL_ERROR "libclang_rt.fuzzer_no_main-x86_64 not found!")
604+
endif()
588605
endif()
589606

590607
# A header-only lib to specify include directories in transitive dependencies

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,19 @@ List of sanitizers available on Windows:
9797

9898
Listed sanitizers can be enabled with appropriate [CMake options](#cmake-standard-options).
9999

100+
### Fuzz testing
101+
102+
To enable fuzz testing, the `UMF_BUILD_FUZZTESTS` CMake configuration flag must
103+
be set to `ON`. Note, that this feature is supported only on Linux and requires
104+
Clang. Additionally, ensure that the `CMAKE_PREFIX_PATH` includes the directory
105+
containing the Clang libraries necessary for fuzzing.
106+
107+
Example:
108+
109+
```bash
110+
cmake -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug -DUMF_BUILD_FUZZTESTS=ON -DCMAKE_PREFIX_PATH=/path/to/clang/libs
111+
```
112+
100113
### CMake standard options
101114

102115
List of options provided by CMake:

0 commit comments

Comments
 (0)