forked from eurecom-s3/symcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sym++.in
executable file
·65 lines (59 loc) · 2.53 KB
/
sym++.in
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
#!/bin/bash
# This file is part of SymCC.
#
# SymCC is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# SymCC is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# SymCC. If not, see <https://www.gnu.org/licenses/>.
runtime_64bit_dir="${SYMCC_RUNTIME_DIR:-@SYM_RUNTIME_DIR@}"
runtime_32bit_dir="${SYMCC_RUNTIME32_DIR:-@SYM_RUNTIME_32BIT_DIR@}"
pass="${SYMCC_PASS_DIR:-@CMAKE_CURRENT_BINARY_DIR@}/libSymbolize.so"
libcxx_var=SYMCC_LIBCXX_PATH
compiler="${SYMCC_CLANGPP:-@CLANGPP_BINARY@}"
# Find out if we're cross-compiling for a 32-bit architecture
runtime_dir="$runtime_64bit_dir"
for arg in "$@"; do
if [[ $arg == "-m32" ]]; then
if [ -z "$runtime_32bit_dir" ]; then
echo "SymCC: 32-bit compilation requested but SymCC was not built with TARGET_32BIT=ON" >&2
exit 255
else
runtime_dir="$runtime_32bit_dir"
libcxx_var=SYMCC_LIBCXX_32BIT_PATH
break
fi
fi
done
if [[ -v SYMCC_REGULAR_LIBCXX ]]; then
stdlib_cflags=
stdlib_ldflags=
elif [[ ! -v $libcxx_var ]]; then
>&2 echo "Please set $libcxx_var to the directory containing libc++ or confirm usage of the system library by setting SYMCC_REGULAR_LIBCXX!"
exit 255
else
# It is important that the resulting binaries load libstdc++ before libc++;
# otherwise our backend calls the instrumented library in cases where
# exported names collide.
stdlib_cflags="-isystem ${!libcxx_var}/include/c++/v1 -nostdlib++"
stdlib_ldflags="-L${!libcxx_var}/lib -Wl,-rpath,${!libcxx_var}/lib -lstdc++ -lc++ -stdlib=libc++"
fi
if [ $# -eq 0 ]; then
echo "Use sym++ as a drop-in replacement for clang++, e.g., sym++ -O2 -o foo foo.cpp" >&2
exit 1
fi
exec $compiler \
-Xclang -load -Xclang "$pass" \
$stdlib_cflags \
"$@" \
$stdlib_ldflags \
-L"$runtime_dir" \
-lSymRuntime \
-Wl,-rpath,"$runtime_dir" \
-Qunused-arguments