OLD | NEW |
1 #!/bin/sh | 1 #!/bin/sh |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # Script to build binutils found in /build/binutils-XXXX when inside a chroot. | 6 # Script to build binutils found in /build/binutils-XXXX when inside a chroot. |
7 # Don't call this script yourself, instead use the build-all.sh script. | 7 # Don't call this script yourself, instead use the build-all.sh script. |
8 | 8 |
9 set -e | 9 set -e |
10 set -x | 10 set -x |
11 | 11 |
12 if [ -z "$1" ]; then | 12 if [ -z "$1" ]; then |
13 echo "Directory of binutils not given." | 13 echo "Directory of binutils not given." |
14 exit 1 | 14 exit 1 |
15 fi | 15 fi |
16 | 16 |
17 cd "$1" | 17 cd "$1" |
18 | |
19 # First, we need to build libtcmalloc_minimal | |
20 | |
21 cd ../gperftools/ | |
22 ./autogen.sh | |
23 ./configure \ | |
24 --disable-cpu-profiler \ | |
25 --disable-heap-checker \ | |
26 --disable-heap-profiler \ | |
27 --disable-static \ | |
28 --enable-minimal | |
29 | |
30 echo | |
31 echo "= gperftools src/config.h ==========================================" | |
32 cat src/config.h | |
33 echo "====================================================================" | |
34 echo | |
35 | |
36 make -j8 | |
37 | |
38 cd "$1" | |
39 | |
40 # Ask the dynamic loader to load libstdc++ from the LLVM build directory if | |
41 # available. That copy of libstdc++ is required by the gold plugin in the same | |
42 # directory. Do the same for libtcmalloc_minimal, that is stored in ../lib. | |
43 # The dynamic loader expects the relative path to start with $ORIGIN, | |
44 # but because of escaping issues | |
45 # (https://sourceware.org/ml/binutils/2009-05/msg00252.html) | |
46 # we embed a dummy path with $ replaced with z and fix it up later. | |
47 | |
48 readonly LIBSTDCPP_RPATH="zORIGIN/../../../../llvm-build/Release+Asserts/lib" | |
49 readonly LIBTCMALLOC_RPATH="zORIGIN/../lib" | |
50 export LDFLAGS="-Wl,-rpath,$LIBSTDCPP_RPATH:$LIBTCMALLOC_RPATH \ | |
51 -L$(pwd)/../gperftools/.libs/" | |
52 export LIBS='-ltcmalloc_minimal' | |
53 | |
54 ./configure \ | 18 ./configure \ |
55 --enable-deterministic-archives \ | 19 --enable-deterministic-archives \ |
56 --enable-gold=default \ | 20 --enable-gold=default \ |
57 --enable-plugins \ | 21 --enable-plugins \ |
58 --enable-threads \ | 22 --enable-threads \ |
59 --prefix=/build/output | 23 --prefix=/build/output |
60 | 24 |
61 | 25 |
62 make -j8 all | 26 make -j8 all |
63 echo | 27 echo |
64 echo "= binutils/config.h ================================================" | 28 echo "= binutils/config.h ================================================" |
65 cat binutils/config.h | 29 cat binutils/config.h |
66 echo "====================================================================" | 30 echo "====================================================================" |
67 echo | 31 echo |
68 make install | 32 make install |
69 | |
70 # Copy libtcmalloc_minimal library and symlinks to the install lib dir. | |
71 cp -a ../gperftools/.libs/libtcmalloc_minimal.so* /build/output/*/lib/ | |
72 | |
73 # Save the list of binaries. The sed -i command will leave .orig files behind. | |
74 # We don't want them to appear in the for loop below. | |
75 bins="$(echo /build/output/*/bin/*)" | |
76 | |
77 # Fix up zORIGIN -> $ORIGIN. | |
78 sed -i.orig 's,zORIGIN,$ORIGIN,g' $bins | |
79 | |
80 # Verify that we changed only two bytes per executable. | |
81 for bin in $bins; do | |
82 test "`cmp -l $bin.orig $bin | wc -l`" = 2 || \ | |
83 (echo "$bin: verification failed" && exit 1) | |
84 done | |
85 | |
86 rm /build/output/*/bin/*.orig | |
OLD | NEW |