From 80ebc6ccea5eeadbc183d4e16acc952592c9006a Mon Sep 17 00:00:00 2001 From: Nikita Mikhaylov Date: Sun, 22 Aug 2021 15:09:49 +0000 Subject: [PATCH 01/11] Done --- CMakeLists.txt | 5 +++-- docker/packager/binary/build.sh | 17 ++++++++++++++++- docker/packager/packager | 2 ++ src/Compression/fuzzers/CMakeLists.txt | 8 +++++++- src/Storages/fuzzers/CMakeLists.txt | 11 ++++------- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1aef8c9fc8d..3d16d5da3f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,12 +126,13 @@ if (USE_STATIC_LIBRARIES) list(REVERSE CMAKE_FIND_LIBRARY_SUFFIXES) endif () -# Implies ${WITH_COVERAGE} option (ENABLE_FUZZING "Fuzzy testing using libfuzzer" OFF) if (ENABLE_FUZZING) + # Also set WITH_COVERAGE=1 for better fuzzing process + # By default this is disabled, because fuzzers are built in CI with the clickhouse itself. + # And we don't want to enable coverage for it. message (STATUS "Fuzzing instrumentation enabled") - set (WITH_COVERAGE ON) set (FUZZER "libfuzzer") endif() diff --git a/docker/packager/binary/build.sh b/docker/packager/binary/build.sh index d6614bbb9e2..5e632e3c592 100755 --- a/docker/packager/binary/build.sh +++ b/docker/packager/binary/build.sh @@ -35,6 +35,22 @@ ninja $NINJA_FLAGS clickhouse-bundle ccache --show-config ||: ccache --show-stats ||: +# Also build fuzzers if any +FUZZER_TARGETS=$(find ../src -name '*_fuzzer.cpp' -execdir basename {} .cpp ';' | tr '\n' ' ') + +mkdir -p /output/fuzzers +for FUZZER_TARGET in $FUZZER_TARGETS +do + ninja $NINJA_FLAGS $FUZZER_TARGET + # Find this binary in build directory and strip it + FUZZER_PATH=$(find ./src -name $FUZZER_TARGET) + strip --strip-unneeded $FUZZER_PATH + mv $FUZZER_PATH /output/fuzzers +done + +tar -zcvf /output/fuzzers.tar.gz /output/fuzzers +rm -rf /output/fuzzers + mv ./programs/clickhouse* /output mv ./src/unit_tests_dbms /output ||: # may not exist for some binary builds find . -name '*.so' -print -exec mv '{}' /output \; @@ -95,4 +111,3 @@ then # files in place, and will fail because this directory is not writable. tar -cv -I pixz -f /output/ccache.log.txz "$CCACHE_LOGFILE" fi - diff --git a/docker/packager/packager b/docker/packager/packager index 95b7fcd8568..924f01dddce 100755 --- a/docker/packager/packager +++ b/docker/packager/packager @@ -120,6 +120,8 @@ def parse_env_variables(build_type, compiler, sanitizer, package_type, image_typ if sanitizer: result.append("SANITIZER={}".format(sanitizer)) + # Build fuzzers only with sanitizers + cmake_flags.append('-DENABLE_FUZZING=1') if build_type: result.append("BUILD_TYPE={}".format(build_type)) diff --git a/src/Compression/fuzzers/CMakeLists.txt b/src/Compression/fuzzers/CMakeLists.txt index 74bf2d2649b..73b95d09fa3 100644 --- a/src/Compression/fuzzers/CMakeLists.txt +++ b/src/Compression/fuzzers/CMakeLists.txt @@ -1,2 +1,8 @@ add_executable (compressed_buffer_fuzzer compressed_buffer_fuzzer.cpp) -target_link_libraries (compressed_buffer_fuzzer PRIVATE fuzz_compression clickhouse_common_io ${LIB_FUZZING_ENGINE}) + +# Our code has strong cohesion and target associated with `Compression` also depends on `DataTypes`. +# But we can exclude some files which have dependencies in case of +# fuzzer related build (we are interested in fuzzing only particular part of our code). +# So, some symbols will be declared, but not defined. Unfortunately, this trick doesn't work with UBSan. +# If you want really small size of the resulted binary, just link with fuzz_compression and clickhouse_common_io +target_link_libraries (compressed_buffer_fuzzer PRIVATE dbms ${LIB_FUZZING_ENGINE}) diff --git a/src/Storages/fuzzers/CMakeLists.txt b/src/Storages/fuzzers/CMakeLists.txt index 93d3d2926bd..dcbd07ccd91 100644 --- a/src/Storages/fuzzers/CMakeLists.txt +++ b/src/Storages/fuzzers/CMakeLists.txt @@ -1,11 +1,8 @@ -add_executable (mergetree_checksum_fuzzer - mergetree_checksum_fuzzer.cpp - "${ClickHouse_SOURCE_DIR}/src/Storages/MergeTree/MergeTreeDataPartChecksum.cpp" - "${ClickHouse_SOURCE_DIR}/src/Compression/CompressedReadBuffer.cpp" - "${ClickHouse_SOURCE_DIR}/src/Compression/CompressedWriteBuffer.cpp" -) -target_link_libraries (mergetree_checksum_fuzzer PRIVATE clickhouse_common_io fuzz_compression ${LIB_FUZZING_ENGINE}) +add_executable (mergetree_checksum_fuzzer mergetree_checksum_fuzzer.cpp) + +# Look at comment around fuzz_compression target declaration +target_link_libraries (mergetree_checksum_fuzzer PRIVATE dbms ${LIB_FUZZING_ENGINE}) add_executable (columns_description_fuzzer columns_description_fuzzer.cpp) target_link_libraries (columns_description_fuzzer PRIVATE dbms ${LIB_FUZZING_ENGINE}) From 1c956481a14577cefb82097e870738ee193d5468 Mon Sep 17 00:00:00 2001 From: Nikita Mikhaylov Date: Mon, 23 Aug 2021 13:21:39 +0000 Subject: [PATCH 02/11] Updated deb/build.sh and fixed shellcheck --- docker/packager/binary/build.sh | 7 ++++--- docker/packager/deb/build.sh | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docker/packager/binary/build.sh b/docker/packager/binary/build.sh index 5e632e3c592..70139a04852 100755 --- a/docker/packager/binary/build.sh +++ b/docker/packager/binary/build.sh @@ -41,11 +41,12 @@ FUZZER_TARGETS=$(find ../src -name '*_fuzzer.cpp' -execdir basename {} .cpp ';' mkdir -p /output/fuzzers for FUZZER_TARGET in $FUZZER_TARGETS do + # shellcheck disable=SC2086 # No quotes because I want it to expand to nothing if empty. ninja $NINJA_FLAGS $FUZZER_TARGET # Find this binary in build directory and strip it - FUZZER_PATH=$(find ./src -name $FUZZER_TARGET) - strip --strip-unneeded $FUZZER_PATH - mv $FUZZER_PATH /output/fuzzers + FUZZER_PATH=$(find ./src -name "$FUZZER_TARGET") + strip --strip-unneeded "$FUZZER_PATH" + mv "$FUZZER_PATH" /output/fuzzers done tar -zcvf /output/fuzzers.tar.gz /output/fuzzers diff --git a/docker/packager/deb/build.sh b/docker/packager/deb/build.sh index 4e14574b738..7bcd79a919f 100755 --- a/docker/packager/deb/build.sh +++ b/docker/packager/deb/build.sh @@ -23,6 +23,20 @@ then echo "Place $BINARY_OUTPUT to output" mkdir /output/binary ||: # if exists mv /build/obj-*/programs/clickhouse* /output/binary + + # Copy all fuzzers + FUZZER_TARGETS=$(find /build/obj-*/src -name '*_fuzzer' -execdir basename {} ';' | tr '\n' ' ') + mkdir -p /output/fuzzers ||: # if exists + for FUZZER_TARGET in $FUZZER_TARGETS + do + FUZZER_PATH=$(find /build/obj-*/src -name "$FUZZER_TARGET") + strip --strip-unneeded "$FUZZER_PATH" + mv "$FUZZER_PATH" /output/fuzzers ||: # if exists + done + + tar -zcvf /output/fuzzers.tar.gz /output/fuzzers + rm -rf /output/fuzzers + if [ "$BINARY_OUTPUT" = "tests" ] then mv /build/obj-*/src/unit_tests_dbms /output/binary From 77430a1baa470f07cc18cc823664a69bcafe48b2 Mon Sep 17 00:00:00 2001 From: Nikita Mikhaylov Date: Mon, 23 Aug 2021 14:36:26 +0000 Subject: [PATCH 03/11] better --- docker/packager/binary/build.sh | 30 ++++++++++++++++-------------- docker/packager/deb/build.sh | 26 ++++++++++++++++---------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/docker/packager/binary/build.sh b/docker/packager/binary/build.sh index 70139a04852..0c88cbe57aa 100755 --- a/docker/packager/binary/build.sh +++ b/docker/packager/binary/build.sh @@ -35,22 +35,24 @@ ninja $NINJA_FLAGS clickhouse-bundle ccache --show-config ||: ccache --show-stats ||: -# Also build fuzzers if any -FUZZER_TARGETS=$(find ../src -name '*_fuzzer.cpp' -execdir basename {} .cpp ';' | tr '\n' ' ') + # Also build fuzzers if any +if [[ "${CMAKE_FLAGS[@]}" == "*ENABLE_FUZZING*" ]]; then + FUZZER_TARGETS=$(find ../src -name '*_fuzzer.cpp' -execdir basename {} .cpp ';' | tr '\n' ' ') -mkdir -p /output/fuzzers -for FUZZER_TARGET in $FUZZER_TARGETS -do - # shellcheck disable=SC2086 # No quotes because I want it to expand to nothing if empty. - ninja $NINJA_FLAGS $FUZZER_TARGET - # Find this binary in build directory and strip it - FUZZER_PATH=$(find ./src -name "$FUZZER_TARGET") - strip --strip-unneeded "$FUZZER_PATH" - mv "$FUZZER_PATH" /output/fuzzers -done + mkdir -p /output/fuzzers + for FUZZER_TARGET in $FUZZER_TARGETS + do + # shellcheck disable=SC2086 # No quotes because I want it to expand to nothing if empty. + ninja $NINJA_FLAGS $FUZZER_TARGET + # Find this binary in build directory and strip it + FUZZER_PATH=$(find ./src -name "$FUZZER_TARGET") + strip --strip-unneeded "$FUZZER_PATH" + mv "$FUZZER_PATH" /output/fuzzers + done -tar -zcvf /output/fuzzers.tar.gz /output/fuzzers -rm -rf /output/fuzzers + tar -zcvf /output/fuzzers.tar.gz /output/fuzzers + rm -rf /output/fuzzers +fi mv ./programs/clickhouse* /output mv ./src/unit_tests_dbms /output ||: # may not exist for some binary builds diff --git a/docker/packager/deb/build.sh b/docker/packager/deb/build.sh index 7bcd79a919f..d343287eee9 100755 --- a/docker/packager/deb/build.sh +++ b/docker/packager/deb/build.sh @@ -24,18 +24,24 @@ then mkdir /output/binary ||: # if exists mv /build/obj-*/programs/clickhouse* /output/binary - # Copy all fuzzers + # Copy all fuzzers if any FUZZER_TARGETS=$(find /build/obj-*/src -name '*_fuzzer' -execdir basename {} ';' | tr '\n' ' ') - mkdir -p /output/fuzzers ||: # if exists - for FUZZER_TARGET in $FUZZER_TARGETS - do - FUZZER_PATH=$(find /build/obj-*/src -name "$FUZZER_TARGET") - strip --strip-unneeded "$FUZZER_PATH" - mv "$FUZZER_PATH" /output/fuzzers ||: # if exists - done - tar -zcvf /output/fuzzers.tar.gz /output/fuzzers - rm -rf /output/fuzzers + if [[ $FUZZER_TARGETS != "" ]]; then + + mkdir -p /output/fuzzers ||: # if exists + for FUZZER_TARGET in $FUZZER_TARGETS + do + FUZZER_PATH=$(find /build/obj-*/src -name "$FUZZER_TARGET") + strip --strip-unneeded "$FUZZER_PATH" + mv "$FUZZER_PATH" /output/fuzzers ||: # if exists + done + + + tar -zcvf /output/fuzzers.tar.gz /output/fuzzers + rm -rf /output/fuzzers + + fi if [ "$BINARY_OUTPUT" = "tests" ] then From afae867060d1904638e301d7eb83ed34d3ba4161 Mon Sep 17 00:00:00 2001 From: Nikita Mikhaylov Date: Mon, 23 Aug 2021 18:31:17 +0000 Subject: [PATCH 04/11] Fix build --- docker/packager/binary/build.sh | 3 ++- docker/packager/packager | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docker/packager/binary/build.sh b/docker/packager/binary/build.sh index 0c88cbe57aa..99655450946 100755 --- a/docker/packager/binary/build.sh +++ b/docker/packager/binary/build.sh @@ -36,7 +36,8 @@ ccache --show-config ||: ccache --show-stats ||: # Also build fuzzers if any -if [[ "${CMAKE_FLAGS[@]}" == "*ENABLE_FUZZING*" ]]; then +if [ -n "$FUZZER" ] +then FUZZER_TARGETS=$(find ../src -name '*_fuzzer.cpp' -execdir basename {} .cpp ';' | tr '\n' ' ') mkdir -p /output/fuzzers diff --git a/docker/packager/packager b/docker/packager/packager index 924f01dddce..50bb4d8e23b 100755 --- a/docker/packager/packager +++ b/docker/packager/packager @@ -121,6 +121,8 @@ def parse_env_variables(build_type, compiler, sanitizer, package_type, image_typ if sanitizer: result.append("SANITIZER={}".format(sanitizer)) # Build fuzzers only with sanitizers + # This is needed to check necessity particularly in build script + result.append("FUZZER=TRUE") cmake_flags.append('-DENABLE_FUZZING=1') if build_type: result.append("BUILD_TYPE={}".format(build_type)) From ac4a51615219e0f91799a1580d8da1e1f059bcd0 Mon Sep 17 00:00:00 2001 From: Nikita Mikhaylov Date: Mon, 23 Aug 2021 21:45:48 +0000 Subject: [PATCH 05/11] Fix build --- docker/packager/binary/build.sh | 47 +++++++++++++++++++-------------- docker/packager/packager | 4 --- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/docker/packager/binary/build.sh b/docker/packager/binary/build.sh index 99655450946..9a77d3b2fe3 100755 --- a/docker/packager/binary/build.sh +++ b/docker/packager/binary/build.sh @@ -35,26 +35,6 @@ ninja $NINJA_FLAGS clickhouse-bundle ccache --show-config ||: ccache --show-stats ||: - # Also build fuzzers if any -if [ -n "$FUZZER" ] -then - FUZZER_TARGETS=$(find ../src -name '*_fuzzer.cpp' -execdir basename {} .cpp ';' | tr '\n' ' ') - - mkdir -p /output/fuzzers - for FUZZER_TARGET in $FUZZER_TARGETS - do - # shellcheck disable=SC2086 # No quotes because I want it to expand to nothing if empty. - ninja $NINJA_FLAGS $FUZZER_TARGET - # Find this binary in build directory and strip it - FUZZER_PATH=$(find ./src -name "$FUZZER_TARGET") - strip --strip-unneeded "$FUZZER_PATH" - mv "$FUZZER_PATH" /output/fuzzers - done - - tar -zcvf /output/fuzzers.tar.gz /output/fuzzers - rm -rf /output/fuzzers -fi - mv ./programs/clickhouse* /output mv ./src/unit_tests_dbms /output ||: # may not exist for some binary builds find . -name '*.so' -print -exec mv '{}' /output \; @@ -115,3 +95,30 @@ then # files in place, and will fail because this directory is not writable. tar -cv -I pixz -f /output/ccache.log.txz "$CCACHE_LOGFILE" fi + +# Also build fuzzers if any sanitizer specified +if [ -n "$SANITIZER" ] +then + # Delete previous cache, because we add a new flag -DENABLE_FUZZING=1 + rm -rf CMakeCache.txt CMakeFiles/ + + # Hope, that the most part of files will be in cache, so we just link new executables + cmake --debug-trycompile --verbose=1 -DCMAKE_VERBOSE_MAKEFILE=1 -LA "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" \ + "-DSANITIZE=$SANITIZER" -DENABLE_FUZZING=1 -DENABLE_CHECK_HEAVY_BUILDS=1 "${CMAKE_FLAGS[@]}" .. + + FUZZER_TARGETS=$(find ../src -name '*_fuzzer.cpp' -execdir basename {} .cpp ';' | tr '\n' ' ') + + mkdir -p /output/fuzzers + for FUZZER_TARGET in $FUZZER_TARGETS + do + # shellcheck disable=SC2086 # No quotes because I want it to expand to nothing if empty. + ninja $NINJA_FLAGS $FUZZER_TARGET + # Find this binary in build directory and strip it + FUZZER_PATH=$(find ./src -name "$FUZZER_TARGET") + strip --strip-unneeded "$FUZZER_PATH" + mv "$FUZZER_PATH" /output/fuzzers + done + + tar -zcvf /output/fuzzers.tar.gz /output/fuzzers + rm -rf /output/fuzzers +fi diff --git a/docker/packager/packager b/docker/packager/packager index 50bb4d8e23b..95b7fcd8568 100755 --- a/docker/packager/packager +++ b/docker/packager/packager @@ -120,10 +120,6 @@ def parse_env_variables(build_type, compiler, sanitizer, package_type, image_typ if sanitizer: result.append("SANITIZER={}".format(sanitizer)) - # Build fuzzers only with sanitizers - # This is needed to check necessity particularly in build script - result.append("FUZZER=TRUE") - cmake_flags.append('-DENABLE_FUZZING=1') if build_type: result.append("BUILD_TYPE={}".format(build_type)) From 242ef3dcb5d5f2d9f7f3d5c40e265b93146cd435 Mon Sep 17 00:00:00 2001 From: Nikita Mikhaylov Date: Tue, 24 Aug 2021 00:09:19 +0000 Subject: [PATCH 06/11] Proper build --- docker/packager/binary/build.sh | 37 +++++++++------------------------ docker/packager/deb/build.sh | 25 ++++++---------------- docker/packager/other/fuzzer.sh | 30 ++++++++++++++++++++++++++ release | 3 --- 4 files changed, 46 insertions(+), 49 deletions(-) create mode 100644 docker/packager/other/fuzzer.sh diff --git a/docker/packager/binary/build.sh b/docker/packager/binary/build.sh index 9a77d3b2fe3..b9900e34bf1 100755 --- a/docker/packager/binary/build.sh +++ b/docker/packager/binary/build.sh @@ -83,6 +83,16 @@ then mv "$COMBINED_OUTPUT.tgz" /output fi +# Also build fuzzers if any sanitizer specified +if [ -n "$SANITIZER" ] +then + # Currently we are in build/build_docker directory + ../docker/packager/other/fuzzer.sh +fi + +ccache --show-config ||: +ccache --show-stats ||: + if [ "${CCACHE_DEBUG:-}" == "1" ] then find . -name '*.ccache-*' -print0 \ @@ -95,30 +105,3 @@ then # files in place, and will fail because this directory is not writable. tar -cv -I pixz -f /output/ccache.log.txz "$CCACHE_LOGFILE" fi - -# Also build fuzzers if any sanitizer specified -if [ -n "$SANITIZER" ] -then - # Delete previous cache, because we add a new flag -DENABLE_FUZZING=1 - rm -rf CMakeCache.txt CMakeFiles/ - - # Hope, that the most part of files will be in cache, so we just link new executables - cmake --debug-trycompile --verbose=1 -DCMAKE_VERBOSE_MAKEFILE=1 -LA "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" \ - "-DSANITIZE=$SANITIZER" -DENABLE_FUZZING=1 -DENABLE_CHECK_HEAVY_BUILDS=1 "${CMAKE_FLAGS[@]}" .. - - FUZZER_TARGETS=$(find ../src -name '*_fuzzer.cpp' -execdir basename {} .cpp ';' | tr '\n' ' ') - - mkdir -p /output/fuzzers - for FUZZER_TARGET in $FUZZER_TARGETS - do - # shellcheck disable=SC2086 # No quotes because I want it to expand to nothing if empty. - ninja $NINJA_FLAGS $FUZZER_TARGET - # Find this binary in build directory and strip it - FUZZER_PATH=$(find ./src -name "$FUZZER_TARGET") - strip --strip-unneeded "$FUZZER_PATH" - mv "$FUZZER_PATH" /output/fuzzers - done - - tar -zcvf /output/fuzzers.tar.gz /output/fuzzers - rm -rf /output/fuzzers -fi diff --git a/docker/packager/deb/build.sh b/docker/packager/deb/build.sh index d343287eee9..5016e40dd2e 100755 --- a/docker/packager/deb/build.sh +++ b/docker/packager/deb/build.sh @@ -24,31 +24,18 @@ then mkdir /output/binary ||: # if exists mv /build/obj-*/programs/clickhouse* /output/binary - # Copy all fuzzers if any - FUZZER_TARGETS=$(find /build/obj-*/src -name '*_fuzzer' -execdir basename {} ';' | tr '\n' ' ') - - if [[ $FUZZER_TARGETS != "" ]]; then - - mkdir -p /output/fuzzers ||: # if exists - for FUZZER_TARGET in $FUZZER_TARGETS - do - FUZZER_PATH=$(find /build/obj-*/src -name "$FUZZER_TARGET") - strip --strip-unneeded "$FUZZER_PATH" - mv "$FUZZER_PATH" /output/fuzzers ||: # if exists - done - - - tar -zcvf /output/fuzzers.tar.gz /output/fuzzers - rm -rf /output/fuzzers - - fi - if [ "$BINARY_OUTPUT" = "tests" ] then mv /build/obj-*/src/unit_tests_dbms /output/binary fi fi +# Also build fuzzers if any sanitizer specified +if [ -n "$SANITIZER" ] +then + build/docker/packager/other/fuzzer.sh +fi + ccache --show-config ||: ccache --show-stats ||: diff --git a/docker/packager/other/fuzzer.sh b/docker/packager/other/fuzzer.sh new file mode 100644 index 00000000000..d6609d3c632 --- /dev/null +++ b/docker/packager/other/fuzzer.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +set -x -e + +# This script is responsible for building all fuzzers, and copy them to output directory +# as an archive. + +# Delete previous cache, because we add a new flags -DENABLE_FUZZING=1 and -DFUZZER=libfuzzer +rm -f CMakeCache.txt +read -ra CMAKE_FLAGS <<< "${CMAKE_FLAGS:-}" +# Hope, that the most part of files will be in cache, so we just link new executables +cmake --debug-trycompile --verbose=1 -DCMAKE_VERBOSE_MAKEFILE=1 -LA "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" \ + "-DSANITIZE=$SANITIZER" -DENABLE_FUZZING=1 -DFUZZER='libfuzzer' -DENABLE_TCMALLOC=0 -DENABLE_JEMALLOC=0 \ + -DENABLE_CHECK_HEAVY_BUILDS=1 "${CMAKE_FLAGS[@]}" .. + +FUZZER_TARGETS=$(find ../src -name '*_fuzzer.cpp' -execdir basename {} .cpp ';' | tr '\n' ' ') + +mkdir -p /output/fuzzers +for FUZZER_TARGET in $FUZZER_TARGETS +do + # shellcheck disable=SC2086 # No quotes because I want it to expand to nothing if empty. + ninja $NINJA_FLAGS $FUZZER_TARGET + # Find this binary in build directory and strip it + FUZZER_PATH=$(find ./src -name "$FUZZER_TARGET") + strip --strip-unneeded "$FUZZER_PATH" + mv "$FUZZER_PATH" /output/fuzzers +done + +tar -zcvf /output/fuzzers.tar.gz /output/fuzzers +rm -rf /output/fuzzers diff --git a/release b/release index de549595d43..6e6970d7b00 100755 --- a/release +++ b/release @@ -60,9 +60,6 @@ then elif [[ "$SANITIZER" == "thread" ]]; then VERSION_POSTFIX+="+tsan" elif [[ "$SANITIZER" == "memory" ]]; then VERSION_POSTFIX+="+msan" elif [[ "$SANITIZER" == "undefined" ]]; then VERSION_POSTFIX+="+ubsan" - elif [[ "$SANITIZER" == "libfuzzer" ]]; then - VERSION_POSTFIX+="+libfuzzer" - MALLOC_OPTS="-DENABLE_TCMALLOC=0 -DENABLE_JEMALLOC=0" else echo "Unknown value of SANITIZER variable: $SANITIZER" exit 3 From 19fc7233287bfd7007c297ac56265983c2266c8d Mon Sep 17 00:00:00 2001 From: Nikita Mikhaylov Date: Tue, 24 Aug 2021 11:14:37 +0000 Subject: [PATCH 07/11] chmod +x --- docker/packager/other/fuzzer.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 docker/packager/other/fuzzer.sh diff --git a/docker/packager/other/fuzzer.sh b/docker/packager/other/fuzzer.sh old mode 100644 new mode 100755 From b330cb855f163f573a269ac7720a6ee2035d751a Mon Sep 17 00:00:00 2001 From: Nikita Mikhaylov Date: Tue, 24 Aug 2021 23:11:48 +0000 Subject: [PATCH 08/11] Fix build --- docker/packager/deb/build.sh | 6 ++++++ docker/packager/other/fuzzer.sh | 9 ++++++--- docker/packager/packager | 3 +++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docker/packager/deb/build.sh b/docker/packager/deb/build.sh index 5016e40dd2e..fb9c3f6cab7 100755 --- a/docker/packager/deb/build.sh +++ b/docker/packager/deb/build.sh @@ -33,6 +33,12 @@ fi # Also build fuzzers if any sanitizer specified if [ -n "$SANITIZER" ] then + # Script is supposed that we are in build directory. + mkdir -p build/build_docker + cd build/build_docker + # Launching build script + ../docker/packager/other/fuzzer.sh + cd build/docker/packager/other/fuzzer.sh fi diff --git a/docker/packager/other/fuzzer.sh b/docker/packager/other/fuzzer.sh index d6609d3c632..fe4de5802dc 100755 --- a/docker/packager/other/fuzzer.sh +++ b/docker/packager/other/fuzzer.sh @@ -1,15 +1,18 @@ #!/usr/bin/env bash -set -x -e - # This script is responsible for building all fuzzers, and copy them to output directory # as an archive. +# Script is supposed that we are in build directory. + +set -x -e + +printenv # Delete previous cache, because we add a new flags -DENABLE_FUZZING=1 and -DFUZZER=libfuzzer rm -f CMakeCache.txt read -ra CMAKE_FLAGS <<< "${CMAKE_FLAGS:-}" # Hope, that the most part of files will be in cache, so we just link new executables -cmake --debug-trycompile --verbose=1 -DCMAKE_VERBOSE_MAKEFILE=1 -LA "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" \ +cmake --debug-trycompile --verbose=1 -DCMAKE_VERBOSE_MAKEFILE=1 -LA -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX \ "-DSANITIZE=$SANITIZER" -DENABLE_FUZZING=1 -DFUZZER='libfuzzer' -DENABLE_TCMALLOC=0 -DENABLE_JEMALLOC=0 \ -DENABLE_CHECK_HEAVY_BUILDS=1 "${CMAKE_FLAGS[@]}" .. diff --git a/docker/packager/packager b/docker/packager/packager index 95b7fcd8568..673878bce43 100755 --- a/docker/packager/packager +++ b/docker/packager/packager @@ -105,6 +105,9 @@ def parse_env_variables(build_type, compiler, sanitizer, package_type, image_typ if image_type == "deb" or image_type == "unbundled": result.append("DEB_CC={}".format(cc)) result.append("DEB_CXX={}".format(cxx)) + # For building fuzzers + result.append("CC={}".format(cc)) + result.append("CXX={}".format(cxx)) elif image_type == "binary": result.append("CC={}".format(cc)) result.append("CXX={}".format(cxx)) From 6cece7d1d956997ae0202afcc73e83e26b2132be Mon Sep 17 00:00:00 2001 From: Nikita Mikhaylov Date: Wed, 25 Aug 2021 11:22:16 +0300 Subject: [PATCH 09/11] Update build.sh --- docker/packager/deb/build.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/docker/packager/deb/build.sh b/docker/packager/deb/build.sh index fb9c3f6cab7..46f6404363d 100755 --- a/docker/packager/deb/build.sh +++ b/docker/packager/deb/build.sh @@ -39,7 +39,6 @@ then # Launching build script ../docker/packager/other/fuzzer.sh cd - build/docker/packager/other/fuzzer.sh fi ccache --show-config ||: From ab22fdaa809e4e98bca7a6ebe89bfcfa03dd96e0 Mon Sep 17 00:00:00 2001 From: Nikita Mikhaylov Date: Wed, 25 Aug 2021 11:16:06 +0000 Subject: [PATCH 10/11] Fix build --- docker/packager/other/fuzzer.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docker/packager/other/fuzzer.sh b/docker/packager/other/fuzzer.sh index fe4de5802dc..33ad7674961 100755 --- a/docker/packager/other/fuzzer.sh +++ b/docker/packager/other/fuzzer.sh @@ -12,8 +12,10 @@ printenv rm -f CMakeCache.txt read -ra CMAKE_FLAGS <<< "${CMAKE_FLAGS:-}" # Hope, that the most part of files will be in cache, so we just link new executables -cmake --debug-trycompile --verbose=1 -DCMAKE_VERBOSE_MAKEFILE=1 -LA -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX \ - "-DSANITIZE=$SANITIZER" -DENABLE_FUZZING=1 -DFUZZER='libfuzzer' -DENABLE_TCMALLOC=0 -DENABLE_JEMALLOC=0 \ +cmake --debug-trycompile --verbose=1 -DCMAKE_VERBOSE_MAKEFILE=1 -LA -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DENABLE_CLICKHOUSE_ODBC_BRIDGE=OFF \ + -DENABLE_LIBRARIES=0 -DENABLE_SSL=1 -DUSE_INTERNAL_SSL_LIBRARY=1 -DUSE_UNWIND=ON -DENABLE_EMBEDDED_COMPILER=0 \ + -DENABLE_EXAMPLES=0 -DENABLE_UTILS=0 "-DSANITIZE=$SANITIZER" \ + -DENABLE_FUZZING=1 -DFUZZER='libfuzzer' -DENABLE_TCMALLOC=0 -DENABLE_JEMALLOC=0 \ -DENABLE_CHECK_HEAVY_BUILDS=1 "${CMAKE_FLAGS[@]}" .. FUZZER_TARGETS=$(find ../src -name '*_fuzzer.cpp' -execdir basename {} .cpp ';' | tr '\n' ' ') From b8ef09a1f84a2eed17e0338dd05cdc1427e00018 Mon Sep 17 00:00:00 2001 From: Nikita Mikhaylov Date: Wed, 25 Aug 2021 11:18:57 +0000 Subject: [PATCH 11/11] Fix build --- docker/packager/other/fuzzer.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/packager/other/fuzzer.sh b/docker/packager/other/fuzzer.sh index 33ad7674961..1a8b80c3f77 100755 --- a/docker/packager/other/fuzzer.sh +++ b/docker/packager/other/fuzzer.sh @@ -14,7 +14,7 @@ read -ra CMAKE_FLAGS <<< "${CMAKE_FLAGS:-}" # Hope, that the most part of files will be in cache, so we just link new executables cmake --debug-trycompile --verbose=1 -DCMAKE_VERBOSE_MAKEFILE=1 -LA -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DENABLE_CLICKHOUSE_ODBC_BRIDGE=OFF \ -DENABLE_LIBRARIES=0 -DENABLE_SSL=1 -DUSE_INTERNAL_SSL_LIBRARY=1 -DUSE_UNWIND=ON -DENABLE_EMBEDDED_COMPILER=0 \ - -DENABLE_EXAMPLES=0 -DENABLE_UTILS=0 "-DSANITIZE=$SANITIZER" \ + -DENABLE_EXAMPLES=0 -DENABLE_UTILS=0 -DENABLE_THINLTO=0 "-DSANITIZE=$SANITIZER" \ -DENABLE_FUZZING=1 -DFUZZER='libfuzzer' -DENABLE_TCMALLOC=0 -DENABLE_JEMALLOC=0 \ -DENABLE_CHECK_HEAVY_BUILDS=1 "${CMAKE_FLAGS[@]}" ..