Inline TLS access. (#17119)
[mono-project.git] / data / dtrace-prelink.sh
blobcb6508f0cef76c8fe7ea9418342ceab15aaf0668
1 #!/bin/sh
2 #
3 # dtrace-prelink.sh: DTrace helper script for Mono
4 #
5 # Authors:
6 # Andreas Faerber <andreas.faerber@web.de>
7 #
9 # Assume that PIC object files live in .libs/, non-PIC code in ./
10 PIC=no
11 if test "$1" = "--pic"; then
12 PIC=yes
13 shift
16 OBJ="$1"
17 PROV="$2"
19 shift
20 shift
22 FILES="$*"
24 OBJS=
25 TMPDIR=.dtrace
26 mkdir -p "${TMPDIR}"
28 # Extract relevant object files to temporary directories
29 for FILE in ${FILES}; do
30 if echo "${FILE}" | grep .la > /dev/null; then
31 LIBDIR=`dirname ${FILE}`
32 LIB=".libs/`basename ${FILE} .la`.a"
33 DIR="${TMPDIR}/`basename ${FILE}`"
34 mkdir -p ${DIR}
35 (cd "${DIR}" && ${AR} x "../../${LIBDIR}/${LIB}")
36 TMPOBJS=`ls -1 "${DIR}"`
37 for TMPOBJ in ${TMPOBJS}; do
38 LO=`basename "${TMPOBJ}" .o`.lo
39 SRCOBJ="${TMPOBJ}"
40 if test x${PIC} = xyes; then
41 SRCOBJ=".libs/${SRCOBJ}"
43 # Overwrite with original version
44 cp "${LIBDIR}/${SRCOBJ}" "${DIR}/${TMPOBJ}" || cp "${LIBDIR}/${TMPOBJ}" "${DIR}/${TMPOBJ}" || exit
45 # Add to list
46 OBJS="${OBJS} ${DIR}/${TMPOBJ}"
47 done
49 if echo "${FILE}" | grep .lo > /dev/null; then
50 DIR=`dirname ${FILE}`
51 SRCOBJ=`basename ${FILE} .lo`.o
52 if test x${PIC} = xyes; then
53 SRCOBJ=".libs/${SRCOBJ}"
55 OBJS="${OBJS} ${DIR}/${SRCOBJ}"
57 done
59 # Run dtrace -G over the temporary objects
60 ${DTRACE} -G ${DTRACEFLAGS} -s "${PROV}" -o "${OBJ}" ${OBJS} || exit
62 # Update the archives with the temporary, modified object files so that they are linked in
63 for FILE in ${FILES}; do
64 if echo "${FILE}" | grep .la > /dev/null; then
65 LIBDIR=`dirname ${FILE}`
66 LIB=".libs/`basename ${FILE} .la`.a"
67 DIR="${TMPDIR}/`basename ${FILE}`"
68 (cd "${DIR}" && ${AR} r "../../${LIBDIR}/${LIB}" *.o)
70 # .lo files were modified in-place
71 done
73 rm -rf "${TMPDIR}"