-
Notifications
You must be signed in to change notification settings - Fork 2
/
clang-tsx
executable file
·72 lines (55 loc) · 1.6 KB
/
clang-tsx
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
71
#!/bin/bash
# set -o xtrace
root=`dirname $(readlink -f $0)`
buildpath=$root/build/
srcpath=$root/src/
mode=$TSXCFI_MODE
libcpath=$buildpath/libc/musl_$mode/lib/
args="$@"
if [ -s $TSXCFI_MODE ]; then echo "Please source switch.sh in the root folder of the project, and switch in one of the 3 mode"; exit 1; fi;
if [ -z "$args" ]; then exit 1; fi;
command="$buildpath/llvm/llvm-build/bin/clang $args -fno-optimize-sibling-calls -nostdlib -nodefaultlibs -Qunused-arguments -mllvm -tsx-cfi=$mode"
fblib="hlefb" # in native mode it's never called from the code
if [ $mode == "rtm" ]; then
fblib="rtmfb"
fi
if [ $mode == "rtm" ]; then
command+=" -Wl,--dynamic-linker=$root/build/ld/glibc_build_rtm/elf/ld.so"
fi
if [ -z $TSXCFI_LIBC ]; then
command+=" -L$libcpath"
fi
if [[ $args == *"-shared"* ]]; then
command+=" -Wl,-Bsymbolic -Wl,--whole-archive,$buildpath/libtsxcfifb/lib$fblib.a -Wl,--no-whole-archive"
else
command+=" -L$buildpath/libtsxcfifb -l$fblib -lc -Wl,$libcpath/crt1.o"
fi;
command+=" -nostartfiles -lgcc"
# Finally running clang..
eval "$command";
# If it's native we don't need to binpatch any file
if [ $mode == "native" ]; then
exit
fi;
# Otherwise find the output file and binpatch it
if [[ $args != *"-c "* ]]; then
name=a.out
MAGIC=`getopt -o o:c -- "$@" 2>/dev/null`
eval set -- "$MAGIC"
while true ; do
case "$1" in
-o)
shift;
name=$1
break
;;
-c)
exit $ret
;;
*)
break
;;
esac
done
python $srcpath/bin_patcher.py $name
fi