forked from amosbird/ldb_toolchain_gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_toolchain.sh
executable file
·466 lines (382 loc) · 17.1 KB
/
generate_toolchain.sh
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
#!/usr/bin/env bash
# Generate toolchain.tgz in CWD
set -e
if [[ -e "toolchain" ]]; then
echo "Dir toolchain/ already exists"
exit 1
fi
mkdir -p toolchain/{bin,lib,libexec}
cp -r -L /opt/exodus/bundles/*/lib/${ARCH}-linux-gnu/* toolchain/lib/
cp -r -L /opt/exodus/bundles/*/usr/lib/${ARCH}-linux-gnu/* toolchain/lib/
cp -r -L /opt/exodus/bundles/*/usr/lib/*.so* toolchain/lib/
cp -L \
/lib/${ARCH}-linux-gnu/libresolv.so.2 \
/lib/${ARCH}-linux-gnu/libnss_nisplus.so.2 \
/lib/${ARCH}-linux-gnu/libnss_compat.so.2 \
/lib/${ARCH}-linux-gnu/libnss_dns.so.2 \
/lib/${ARCH}-linux-gnu/libnss_files.so.2 \
/lib/${ARCH}-linux-gnu/libnss_hesiod.so.2 \
/lib/${ARCH}-linux-gnu/libnss_nis.so.2 \
/lib/${ARCH}-linux-gnu/libtinfo.so.5 \
/lib/${ARCH}-linux-gnu/libncursesw.so.5 \
toolchain/lib/
# Provide gperf CPU profiler
cp -L /usr/lib/${ARCH}-linux-gnu/libprofiler.so.0.4.8 toolchain/lib/libprofiler.so
if [ "${ARCH}" = "x86_64" ]; then
cp -L /usr/lib/${ARCH}-linux-gnu/libunwind.so.8 toolchain/lib/
elif [ "${ARCH}" = "aarch64" ]; then
cp -L /usr/lib/${ARCH}-linux-gnu/libunwind.so.1 toolchain/lib/
else
echo "Unknown architecture: ${ARCH}"
exit 1
fi
gcc -shared -fPIC /disable_ld_preload.c -o toolchain/lib/disable_ld_preload.so -ldl
tar xzf /opt/patchelf-0.14.3-${ARCH}.tar.gz ./bin/patchelf --strip-components=2
for lib in toolchain/lib/*; do
if [[ ! "$lib" = "toolchain/lib/libc.so.6"* ]]; then
./patchelf --set-rpath '$ORIGIN' "$lib"
fi
done
for f in /opt/exodus/bundles/*/usr/bin/*-x /opt/exodus/bundles/*/usr/lib/llvm-${LLVM_VERSION}/bin/*-x; do
p=$(basename $f)
g=${p::-2}
cp $f toolchain/bin/$g
done
cp /usr/lib/llvm-${LLVM_VERSION}/bin/llvm-symbolizer toolchain/bin/
interpreter=""
if [ "${ARCH}" = "x86_64" ]; then
interpreter="$PWD/toolchain/lib/ld-linux-x86-64.so.2"
elif [ "${ARCH}" = "aarch64" ]; then
interpreter="$PWD/toolchain/lib/ld-linux-aarch64.so.1"
else
echo "Unknown architecture: ${ARCH}"
exit 1
fi
for bin in toolchain/bin/*; do
./patchelf --set-interpreter "$interpreter" --set-rpath '$ORIGIN/../lib' "$bin"
done
ln -sf ld.bfd toolchain/bin/ld
if [ "${ARCH}" = "x86_64" ]; then
ln -sf ld.bfd toolchain/bin/x86_64-pc-linux-gnu-ld # clang tries to find this linker
elif [ "${ARCH}" = "aarch64" ]; then
ln -sf ld.bfd toolchain/bin/aarch64-linux-gnu-ld # clang tries to find this linker
else
echo "Unknown architecture: ${ARCH}"
exit 1
fi
ln -sf gcc-ar-${GCC_VERSION} toolchain/bin/gcc-ar
ln -sf gcc-nm-${GCC_VERSION} toolchain/bin/gcc-nm
ln -sf gcc-ranlib-${GCC_VERSION} toolchain/bin/gcc-ranlib
ln -sf llvm-ar-${LLVM_VERSION} toolchain/bin/llvm-ar
ln -sf llvm-cov-${LLVM_VERSION} toolchain/bin/llvm-cov
ln -sf llvm-install-name-tool-${LLVM_VERSION} toolchain/bin/llvm-install-name-tool
ln -sf llvm-nm-${LLVM_VERSION} toolchain/bin/llvm-nm
ln -sf llvm-objcopy-${LLVM_VERSION} toolchain/bin/llvm-objcopy
ln -sf llvm-profdata-${LLVM_VERSION} toolchain/bin/llvm-profdata
ln -sf llvm-profgen-${LLVM_VERSION} toolchain/bin/llvm-profgen
ln -sf llvm-ranlib-${LLVM_VERSION} toolchain/bin/llvm-ranlib
ln -sf llvm-strip-${LLVM_VERSION} toolchain/bin/llvm-strip
ln -sf lld-${LLVM_VERSION} toolchain/bin/ld.lld
ln -sf lld-${LLVM_VERSION} toolchain/bin/ld.lld-${LLVM_VERSION}
ln -sf clang-${LLVM_VERSION} toolchain/bin/clang++-${LLVM_VERSION}
ln -sf llvm-objcopy-${LLVM_VERSION} toolchain/bin/objcopy
ln -sf llvm-objdump-${LLVM_VERSION} toolchain/bin/objdump
ln -sf clang-cpp-${LLVM_VERSION} toolchain/bin/cpp
ln -sf llvm-ar-${LLVM_VERSION} toolchain/bin/ar
ln -sf llvm-ranlib-${LLVM_VERSION} toolchain/bin/ranlib
# llvm-nm somehow doesn't work when compiling hyperscan's fat runtime
# ln -sf llvm-nm-${LLVM_VERSION} toolchain/bin/nm
ln -sf lldb-${LLVM_VERSION} toolchain/bin/lldb
ln -sf clang-tidy-${LLVM_VERSION} toolchain/bin/clang-tidy
ln -sf clang-format-${LLVM_VERSION} toolchain/bin/clang-format
ln -sf gcc toolchain/bin/cc
ln -sf g++ toolchain/bin/c++
mv toolchain/bin/lldb-server-${LLVM_VERSION} toolchain/bin/lldb-server-${LLVM_VERSION}.0.1
# ln -sf gcc-ranlib-11 toolchain/bin/ranlib
# ln -sf gcc-ar-11 toolchain/bin/ar
# ln -sf gcc-nm-11 toolchain/bin/nm
# gcc-ar-11
# gcc-nm-11
# gcc-ranlib-11
if [ "${ARCH}" = "x86_64" ]; then
cp -L /opt/exodus/bundles/*/usr/bin/linker-* toolchain/lib/ld-linux-x86-64.so.2
elif [ "${ARCH}" = "aarch64" ]; then
cp -L /opt/exodus/bundles/*/usr/bin/linker-* toolchain/lib/ld-linux-aarch64.so.1
else
echo "Unknown architecture: ${ARCH}"
exit 1
fi
tar xzf /opt/cmake-3.29.0-linux-${ARCH}.tar.gz --strip-components=1 --exclude='*/doc' --exclude='*/man' -C toolchain
# JDK and Maven are too large
# mkdir toolchain/apache-maven-3.8.4
# tar xzf /opt/apache-maven-3.8.4-bin.tar.gz --strip-components=1 -C toolchain/apache-maven-3.8.4
# mkdir toolchain/openjdk-11.0.2
# tar xzf /opt/openjdk-11.0.2_linux-x64_bin.tar.gz --strip-components=1 -C toolchain/openjdk-11.0.2
# Setup sysroot
mkdir -p toolchain/usr/lib
cp -r --parents /usr/include toolchain
# Python-3.6.6
cp -r --parents \
/usr/include/rpc \
/usr/include/rpcsvc \
/usr/include/${ARCH}-linux-gnu/sys/soundcard.h \
toolchain
# fdb client
if [ "${ARCH}" = "x86_64" ]; then
cp -r --parents /usr/include/foundationdb toolchain
# Require glibc >= 2.17
cp /usr/lib/libfdb_c.so toolchain/lib/
cp /usr/lib/cmake/FoundationDB-Client/* toolchain/
sed -i 's=${_IMPORT_PREFIX}/usr/lib/libfdb_c.so=${CMAKE_CURRENT_LIST_DIR}/lib/libfdb_c.so=' \
toolchain/FoundationDB-Client-release.cmake
fi
# Additional libs
cp -L \
/usr/lib/${ARCH}-linux-gnu/libiberty.a \
/usr/lib/${ARCH}-linux-gnu/libz.a \
/usr/lib/${ARCH}-linux-gnu/libbfd.a \
/usr/lib/${ARCH}-linux-gnu/libcrypt.a \
/usr/lib/${ARCH}-linux-gnu/libtinfo.a \
/usr/lib/${ARCH}-linux-gnu/libtic.a \
/usr/lib/${ARCH}-linux-gnu/libtermcap.a \
/usr/lib/${ARCH}-linux-gnu/libssl.a \
/usr/lib/${ARCH}-linux-gnu/libcrypto.a \
/usr/lib/${ARCH}-linux-gnu/libnsl.a \
toolchain/usr/lib/
# Additional libs usually don't provide stable abi.
# Let's also force static link
# TODO header files are incomplete. Also cmake might still find system libs instead
# for lib in libz libbfd libcrypt libtinfo libtic libssl libcrypto libnsl; do
# echo "OUTPUT_FORMAT(elf64-x86-64)
# GROUP ( ./$lib.a )
# " >toolchain/usr/lib/$lib.so
# done
# TODO ubuntu static libs are mostly compiled without -fPIC. Have to use .so for now.
# TODO Will it break anything? Perhaps we should only provide .a files
for lib in libz libbfd libcrypt libtinfo libtic libtermcap libssl libcrypto libnsl; do
cp -L /usr/lib/${ARCH}-linux-gnu/$lib.so toolchain/usr/lib/$lib.so
done
output_format=""
if [ "${ARCH}" = "x86_64" ]; then
output_format="x86-64"
elif [ "${ARCH}" = "aarch64" ]; then
output_format="littleaarch64"
else
echo "Unknown architecture: ${ARCH}"
exit 1
fi
if [ "${ARCH}" = "x86_64" ]; then
echo "/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf64-${output_format})
GROUP ( ./libglibc-compatibility.a ../../lib/libc.so.6 ./libc_nonshared.a AS_NEEDED ( ../../lib/ld-linux-x86-64.so.2 ) )
" >toolchain/usr/lib/libc.so
elif [ "${ARCH}" = "aarch64" ]; then
echo "/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf64-${output_format})
GROUP ( ./libglibc-compatibility.a ../../lib/libc.so.6 ./libc_nonshared.a AS_NEEDED ( ../../lib/ld-linux-aarch64.so.1 ) )
" >toolchain/usr/lib/libc.so
else
echo "Unknown architecture: ${ARCH}"
exit 1
fi
echo "/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf64-${output_format})
GROUP ( ../../lib/libpthread.so.0 ./libpthread_nonshared.a )
" >toolchain/usr/lib/libpthread.so
ln -s ../../lib/libdl.so.2 toolchain/usr/lib/libdl.so
echo "/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf64-${output_format})
GROUP ( ./libglibc-compatibility.a ../../lib/libm.so.6 )
" >toolchain/usr/lib/libm.so
ln -s ../../lib/libresolv.so.2 toolchain/usr/lib/libresolv.so
ln -s ../../lib/librt.so.1 toolchain/usr/lib/librt.so
cp -L /usr/lib/${ARCH}-linux-gnu/crt1.o toolchain/usr/lib/
cp -L /usr/lib/${ARCH}-linux-gnu/crti.o toolchain/usr/lib/
cp -L /usr/lib/${ARCH}-linux-gnu/crtn.o toolchain/usr/lib/
cp -L /usr/lib/${ARCH}-linux-gnu/libc_nonshared.a toolchain/usr/lib/
cp -L /usr/lib/${ARCH}-linux-gnu/libpthread_nonshared.a toolchain/usr/lib/
cp -L /usr/lib/${ARCH}-linux-gnu/Mcrt1.o toolchain/usr/lib/
cp -L /usr/lib/${ARCH}-linux-gnu/Scrt1.o toolchain/usr/lib/
cp -L /usr/lib/${ARCH}-linux-gnu/gcrt1.o toolchain/usr/lib/
if [ "${ARCH}" = "x86_64" ]; then
cp -L /usr/lib/${ARCH}-linux-gnu/grcrt1.o toolchain/usr/lib/
cp -L /usr/lib/${ARCH}-linux-gnu/rcrt1.o toolchain/usr/lib/
fi
# rust build requires this
cp -L /usr/lib/${ARCH}-linux-gnu/libutil.so toolchain/usr/lib/
cp -L /usr/lib/${ARCH}-linux-gnu/libutil.a toolchain/usr/lib/
# static build
cp -L /usr/lib/${ARCH}-linux-gnu/libc.a toolchain/usr/lib/
cp -L /usr/lib/${ARCH}-linux-gnu/libpthread.a toolchain/usr/lib/
cp -L /usr/lib/${ARCH}-linux-gnu/libdl.a toolchain/usr/lib/
cp -L /usr/lib/${ARCH}-linux-gnu/librt.a toolchain/usr/lib/
cp -L /usr/lib/${ARCH}-linux-gnu/libresolv.a toolchain/usr/lib/
cp -L /usr/lib/${ARCH}-linux-gnu/libffi.a toolchain/usr/lib/
cp -L /usr/lib/${ARCH}-linux-gnu/libffi_pic.a toolchain/usr/lib/
if [ "${ARCH}" = "x86_64" ]; then
echo "/* GNU ld script
*/
OUTPUT_FORMAT(elf64-${output_format})
GROUP ( ./libglibc-compatibility.a ./libm-2.27.a ./libmvec.a ./libpthread.a )
" >toolchain/usr/lib/libm.a
cp -L /usr/lib/${ARCH}-linux-gnu/libm-2.27.a toolchain/usr/lib/
cp -L /usr/lib/${ARCH}-linux-gnu/libmvec.a toolchain/usr/lib/
elif [ "${ARCH}" = "aarch64" ]; then
echo "/* GNU ld script
*/
OUTPUT_FORMAT(elf64-${output_format})
GROUP ( ./libglibc-compatibility.a ./libm-2.27.a ./libpthread.a )
" >toolchain/usr/lib/libm.a
cp -L /usr/lib/${ARCH}-linux-gnu/libm.a toolchain/usr/lib/libm-2.27.a
else
echo "Unknown architecture: ${ARCH}"
exit 1
fi
# We provide bison wrapper to make sure it picks up our m4 and pkg data
mv toolchain/bin/bison toolchain/bin/bison-3.5.1
# We provide curl wrapper to make sure curl can load runtime DSO from our lib
mv toolchain/bin/curl toolchain/bin/ldb-curl
cp -r /wrappers/* toolchain/bin/
sed -i "s/<GCC_VERSION>/$GCC_VERSION/" toolchain/bin/gcc
sed -i "s/<GCC_VERSION>/$GCC_VERSION/" toolchain/bin/g++
sed -i "s/<LLVM_VERSION>/$LLVM_VERSION/" toolchain/bin/clang
sed -i "s/<LLVM_VERSION>/$LLVM_VERSION/" toolchain/bin/clang++
sed -i "s/<LLVM_VERSION>/$LLVM_VERSION/" toolchain/bin/clangd
# Setup gcc toolchains
mkdir -p toolchain/libexec/gcc/${ARCH}-linux-gnu/${GCC_VERSION} toolchain/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}
for f in /opt/exodus/bundles/*/usr/libexec/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/*-x
do
p=$(basename $f)
g=${p::-2}
cp -L $f toolchain/libexec/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/$g
strip toolchain/libexec/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/$g
./patchelf --set-interpreter "$interpreter" --set-rpath '$ORIGIN/../../..' toolchain/libexec/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/$g
done
cp -r -L /usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/crtbegin.o \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/crtend.o \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/crtbeginT.o \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/crtbeginS.o \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/crtendS.o \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libgcc_eh.a \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libgcc.a \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libstdc++.a \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libstdc++fs.a \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libatomic.so \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libatomic.a \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/liblto_plugin.so \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libgcov.a \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libsanitizer.spec \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libasan_preinit.o \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libasan.a \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libasan.so \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libtsan.a \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libtsan.so \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libubsan.a \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libubsan.so \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/liblsan_preinit.o \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/liblsan.a \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/liblsan.so \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/include \
toolchain/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}
# gomp
cp -r -L \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/crtfastmath.o \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libgomp.a \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libgomp.so \
/usr/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libgomp.spec \
toolchain/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}
ln -s gcc/x86_64-linux-gnu/${GCC_VERSION}/libgomp.so toolchain/lib/libgomp.so.1
if [ "${ARCH}" = "x86_64" ]; then
cp -r -L \
/usr/lib/gcc/x86_64-linux-gnu/${GCC_VERSION}/crtprec32.o \
/usr/lib/gcc/x86_64-linux-gnu/${GCC_VERSION}/crtprec64.o \
/usr/lib/gcc/x86_64-linux-gnu/${GCC_VERSION}/crtprec80.o \
toolchain/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}
fi
for so in toolchain/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/*.so
do
./patchelf --set-rpath '$ORIGIN/../../..' "$so"
done
echo "/* GNU ld script
Use the shared library, but some functions are only in
the static library. */
GROUP ( ./libstdc++.a ./libstdc++fs.a )
" >toolchain/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libstdc++.so
echo "/* GNU ld script
Use the shared library, but some functions are only in
the static library. */
GROUP ( -lgcc -lgcc_eh )
" >toolchain/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libgcc_s.so
# Sometimes static linking might still link to libgcc_s. Use ld script to redirect.
echo "/* GNU ld script
Use the shared library, but some functions are only in
the static library. */
GROUP ( -lgcc -lgcc_eh )
" >toolchain/lib/gcc/${ARCH}-linux-gnu/${GCC_VERSION}/libgcc_s.a
mkdir -p toolchain/include/${ARCH}-linux-gnu/c++
mkdir -p toolchain/include/c++
cp -r /usr/include/${ARCH}-linux-gnu/c++/${GCC_VERSION} toolchain/include/${ARCH}-linux-gnu/c++/
cp -r /usr/include/c++/${GCC_VERSION} toolchain/include/c++/
# Setup clang resource includes
mkdir -p toolchain/lib/clang
cp -r -L /usr/lib/llvm-${LLVM_VERSION}/lib/clang/${LLVM_VERSION} toolchain/lib/clang/
# cp -r -L /usr/lib/clang/${LLVM_VERSION_FULL} toolchain/lib/clang/${LLVM_VERSION_FULL}
# for so in toolchain/lib/clang/${LLVM_VERSION_FULL}/lib/linux/*.so
# do
# ./patchelf --set-rpath '$ORIGIN/../../../..' "$so"
# done
# libc++
cp -r /usr/lib/llvm-${LLVM_VERSION}/include/c++/v1 toolchain/include/c++/
cp -L \
/usr/lib/llvm-${LLVM_VERSION}/lib/libunwind.so \
/usr/lib/llvm-${LLVM_VERSION}/lib/libc++abi.so \
/usr/lib/llvm-${LLVM_VERSION}/lib/libc++.so.1 \
/usr/lib/llvm-${LLVM_VERSION}/lib/libunwind.a \
/usr/lib/llvm-${LLVM_VERSION}/lib/libc++.a \
/usr/lib/llvm-${LLVM_VERSION}/lib/libc++experimental.a \
/usr/lib/llvm-${LLVM_VERSION}/lib/libc++abi.a \
toolchain/lib/
./patchelf --set-rpath '$ORIGIN' toolchain/lib/libc++.so.1
./patchelf --set-rpath '$ORIGIN' toolchain/lib/libc++abi.so
./patchelf --set-rpath '$ORIGIN' toolchain/lib/libunwind.so
echo "INPUT(./libc++.so.1 -lunwind -lc++abi)" >toolchain/lib/libc++.so
# For cmake file DOWNLOAD support
./patchelf --add-needed libnss_files.so.2 --add-needed libnss_dns.so.2 toolchain/bin/cmake
cp ./patchelf toolchain/bin/
cp -r /tests toolchain/test
mv toolchain/bin/python3 toolchain/bin/ldb-python3
cp -r /usr/lib/python3.6 toolchain/lib/
cp -r /usr/share/gdb toolchain/share/
# printers for gcc
cp -r /usr/share/gcc toolchain/share/gdb/
# printers for clang
mkdir -p toolchain/share/gdb/libcxx
cp /opt/printers.py toolchain/share/gdb/libcxx/
cp /usr/bin/gdb-add-index toolchain/bin/
cp /usr/bin/google-pprof toolchain/bin/pprof
cp -r /usr/share/bison toolchain/share/
cp -r /usr/share/aclocal toolchain/share/
(
cd /glibc-compatibility
mkdir -p build
cd build
/data/toolchain/bin/cmake ..
make
/data/toolchain/bin/ar x libglibc-compatibility.a
/data/toolchain/bin/ld -relocatable ./*.o -o glibc-compatibility.o
) &> /dev/null
cp /glibc-compatibility/build/libglibc-compatibility.a /glibc-compatibility/build/glibc-compatibility.o toolchain/usr/lib/
tar czf toolchain.tgz toolchain
sed -i "s/\${ARCH}/$ARCH/g" /setup_toolchain.sh
sed -i "s/\${GCC_VERSION}/$GCC_VERSION/g" /setup_toolchain.sh
sed -i "s/\${LLVM_VERSION}/$LLVM_VERSION/g" /setup_toolchain.sh
cat /setup_toolchain.sh toolchain.tgz > ldb_toolchain_gen.sh
chmod +x ldb_toolchain_gen.sh