From 8094949001517719430c08538cde2f4d39318873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Sat, 5 Feb 2022 15:53:30 +0100 Subject: [PATCH] CI: Rework fuzzing and sanitizing --- .github/workflows/linux-build-sanitizer.yml | 35 +++++++++--------- .github/workflows/linux-build.yml | 1 + .github/workflows/msys2-build.yml | 3 +- .github/workflows/windows-build.yml | 1 + xmake.lua | 7 ++-- xmake/toolchains/hfuzz-clang/xmake.lua | 39 +++++++++++++++++++++ 6 files changed, 62 insertions(+), 24 deletions(-) create mode 100644 xmake/toolchains/hfuzz-clang/xmake.lua diff --git a/.github/workflows/linux-build-sanitizer.yml b/.github/workflows/linux-build-sanitizer.yml index 1a21ad7e4..d0babc72a 100644 --- a/.github/workflows/linux-build-sanitizer.yml +++ b/.github/workflows/linux-build-sanitizer.yml @@ -4,6 +4,7 @@ on: pull_request: push: paths-ignore: + - '.github/workflows/linux-build.yml' - '.github/workflows/msys2-build.yml' - '.github/workflows/windows-build.yml' - '.gitignore' @@ -19,7 +20,7 @@ jobs: matrix: os: [ubuntu-20.04] arch: [x86_64] - mode: [debug, releasedbg] + mode: [asan] runs-on: ${{ matrix.os }} if: "!contains(github.event.head_commit.message, 'ci skip')" @@ -35,12 +36,16 @@ jobs: - name: Install system dependencies run: | sudo apt-get install libsndfile1-dev libfreetype6-dev libsdl2-dev mesa-common-dev libxcb-ewmh-dev libxcb-randr0-dev libxcb-icccm4-dev libxcb-keysyms1-dev libgl1-mesa-dev git -y - sudo apt-get install libunwind8-dev libunwind-dev binutils-dev clang-11 -y - sudo apt-get install qtbase5-dev qtdeclarative5-dev + sudo apt-get install libunwind-dev binutils-dev clang-11 -y - git clone https://github.com/google/honggfuzz - make -C honggfuzz - + # Install Honggfuzz + - name: Build and install Hongfuzz + run: | + wget https://github.com/google/honggfuzz/archive/refs/tags/2.5.tar.gz -O honggfuzz.tar.gz + tar -xzvf honggfuzz.tar.gz + cd honggfuzz-*/ + make + sudo make install # Force xmake to a specific folder (for cache) - name: Set xmake env @@ -70,21 +75,15 @@ jobs: # Setup compilation mode and install project dependencies - name: Configure xmake and install dependencies - run: xmake config --shadernodes=y --tests=y --arch=${{ matrix.arch }} --mode=${{ matrix.mode }} --verbose --yes --ld=$(pwd)/honggfuzz/hfuzz_cc/hfuzz-clang++ --sh=$(pwd)/honggfuzz/hfuzz_cc/hfuzz-clang++ --ar=$(pwd)/honggfuzz/hfuzz_cc/hfuzz-clang++ --cxx=$(pwd)/honggfuzz/hfuzz_cc/hfuzz-clang++ --cxxflags="-fsanitize=fuzzer-no-link,address" --ldflags=-fsanitize=fuzzer-no-link,address --shflags=-fsanitize=fuzzer-no-link,address --arflags=-fsanitize=fuzzer-no-link,address --arch=${{ matrix.arch }} --mode=${{ matrix.mode }} --yes --verbose + run: xmake config --shadernodes=y --tests=y --arch=${{ matrix.arch }} --mode=${{ matrix.mode }} --verbose --yes + + # Configure xmake with honggfuzz to build the engine + - name: Configure xmake with honggfuzz + run: xmake config --shadernodes=y --tests=y --arch=${{ matrix.arch }} --mode=${{ matrix.mode }} --verbose --toolchain=hfuzz-clang # Build the engine - name: Build Nazara run: xmake -v - - name: Run Sanitized Nazaras + - name: Run Nazara Unit tests run: xmake run NazaraUnitTests - - # Install the result files - - name: Install Nazara - run: xmake install -vo package - - # Upload artifacts - - uses: actions/upload-artifact@v2 - with: - name: ${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.mode }} - path: package diff --git a/.github/workflows/linux-build.yml b/.github/workflows/linux-build.yml index 2b8885e4f..faa836a4a 100644 --- a/.github/workflows/linux-build.yml +++ b/.github/workflows/linux-build.yml @@ -4,6 +4,7 @@ on: pull_request: push: paths-ignore: + - '.github/workflows/linux-build-sanitizer.yml' - '.github/workflows/msys2-build.yml' - '.github/workflows/windows-build.yml' - '.gitignore' diff --git a/.github/workflows/msys2-build.yml b/.github/workflows/msys2-build.yml index ea905739a..05177870e 100644 --- a/.github/workflows/msys2-build.yml +++ b/.github/workflows/msys2-build.yml @@ -4,6 +4,7 @@ on: pull_request: push: paths-ignore: + - '.github/workflows/linux-build-sanitizer.yml' - '.github/workflows/linux-build.yml' - '.github/workflows/windows-build.yml' - '.gitignore' @@ -76,7 +77,7 @@ jobs: # Build the engine - name: Build Nazara - run: xmake -v + run: xmake # Install the result files - name: Install Nazara diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 5ca9c31c3..e4c4966ac 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -4,6 +4,7 @@ on: pull_request: push: paths-ignore: + - '.github/workflows/linux-build-sanitizer.yml' - '.github/workflows/linux-build.yml' - '.github/workflows/msys2-build.yml' - '.gitignore' diff --git a/xmake.lua b/xmake.lua index 298bca31b..e1d6c8e08 100644 --- a/xmake.lua +++ b/xmake.lua @@ -103,11 +103,9 @@ local modules = { } } --- remove_headerfiles and remove_files were added in xmake 2.6.3, add a fallback for previous versions -remove_files = remove_files or del_files -remove_headerfiles = remove_headerfiles or function () end +includes("xmake/**.lua") -set_xmakever("2.5.6") +set_xmakever("2.6.3") add_repositories("local-repo xmake-repo") @@ -230,7 +228,6 @@ for name, module in pairs(modules) do end end -includes("xmake/actions/*.lua") includes("tools/xmake.lua") includes("tests/xmake.lua") includes("plugins/*/xmake.lua") diff --git a/xmake/toolchains/hfuzz-clang/xmake.lua b/xmake/toolchains/hfuzz-clang/xmake.lua new file mode 100644 index 000000000..c76bc7a09 --- /dev/null +++ b/xmake/toolchains/hfuzz-clang/xmake.lua @@ -0,0 +1,39 @@ +toolchain("hfuzz-clang") + + set_homepage("https://honggfuzz.dev") + set_description("Security oriented software fuzzer. Supports evolutionary, feedback-driven fuzzing based on code coverage (SW and HW based)") + + set_kind("standalone") + + set_toolset("cc", "hfuzz-clang") + set_toolset("cxx", "hfuzz-clang++") + set_toolset("ld", "hfuzz-clang++", "hfuzz-clang") + set_toolset("sh", "hfuzz-clang++", "hfuzz-clang") + set_toolset("ar", "ar") + set_toolset("strip", "strip") + set_toolset("mm", "hfuzz-clang") + set_toolset("mxx", "hfuzz-clang++") + set_toolset("as", "hfuzz-clang") + + add_cxflags("-fsanitize=fuzzer-no-link") + add_ldflags("-fsanitize=fuzzer-no-link") + add_shflags("-fsanitize=fuzzer-no-link") + add_arflags("-fsanitize=fuzzer-no-link") + + on_check(function (toolchain) + return import("lib.detect.find_tool")("hfuzz-clang") + end) + + on_load(function (toolchain) + local march + if toolchain:is_arch("x86_64", "x64") then + march = "-m64" + elseif toolchain:is_arch("i386", "x86") then + march = "-m32" + end + if march then + toolchain:add("cxflags", march) + toolchain:add("ldflags", march) + toolchain:add("shflags", march) + end + end)