~ruther/guix-local

b9e5d234d9551dfb85f1c2c6f400b6ae93ddb559 — Nguyễn Gia Phong a year ago b54a327
gnu: Add qemu-for-aflplusplus.

* gnu/packages/debug.scm (qemu-for-aflplusplus): New variable.

Change-Id: Iecb693c5f4544ac511387a59819ecab422c62949
Signed-off-by: 宋文武 <iyzsong@member.fsf.org>
1 files changed, 77 insertions(+), 0 deletions(-)

M gnu/packages/debug.scm
M gnu/packages/debug.scm => gnu/packages/debug.scm +77 -0
@@ 529,6 529,83 @@ server and embedded PowerPC, and S390 guests.")
    ;; Several tests fail on MIPS.
    (supported-systems (delete "mips64el-linux" %supported-systems))))))

(define-public qemu-for-aflplusplus
  (let ((base qemu-minimal)
        (commit "790d2124fd054621d3c0d3ec31bea114b60601f9")
        (revision "0"))
    (hidden-package
     (package
       (inherit base)
       (name "qemu")
       (version (git-version "5.2.50" revision commit))
       (source
        (origin
          (method git-fetch)
          (uri (git-reference (url "https://github.com/AFLplusplus/qemuafl")
                              (commit commit)
                              (recursive? #t)))
          (file-name (git-file-name name version))
          (sha256
           (base32 "1l2kl8768l4mbkiaj63zn6gsdn3qpl3rg7s6h62rmd7599ar3xn3"))))
       (arguments
        (substitute-keyword-arguments (package-arguments base)
          ((#:configure-flags _ #~'())
           #~(list (string-append
                    "--target-list="
                    ;; AFL++ only supports using a single afl-qemu-trace,
                    ;; so we only build qemu for the native target.
                    (match #$(let-system system system)
                      ("aarch64-linux"  "aarch64-linux-user")
                      ("armhf-linux"    "arm-linux-user")
                      ("i686-linux"     "i386-linux-user")
                      ("mips64el-linux" "mips64el-linux-user")
                      ("powerpc-linux"  "ppc-linux-user")
                      ("riscv64-linux"  "riscv64-linux-user")
                      ("x86_64-linux"   "x86_64-linux-user")))))
          ((#:phases phases)
           #~(modify-phases #$phases
               (delete 'replace-firmwares)
               (delete 'patch-embedded-shebangs)
               (delete 'fix-optionrom-makefile)
               (delete 'disable-unusable-tests)
               (replace 'configure
                 (lambda* (#:key configure-flags #:allow-other-keys)
                   ;; The `configure' script doesn't understand some of the
                   ;; GNU options.  Thus, add a new phase that's compatible.
                   (setenv "SHELL" (which "bash"))
                   ;; The binaries need to be linked against -lrt.
                   (setenv "LDFLAGS" "-lrt")
                   (apply invoke
                          "./configure"
                          (string-append "--cc=" #$(cc-for-target))
                          ;; Some architectures insist on using HOST_CC
                          (string-append "--host-cc=" #$(cc-for-target))
                          "--disable-debug-info" ; save build space
                          (string-append "--prefix=" #$output)
                          (string-append "--sysconfdir=/etc")
                          configure-flags)))
               (add-after 'install 'install-qasan-header
                 (lambda _
                   (install-file "qemuafl/qasan.h"
                                 (string-append #$output "/include"))))
               (delete 'delete-firmwares)
               #$@(if (target-riscv64?)
                      '((replace 'disable-some-tests
                          (lambda _
                            ;; qemu.qmp.QMPConnectError:
                            ;; Unexpected empty reply from server
                            (delete-file "tests/qemu-iotests/040")
                            (delete-file "tests/qemu-iotests/041")
                            (delete-file "tests/qemu-iotests/256")
                            ;; No 'PCI' bus found for device 'virtio-scsi-pci'
                            (delete-file "tests/qemu-iotests/127")
                            (delete-file "tests/qemu-iotests/267"))))
                      '())))))
       (inputs (modify-inputs (package-inputs base)
                 (delete "dtc")))
       (home-page "https://github.com/AFLplusplus/qemuafl")
       (synopsis "QEMU for AFL++")))))

(define-public aflplusplus
  (package
    (inherit american-fuzzy-lop)