From e11b1787217aa306d2925d3857efd04a8f68b08d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Mon, 6 Oct 2025 07:06:13 +0200 Subject: [PATCH] gnu: aflplusplus: Enable llvm_mode and afl-clang-lto. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gnu/packages/debug.scm (aflplusplus) [inputs]: Replace gcc-11 with gcc; add clang. [native-inputs]: Replace gcc-11 with gcc. [arguments]: Set CXX, LLVM_CONFIG, AFL_REAL_LD, CLANG_BIN, CLANGPP_BIN, LLVM_LTO and AFL_CLANG_FLTO. : Add fatal-llvm-failure and patch-clang-path. Closes: guix/guix#3358 Change-Id: Ia306cc33b07186299c4310619a0b70bc42fea1be Signed-off-by: 宋文武 --- gnu/packages/debug.scm | 44 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/gnu/packages/debug.scm b/gnu/packages/debug.scm index cf00e82cca0408d003f62e307dfa3017ba66881a..2258e2ff2dfb88dcb2e5a7d0ec2a973518b00714 100644 --- a/gnu/packages/debug.scm +++ b/gnu/packages/debug.scm @@ -627,9 +627,47 @@ server and embedded PowerPC, and S390 guests.") (string-append "DOC_PATH=" #$output "/share/doc/" #$(package-name this-package) "-" #$(package-version this-package)) - (string-append "CC=" #$(cc-for-target)))) + (string-append "CC=" #$(cc-for-target)) + (string-append "CXX=" #$(cxx-for-target)) + (string-append "LLVM_CONFIG=" + (search-input-file %build-inputs "/bin/llvm-config")) + ;; Need to use LLD with the llvm_mode, because LTO in + ;; combination with binutils gold is currently broken. + ;; + ;; See: https://codeberg.org/guix/guix/issues/3307 + (string-append "AFL_REAL_LD=" + (search-input-file %build-inputs "/bin/ld.lld")) + (string-append "CLANG_BIN=" + (search-input-file %build-inputs "/bin/clang")) + (string-append "CLANGPP_BIN=" + (search-input-file %build-inputs "/bin/clang++")) + "LLVM_LTO=1" + "AFL_CLANG_FLTO=-flto=full")) ((#:phases phases '%standard-phases) #~(modify-phases #$phases + ;; Ensure that the build fails early if LLVM support fails to + ;; compile, makes the build log much easier to understand. + (add-after 'unpack 'fatal-llvm-failure + (lambda* (#:key inputs #:allow-other-keys) + (substitute* "GNUmakefile" + (("-\\$\\(MAKE\\) ..* -f GNUmakefile.llvm$" all) + (substring all 1))))) ; remove the leading '-' + ;; GNUmakefile.llvm tries to find clang/clang++ relative to the + ;; --bindir reported by llvm-config, but since llvm and clang + ;; have different store paths on Guix, this doesn't work here. + (add-after 'unpack 'patch-clang-path + (lambda* (#:key inputs #:allow-other-keys) + (substitute* "GNUmakefile.llvm" + (("^CC *= .*$") + (string-append + "override CC = " + (search-input-file inputs "/bin/clang") + "\n")) + (("^CXX *= .*$") + (string-append + "override CXX = " + (search-input-file inputs "/bin/clang++") + "\n"))))) ;; For GCC plugins. (add-after 'unpack 'patch-gcc-path (lambda* (#:key inputs #:allow-other-keys) @@ -656,8 +694,8 @@ server and embedded PowerPC, and S390 guests.") `("AFL_PATH" = (,(string-append #$output "/lib/afl")))))))))) ;; According to the Dockerfile, GCC 12 is producing compile errors for some ;; targets, so explicitly use GCC 11 here. - (inputs (list gcc-11 gmp python qemu-for-aflplusplus)) - (native-inputs (list gcc-11)) + (inputs (list llvm-20 clang-20 lld-20 gcc gmp python qemu-for-aflplusplus)) + (native-inputs (list gcc)) (home-page "https://aflplus.plus/") (description "AFLplusplus is a security-oriented fuzzer that employs a novel type of