From: Maria Guseva Date: Fri, 5 May 2017 16:04:28 +0000 (+0300) Subject: Introduce fuzz-force-options package X-Git-Tag: submit/tizen/20170714.013956~23 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1f4515a7ebf41bb253fa9c8d92fe3e045a69f4f8;p=tools%2FlibFuzzer.git Introduce fuzz-force-options package The packages forces compile options for Address Sanitization and coverage needed for fuzzing. --- diff --git a/packaging/gcc-force-options b/packaging/gcc-force-options new file mode 100755 index 0000000..34f4945 --- /dev/null +++ b/packaging/gcc-force-options @@ -0,0 +1,70 @@ +#!/bin/sh + +set -e + +if [ $# -eq 0 ]; then + cat << EOF +Syntax: + $(basename $0) OPT1 [OPT2...]" + +Example: + $(basename $0) [prepend|append] -fsanitize=address -fno-common -U_FORTIFY_SOURCE + By default flags are appending. +EOF + exit 1 +fi + +FLAGS="$@" + +if [ $(find $(dirname $0) -name \*-real | wc -l) -gt 0 ]; then + echo >&2 "$(basename $0): directory was already processed, aborting" + exit 1 +fi + +case "$1" in +prepend) + shift + PREFLAGS="$@" + POSTFLAGS= + ;; +append) + shift + PREFLAGS= + POSTFLAGS="$@" + ;; +*) + PREFLAGS= + POSTFLAGS="$@" + ;; +esac + +TMP=$(pwd)/tmp.$$ +cat > $TMP << EOF +#!/bin/sh +if echo "$PREFLAGS "\$@" $POSTFLAGS" | grep -q -- "-fsanitize=undefined" && echo "\$@" | grep -q "\.gch\>"; then + # UBSan doesn't support precompiled headers. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66343 + echo "Precompiled headers currently not supported by UBSan" >&2 + # Don't instrument kernel modules + # Don't instrument with "-nostdlib" linking +elif ! echo "\$@" | grep -q -e __KERNEL__ -e \-nostdlib; then + # Use readlink in order to follow symlinks if any + \$(readlink -f \$0)-real $PREFLAGS "\$@" $POSTFLAGS +else + \$(readlink -f \$0)-real "\$@" +fi +EOF +chmod +x $TMP + +find -L $(dirname $0) -type f -a -perm -a=x | grep -E '(gcc|g\+\+|c\+\+)$' | while read tool; do + mv $tool $tool-real + cp $TMP $tool +done + +if [ -d /emul ]; then + find -L /emul -type f -a -perm -a=x | grep -E '(gcc|g\+\+|c\+\+)$' | while read tool; do + ln -sf $(basename $tool) $tool-real + done +fi + +rm $TMP + diff --git a/packaging/gcc-unforce-options b/packaging/gcc-unforce-options new file mode 100755 index 0000000..cf36d04 --- /dev/null +++ b/packaging/gcc-unforce-options @@ -0,0 +1,19 @@ +#!/bin/sh + +set -e + +if [ $# -gt 0 ]; then + echo >&2 "$(basename $0): unexpected arguments" + exit 1 +fi + +find $(dirname $0) -name \*-real | while read tool_real; do + tool=$(echo "$tool_real" | sed -e 's/-real$//') + mv $tool_real $tool +done +if [ -d /emul ]; then + find /emul -name \*-real | while read tool_real; do + rm $tool_real + done +fi + diff --git a/packaging/libFuzzer.spec b/packaging/libFuzzer.spec index 30372e7..8e8b707 100644 --- a/packaging/libFuzzer.spec +++ b/packaging/libFuzzer.spec @@ -6,6 +6,8 @@ Summary: libFuzzer Url: http://llvm.org/docs/LibFuzzer.html Group: Development/Testing Source0: %{name}-%{version}.tar.xz +Source1: gcc-force-options +Source2: gcc-unforce-options %description LibFuzzer is in-process, coverage-guided, evolutionary fuzzing engine. @@ -24,9 +26,35 @@ ar rcs libsancov_cb.a sancov_cb.o mkdir -p %{buildroot}%{_libdir} cp lib/Fuzzer/libFuzzer.a %{buildroot}%{_libdir} cp libsancov_cb.a %{buildroot}%{_libdir} +mkdir -p %{buildroot}%{_prefix}/bin +cp %{SOURCE1} %{SOURCE2} %{buildroot}%{_prefix}/bin %files %manifest %{name}.manifest %defattr(-,root,root,-) %{_libdir}/libFuzzer.a + +%package -n fuzz-force-options +Summary: Scripts to enable automatic package sanitization for fuzzing +Group: System Environment +# Need to have gcc installed before running the force-options script +Requires: gcc libasan + +%description -n fuzz-force-options +Scripts for ASan and SanCov instrumentation needed for fuzzing. + +%post -n fuzz-force-options +# Change mode to allow all users to run gcc-force/unforce-options +chmod a+w /usr/bin +/usr/bin/gcc-force-options -fsanitize-coverage=trace-pc -fsanitize=address -fno-common -fno-omit-frame-pointer -U_FORTIFY_SOURCE -lsancov_cb +chmod a-w /usr/bin + +%preun -n fuzz-force-options +chmod a+w /usr/bin +/usr/bin/gcc-unforce-options +chmod a-w /usr/bin + +%files -n fuzz-force-options +%{_prefix}/bin/gcc-force-options +%{_prefix}/bin/gcc-unforce-options %{_libdir}/libsancov_cb.a