From a33c0eb179a5fac79dc2a1c8af1a5d1b129cc21d Mon Sep 17 00:00:00 2001 From: Jacek Glen Date: Thu, 12 Oct 2023 14:02:28 +0200 Subject: [PATCH] rpcdaemon: enable fuzzer build on CI --- .circleci/config.yml | 16 +++++++-------- cmd/test/CMakeLists.txt | 4 ++-- cmd/test/address_sanitizer_fix.hpp | 32 ++++++++++++++++++++++++++++++ cmd/test/fuzzer_diagnostics.cpp | 3 +++ cmd/test/fuzzer_test.cpp | 2 ++ 5 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 cmd/test/address_sanitizer_fix.hpp diff --git a/.circleci/config.yml b/.circleci/config.yml index dce490b30f..70474c80c1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -61,10 +61,10 @@ commands: then CONAN_CMAKE_ARGS="-DCONAN_PROFILE=<>" fi - if [[ "<>" == "clang" ]] - then - TOOLCHAIN_CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=../project/cmake/toolchain/clang_libcxx.cmake" - fi + # if [[ "<>" == "clang" ]] + # then + # TOOLCHAIN_CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=../project/cmake/toolchain/clang_libcxx.cmake" + # fi cmake ../project -DCMAKE_BUILD_TYPE=<> $CONAN_CMAKE_ARGS $TOOLCHAIN_CMAKE_ARGS $BUILD_CMAKE_ARGS - run: @@ -150,6 +150,7 @@ commands: mkdir -p ~/corpus mkdir -p ~/crashes mkdir -p ~/artifacts + for pathname in ../project/third_party/execution-apis/tests/*/*.io; do cp --backup=numbered "$pathname" ~/artifacts; done ./cmd/test/rpcdaemon_fuzzer_test -max_total_time=10 ~/corpus ~/crashes ~/artifacts jobs: @@ -308,13 +309,13 @@ jobs: linux-clang-fuzzer: environment: BUILD_CMAKE_ARGS: -DSILKWORM_FUZZER=ON - ASAN_OPTIONS: alloc_dealloc_mismatch=0 # https://github.com/llvm/llvm-project/issues/59432 UBSAN_OPTIONS: print_stacktrace=1 machine: image: ubuntu-2204:2023.04.2 resource_class: xlarge steps: - - checkout_with_submodules + - checkout_with_submodules: + ethereum_tests: false - build_using_conan: build_type: Release compiler_id: clang @@ -414,8 +415,7 @@ workflows: when: or: - equal: [ master, <> ] - - equal: [ master, <> ] - # - matches: { pattern: "^ci\\/.+$", value: <> } + - matches: { pattern: "^ci\\/.+$", value: <> } jobs: - linux-release: name: linux-gcc-<>-release diff --git a/cmd/test/CMakeLists.txt b/cmd/test/CMakeLists.txt index 2bbd8b9f93..97fe1447aa 100644 --- a/cmd/test/CMakeLists.txt +++ b/cmd/test/CMakeLists.txt @@ -51,8 +51,8 @@ if(NOT SILKWORM_CORE_ONLY) # Silkworm RpcDaemon Fuzz Debug Executable add_executable(rpcdaemon_fuzzer_diagnostics fuzzer_diagnostics.cpp) - target_compile_options(rpcdaemon_fuzzer_diagnostics PRIVATE -fsanitize=address) - target_link_libraries(rpcdaemon_fuzzer_diagnostics PRIVATE silkrpc CLI11::CLI11 -fsanitize=address) + target_compile_options(rpcdaemon_fuzzer_diagnostics PRIVATE -fsanitize=address,undefined) + target_link_libraries(rpcdaemon_fuzzer_diagnostics PRIVATE silkrpc CLI11::CLI11 -fsanitize=address,undefined) endif() # Silkworm Sync Tests diff --git a/cmd/test/address_sanitizer_fix.hpp b/cmd/test/address_sanitizer_fix.hpp new file mode 100644 index 0000000000..45bf1ecddd --- /dev/null +++ b/cmd/test/address_sanitizer_fix.hpp @@ -0,0 +1,32 @@ +/* + Copyright 2023 The Silkworm Authors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +// https://github.com/llvm/llvm-project/issues/59432 + + +#ifndef __has_feature +// GCC does not have __has_feature, adding it to avoid compilation errors +#define __has_feature(feature) 0 +#endif + +#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) +#ifdef __cplusplus +extern "C" +#endif +const char *__asan_default_options() { + return "alloc_dealloc_mismatch=0"; +} +#endif diff --git a/cmd/test/fuzzer_diagnostics.cpp b/cmd/test/fuzzer_diagnostics.cpp index a8617e15e0..4584fcda75 100644 --- a/cmd/test/fuzzer_diagnostics.cpp +++ b/cmd/test/fuzzer_diagnostics.cpp @@ -14,6 +14,7 @@ limitations under the License. */ + #include #include @@ -23,6 +24,7 @@ #include #include +#include "address_sanitizer_fix.hpp" void print_stack_trace() { void* trace[16]; @@ -59,6 +61,7 @@ int main(int argc, char* argv[]) { app.add_option("input", input_str, "Input string") ->description("Wrap JSON in '' to avoid shell escaping, e.g. '{\"jsonrpc\":\"2.0\",\"id\":1}'") + ->default_val(R"({"jsonrpc":"2.0","id":1,"method":"debug_getRawBlock","params":["3"]})") ->required(false); app.add_option("-f", input_file, "Path to test file or directory") diff --git a/cmd/test/fuzzer_test.cpp b/cmd/test/fuzzer_test.cpp index 14ecac2b7a..28f7eb7487 100644 --- a/cmd/test/fuzzer_test.cpp +++ b/cmd/test/fuzzer_test.cpp @@ -18,6 +18,8 @@ #include +#include "address_sanitizer_fix.hpp" + using namespace silkworm::rpc::test; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) {