From dac1ec64a3b7d79f2ad9e66bd9a1d76d76b10205 Mon Sep 17 00:00:00 2001 From: Eduard Zingerman Date: Fri, 18 Jul 2025 16:42:07 -0700 Subject: [PATCH] scripts: allow skipping elfutils rebuild in build-fuzzers.sh This simplifies local reproduction of fuzzer reported errors. E.g. the following sequence of commands would execute much faster on a second run: $ SKIP_LIBELF_REBUILD=1 scripts/build-fuzzers.sh $ out/bpf-object-fuzzer Signed-off-by: Eduard Zingerman --- scripts/build-fuzzers.sh | 60 +++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/scripts/build-fuzzers.sh b/scripts/build-fuzzers.sh index 72de432..fa1dacf 100755 --- a/scripts/build-fuzzers.sh +++ b/scripts/build-fuzzers.sh @@ -35,44 +35,48 @@ if [[ "$SANITIZER" == undefined ]]; then CXXFLAGS+=" $UBSAN_FLAGS" fi +export SKIP_LIBELF_REBUILD=${SKIP_LIBELF_REBUILD:=''} + # Ideally libbelf should be built using release tarballs available # at https://sourceware.org/elfutils/ftp/. Unfortunately sometimes they # fail to compile (for example, elfutils-0.185 fails to compile with LDFLAGS enabled # due to https://bugs.gentoo.org/794601) so let's just point the script to # commits referring to versions of libelf that actually can be built -rm -rf elfutils -git clone https://sourceware.org/git/elfutils.git -( -cd elfutils -git checkout 67a187d4c1790058fc7fd218317851cb68bb087c -git log --oneline -1 +if [[ ! -e elfutils || "$SKIP_LIBELF_REBUILD" == "" ]]; then + rm -rf elfutils + git clone https://sourceware.org/git/elfutils.git + ( + cd elfutils + git checkout 67a187d4c1790058fc7fd218317851cb68bb087c + git log --oneline -1 -# ASan isn't compatible with -Wl,--no-undefined: https://github.com/google/sanitizers/issues/380 -sed -i 's/^\(NO_UNDEFINED=\).*/\1/' configure.ac + # ASan isn't compatible with -Wl,--no-undefined: https://github.com/google/sanitizers/issues/380 + sed -i 's/^\(NO_UNDEFINED=\).*/\1/' configure.ac -# ASan isn't compatible with -Wl,-z,defs either: -# https://clang.llvm.org/docs/AddressSanitizer.html#usage -sed -i 's/^\(ZDEFS_LDFLAGS=\).*/\1/' configure.ac + # ASan isn't compatible with -Wl,-z,defs either: + # https://clang.llvm.org/docs/AddressSanitizer.html#usage + sed -i 's/^\(ZDEFS_LDFLAGS=\).*/\1/' configure.ac -if [[ "$SANITIZER" == undefined ]]; then - # That's basicaly what --enable-sanitize-undefined does to turn off unaligned access - # elfutils heavily relies on on i386/x86_64 but without changing compiler flags along the way - sed -i 's/\(check_undefined_val\)=[0-9]/\1=1/' configure.ac + if [[ "$SANITIZER" == undefined ]]; then + # That's basicaly what --enable-sanitize-undefined does to turn off unaligned access + # elfutils heavily relies on on i386/x86_64 but without changing compiler flags along the way + sed -i 's/\(check_undefined_val\)=[0-9]/\1=1/' configure.ac + fi + + autoreconf -i -f + if ! ./configure --enable-maintainer-mode --disable-debuginfod --disable-libdebuginfod \ + --disable-demangler --without-bzlib --without-lzma --without-zstd \ + CC="$CC" CFLAGS="-Wno-error $CFLAGS" CXX="$CXX" CXXFLAGS="-Wno-error $CXXFLAGS" LDFLAGS="$CFLAGS"; then + cat config.log + exit 1 + fi + + make -C config -j$(nproc) V=1 + make -C lib -j$(nproc) V=1 + make -C libelf -j$(nproc) V=1 + ) fi -autoreconf -i -f -if ! ./configure --enable-maintainer-mode --disable-debuginfod --disable-libdebuginfod \ - --disable-demangler --without-bzlib --without-lzma --without-zstd \ - CC="$CC" CFLAGS="-Wno-error $CFLAGS" CXX="$CXX" CXXFLAGS="-Wno-error $CXXFLAGS" LDFLAGS="$CFLAGS"; then - cat config.log - exit 1 -fi - -make -C config -j$(nproc) V=1 -make -C lib -j$(nproc) V=1 -make -C libelf -j$(nproc) V=1 -) - make -C src BUILD_STATIC_ONLY=y V=1 clean make -C src -j$(nproc) CFLAGS="-I$(pwd)/elfutils/libelf $CFLAGS" BUILD_STATIC_ONLY=y V=1