Skip to content

link with Clang static fuzzer lib if UMF_BUILD_FUZZTESTS is set #1284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,35 @@ jobs:
sudo apt-get update
sudo apt-get install -y cmake hwloc libhwloc-dev libnuma-dev libtbb-dev

- name: Find Clang fuzzer lib
run: |
CLANG_LIBS_DIR=$(find /usr/lib -name "libclang_rt.fuzzer_no_main-x86_64.a" -exec dirname {} \; | head -n 1)
echo "CLANG_LIBS_DIR=${CLANG_LIBS_DIR}" >> $GITHUB_ENV

- name: Configure CMake
run: >
cmake
-B ${{github.workspace}}/build
-DCMAKE_PREFIX_PATH=${{env.CLANG_LIBS_DIR}}
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
-DCMAKE_C_COMPILER=${{matrix.compiler.c}}
-DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
-DUMF_BUILD_SHARED_LIBRARY=ON
-DUMF_TESTS_FAIL_ON_SKIP=ON
-DUMF_DEVELOPER_MODE=ON
-DUMF_BUILD_FUZZTESTS=ON

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{matrix.build_type}} --verbose -j$(nproc)

- name: Run regular tests
working-directory: ${{github.workspace}}/build
run: ctest -C ${{matrix.build_type}} --output-on-failure -E "fuzz|test_init_teardown"

- name: Run regular tests with proxy library
working-directory: ${{env.BUILD_DIR}}
run: LD_PRELOAD=./lib/libumf_proxy.so ctest -C ${{matrix.build_type}} --output-on-failure -E "fuzz|test_init_teardown"

- name: Fuzz long test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{matrix.build_type}} --output-on-failure --verbose -L "fuzz-long"
Expand Down
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,20 @@ if(UMF_BUILD_FUZZTESTS)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND LINUX)
add_compile_options("-fsanitize=fuzzer-no-link")
add_link_options("-fsanitize=fuzzer-no-link")

# We need to find the fuzzer lib in the LLVM installation dir and link
# it statically as UMF does not define the main function used by fuzzer
# as well as __sancov_* functions
find_library(FUZZER_NO_MAIN_LIB
NAMES libclang_rt.fuzzer_no_main-x86_64.a)

if(FUZZER_NO_MAIN_LIB)
message(STATUS "Found fuzzer lib: ${FUZZER_NO_MAIN_LIB}")
# Fuzzer lib requires libstdc++
link_libraries(${FUZZER_NO_MAIN_LIB} "stdc++")
else()
message(FATAL_ERROR "libclang_rt.fuzzer_no_main-x86_64 not found!")
endif()
else()
message(
FATAL_ERROR
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ List of sanitizers available on Windows:

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

### Fuzz testing

To enable fuzz testing, the `UMF_BUILD_FUZZTESTS` CMake configuration flag must
be set to `ON`. Note, that this feature is supported only on Linux and requires
Clang. Additionally, ensure that the `CMAKE_PREFIX_PATH` includes the directory
containing the libraries necessary for fuzzing (e.g., Clang's
libclang_rt.fuzzer_no_main-x86_64.a).

Example:

```bash
cmake -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug -DUMF_BUILD_FUZZTESTS=ON -DCMAKE_PREFIX_PATH=/path/to/fuzzer/libs
```

### CMake standard options

List of options provided by CMake:
Expand Down
Loading