--- /dev/null
+#!/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
+
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.
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