summaryrefslogtreecommitdiff
path: root/packaging/gcc-force-options
blob: 34f49455f2b8a0ddd79b389ef39e42a02a642377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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