From 968290922ef4d44471c338e4cb306422c505c89d Mon Sep 17 00:00:00 2001 From: Tobias Kortkamp Date: Sun, 1 Dec 2019 08:28:53 +0000 Subject: [PATCH] security/afl++: Add option to build GCC plugin and afl-gcc-fast Unfortunately not enabled by default since lang/gcc* does not enable plugins support by default yet. Suggested by: David Carlier --- security/afl++/Makefile | 40 ++++++++++++++++++++++++++++++++++++---- security/afl++/pkg-plist | 8 ++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/security/afl++/Makefile b/security/afl++/Makefile index 0840d49aa6d1..65850aa59f4b 100644 --- a/security/afl++/Makefile +++ b/security/afl++/Makefile @@ -27,14 +27,18 @@ TEST_TARGET= test_build CONFLICTS_INSTALL= afl -OPTIONS_DEFINE= DEBUG DOCS LLVM +OPTIONS_DEFINE= DEBUG DOCS GCC LLVM OPTIONS_DEFAULT= LLVM # On non-x86 architectures LLVM is mandatory OPTIONS_SLAVE= ${ARCH:Namd64:Ni386:S/${ARCH}/LLVM/} OPTIONS_SUB= yes +GCC_DESC= Build GCC plugin and afl-gcc-fast LLVM_DESC= LLVM-based instrumentation +GCC_BUILD_DEPENDS= gcc${GCC_DEFAULT}:lang/gcc${GCC_DEFAULT} +GCC_RUN_DEPENDS= gcc${GCC_DEFAULT}:lang/gcc${GCC_DEFAULT} + LLVM_BUILD_DEPENDS= clang${LLVM_DEFAULT}:devel/llvm${LLVM_DEFAULT} LLVM_RUN_DEPENDS= clang${LLVM_DEFAULT}:devel/llvm${LLVM_DEFAULT} LLVM_MAKE_ARGS= LLVM_CONFIG=llvm-config${LLVM_DEFAULT} @@ -71,12 +75,22 @@ post-patch: .endif @${CAT} ${FILESDIR}/Makefile.extra >> ${WRKSRC}/Makefile +post-patch-GCC-on: + @${REINPLACE_CMD} \ + -e 's|"gcc"|"gcc${GCC_DEFAULT}"|g' \ + -e 's|"g\+\+"|"g\+\+${GCC_DEFAULT}"|g' \ + ${WRKSRC}/gcc_plugin/afl-gcc-fast.c + post-patch-LLVM-on: @${REINPLACE_CMD} \ -e 's|"clang"|"clang${LLVM_DEFAULT}"|g' \ -e 's|"clang\+\+"|"clang\+\+${LLVM_DEFAULT}"|g' \ ${WRKSRC}/llvm_mode/afl-clang-fast.c +post-build-GCC-on: + @${DO_MAKE_BUILD} -C ${WRKSRC}/gcc_plugin CC=gcc${GCC_DEFAULT} \ + CXX=g++${GCC_DEFAULT} + post-install: .for script in afl-cmin afl-plot afl-whatsup ${INSTALL_SCRIPT} ${WRKSRC}/${script} ${STAGEDIR}${PREFIX}/bin @@ -85,12 +99,26 @@ post-install: .for prog in afl-analyze afl-fuzz afl-gcc afl-gotcpu afl-showmap afl-tmin @${STRIP_CMD} ${STAGEDIR}${PREFIX}/bin/${prog} .endfor - ${INSTALL_LIB} ${WRKSRC}/libdislocator.so \ - ${STAGEDIR}${PREFIX}/lib/afl - ${MKDIR} ${STAGEDIR}${DOCSDIR}/libdislocator + @${STRIP_CMD} ${STAGEDIR}${PREFIX}/lib/afl/*.so + @${MKDIR} ${STAGEDIR}${DOCSDIR}/libdislocator ${INSTALL_MAN} ${WRKSRC}/libdislocator/README.md \ ${STAGEDIR}${DOCSDIR}/libdislocator +post-install-GCC-on: + ${INSTALL_PROGRAM} ${WRKSRC}/afl-g++-fast \ + ${WRKSRC}/afl-gcc-fast \ + ${STAGEDIR}${PREFIX}/bin + ${INSTALL_MAN} ${WRKSRC}/afl-g++-fast.8 \ + ${WRKSRC}/afl-gcc-fast.8 \ + ${STAGEDIR}${PREFIX}/man/man8 + ${INSTALL_LIB} ${WRKSRC}/afl-gcc-pass.so \ + ${STAGEDIR}${PREFIX}/lib/afl + ${INSTALL_DATA} ${WRKSRC}/afl-gcc-rt.o \ + ${STAGEDIR}${PREFIX}/lib/afl + @${MKDIR} ${STAGEDIR}${DOCSDIR}/gcc_plugin + ${INSTALL_MAN} ${WRKSRC}/gcc_plugin/README.* \ + ${STAGEDIR}${DOCSDIR}/gcc_plugin + post-install-LLVM-on: @${STRIP_CMD} ${STAGEDIR}${PREFIX}/lib/afl/*.so \ ${STAGEDIR}${PREFIX}/bin/afl-clang-fast @@ -98,4 +126,8 @@ post-install-LLVM-on: ${INSTALL_MAN} ${WRKSRC}/llvm_mode/README.* \ ${STAGEDIR}${DOCSDIR}/llvm_mode +post-test-GCC-on: + @${DO_MAKE_BUILD} -C ${WRKSRC}/gcc_plugin CC=gcc${GCC_DEFAULT} \ + CXX=g++${GCC_DEFAULT} test_build + .include diff --git a/security/afl++/pkg-plist b/security/afl++/pkg-plist index 63c3c8357c5b..cc6399a137a3 100644 --- a/security/afl++/pkg-plist +++ b/security/afl++/pkg-plist @@ -3,6 +3,8 @@ bin/afl-analyze %%X86%%bin/afl-clang++ %%LLVM%%bin/afl-clang-fast %%LLVM%%bin/afl-clang-fast++ +%%GCC%%bin/afl-g++-fast +%%GCC%%bin/afl-gcc-fast bin/afl-cmin bin/afl-fuzz %%X86%%bin/afl-g++ @@ -14,6 +16,8 @@ bin/afl-system-config bin/afl-tmin bin/afl-whatsup %%X86%%lib/afl/afl-as +%%GCC%%lib/afl/afl-gcc-pass.so +%%GCC%%lib/afl/afl-gcc-rt.o %%LLVM%%lib/afl/afl-llvm-pass.so %%X86%%%%LLVM%%lib/afl/afl-llvm-rt-32.o %%LLVM%%lib/afl/afl-llvm-rt-64.o @@ -28,6 +32,8 @@ lib/afl/libdislocator.so %%LLVM%%man/man8/afl-clang-fast++.8.gz man/man8/afl-cmin.8.gz man/man8/afl-fuzz.8.gz +%%GCC%%man/man8/afl-g++-fast.8.gz +%%GCC%%man/man8/afl-gcc-fast.8.gz man/man8/afl-gcc.8.gz man/man8/afl-gotcpu.8.gz man/man8/afl-plot.8.gz @@ -93,6 +99,8 @@ man/man8/afl-whatsup.8.gz %%PORTDOCS%%%%DOCSDIR%%/binaryonly_fuzzing.txt %%PORTDOCS%%%%DOCSDIR%%/custom_mutator.txt %%PORTDOCS%%%%DOCSDIR%%/env_variables.txt +%%GCC%%%%PORTDOCS%%%%DOCSDIR%%/gcc_plugin/README.gcc.md +%%GCC%%%%PORTDOCS%%%%DOCSDIR%%/gcc_plugin/README.whitelist.md %%PORTDOCS%%%%DOCSDIR%%/historical_notes.txt %%PORTDOCS%%%%DOCSDIR%%/libdislocator/README.md %%PORTDOCS%%%%DOCSDIR%%/life_pro_tips.txt