OLD | NEW |
1 #!/bin/sh | 1 #!/bin/sh |
2 | 2 |
3 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # Script to build valgrind for use with chromium | 7 # Script to build valgrind binaries for use with chromium |
8 # | |
9 # Can also be used to just prepare patched source tarball with MAKE_TARBALL=yes | |
10 # or to just build from a patched source tarball with USE_TARBALL=yes. | |
11 # These are useful when configuring jailed buildbots which are not allowed to | |
12 # fetch valgrind source via svn. Most users won't need those options. | |
13 | |
14 # Checkout by date doesn't work unless you specify the friggin' timezone | |
15 VALGRIND_SVN_REV=10880 | |
16 # And svn isn't smart enough to figure out what rev of the linked tree to get | |
17 VEX_SVN_REV=1914 | |
18 # and TSAN may be out of sync, so you have to check that out by rev anyway | |
19 TSAN_SVN_REV=1274 | |
20 | |
21 # suffix for build and install dir to denote our set of patches (may be empty) | |
22 PATCHLEVEL=-redzone | |
23 | |
24 DIRNAME=valgrind-${VALGRIND_SVN_REV}${PATCHLEVEL} | |
25 | 8 |
26 THISDIR=$(dirname "${0}") | 9 THISDIR=$(dirname "${0}") |
27 THISDIR=$(cd "${THISDIR}" && /bin/pwd) | 10 THISDIR=$(cd "${THISDIR}" && /bin/pwd) |
28 | 11 |
29 case "x${1}" in | 12 checkout_and_patch_valgrind() { |
30 x|x/*) ;; | 13 # {{{1 |
31 *) | 14 # Checkout Valgrind and ThreadSanitizer, apply our patches to Valgrind. |
32 echo "Usage: sh build-valgrind-for-chromium.sh [prefix]" | 15 # The source will be put in $THISDIR/valgrind-source |
33 echo "Prefix is optional, but if present, must be the absolute path to where" | 16 cd $THISDIR |
34 echo "you want to install valgrind's bin, include, and lib directories." | 17 VALGRIND_SOURCE="$THISDIR/valgrind-source" |
35 echo "Prefix defaults to /usr/local/$DIRNAME." | |
36 echo "Will use sudo to do the install if you don't own the parent of prefix." | |
37 exit 1 | |
38 ;; | |
39 esac | |
40 | 18 |
41 set -x | 19 # Checkout by date doesn't work unless you specify the friggin' timezone |
42 set -e | 20 # and svn isn't smart enough to figure out what rev of VEX to get |
| 21 # and TSAN may be out of sync, so you have to check that out by rev anyway. |
| 22 VALGRIND_SVN_REV=10880 |
| 23 VEX_SVN_REV=1914 |
| 24 TSAN_SVN_REV=1274 |
43 | 25 |
44 if test "x${USE_TARBALL}" = "xyes" && test "x${MAKE_TARBALL}" = "xyes" | 26 test -d "$VALGRIND_SOURCE" && rm -rf "$VALGRIND_SOURCE" |
45 then | 27 mkdir "$VALGRIND_SOURCE" |
46 echo Set only one of MAKE_TARBALL or USE_TARBALL to yes | |
47 exit 1 | |
48 fi | |
49 | 28 |
50 # Clean checkout our untar | |
51 test -d "$DIRNAME" && rm -rf ./"$DIRNAME" | |
52 mkdir -p "$DIRNAME" | |
53 | |
54 if test "x${USE_TARBALL}" != "xyes" | |
55 then | |
56 # Check out latest version that following patches known to apply against | 29 # Check out latest version that following patches known to apply against |
57 svn co -r "${VALGRIND_SVN_REV}" "svn://svn.valgrind.org/valgrind/trunk" "$DIRN
AME" | 30 svn co -r "${VALGRIND_SVN_REV}" "svn://svn.valgrind.org/valgrind/trunk" "$VALG
RIND_SOURCE" |
58 | 31 cd "$VALGRIND_SOURCE" |
59 cd "$DIRNAME" | |
60 | |
61 # Make sure svn gets the right version of the external VEX repo, too | 32 # Make sure svn gets the right version of the external VEX repo, too |
62 svn update -r "${VEX_SVN_REV}" VEX/ | 33 svn update -r "${VEX_SVN_REV}" VEX/ |
63 | 34 |
| 35 # Apply patches to Valgrind {{{2 |
64 # Work around bug https://bugs.kde.org/show_bug.cgi?id=162848 | 36 # Work around bug https://bugs.kde.org/show_bug.cgi?id=162848 |
65 # "fork() not handled properly" | 37 # "fork() not handled properly" |
66 patch -p0 < "${THISDIR}/fork.patch" | 38 patch -p0 < "${THISDIR}/fork.patch" |
67 | 39 |
68 # Add feature bug https://bugs.kde.org/show_bug.cgi?id=201170 | 40 # Add feature bug https://bugs.kde.org/show_bug.cgi?id=201170 |
69 # "Want --show-possible option so I can ignore the bazillion possible leaks...
" | 41 # "Want --show-possible option so I can ignore the bazillion possible leaks...
" |
70 patch -p0 < "${THISDIR}/possible.patch" | 42 patch -p0 < "${THISDIR}/possible.patch" |
71 | 43 |
72 # Add feature bug https://bugs.kde.org/show_bug.cgi?id=205000 | 44 # Add feature bug https://bugs.kde.org/show_bug.cgi?id=205000 |
73 # "Need library load address in log files" | 45 # "Need library load address in log files" |
74 patch -p0 < "${THISDIR}/xml-loadadr.patch" | 46 patch -p0 < "${THISDIR}/xml-loadadr.patch" |
75 | 47 |
76 # Make red zone 64 bytes bigger to catch more buffer overruns | 48 # Make red zone 64 bytes bigger to catch more buffer overruns |
77 patch -p0 < "${THISDIR}/redzone.patch" | 49 patch -p0 < "${THISDIR}/redzone.patch" |
78 | 50 |
79 # Fix/work around https://bugs.kde.org/show_bug.cgi?id=210481 | 51 # Fix/work around https://bugs.kde.org/show_bug.cgi?id=210481 |
80 # which prevented valgrind from handling v8 on 64 bits | 52 # which prevented valgrind from handling v8 on 64 bits |
81 patch -p0 < "${THISDIR}/vbug210481.patch" | 53 patch -p0 < "${THISDIR}/vbug210481.patch" |
82 | 54 |
83 # Fix/work around https://bugs.kde.org/show_bug.cgi?id=205541 | 55 # Fix/work around https://bugs.kde.org/show_bug.cgi?id=205541 |
84 # which prevented valgrind from handling wine | 56 # which prevented valgrind from handling wine |
85 patch -p0 < "${THISDIR}/vbug205541.patch" | 57 patch -p0 < "${THISDIR}/vbug205541.patch" |
86 | 58 |
87 # Add intercepts for tcmalloc memory functions. | 59 # Add intercepts for tcmalloc memory functions. |
88 # The corresponding feature request for Valgrind is at | 60 # The corresponding feature request for Valgrind is at |
89 # https://bugs.kde.org/show_bug.cgi?id=219156. | 61 # https://bugs.kde.org/show_bug.cgi?id=219156. |
90 patch -p0 < "${THISDIR}/intercept_tcmalloc.patch" | 62 patch -p0 < "${THISDIR}/intercept_tcmalloc.patch" |
| 63 # }}} |
91 | 64 |
| 65 # Add ThreadSanitier to the installation. |
| 66 # ThreadSanitizer is an experimental dynamic data race detector. |
| 67 # See http://code.google.com/p/data-race-test/wiki/ThreadSanitizer |
| 68 svn checkout -r "${TSAN_SVN_REV}" http://data-race-test.googlecode.com/svn/tru
nk/tsan tsan |
| 69 mkdir tsan/tests |
| 70 touch tsan/tests/Makefile.am |
| 71 patch -p0 < tsan/valgrind.patch |
| 72 # }}} |
| 73 } |
92 | 74 |
93 if [ "${INSTALL_TSAN}" = "yes" ] | 75 build_valgrind() { |
94 then | 76 # $1 = platform name to build; also, the name of the output subdirectory. |
95 # Add ThreadSanitier to the installation. | 77 # $2 = flags to pass to configure |
96 # ThreadSanitizer is an experimental dynamic data race detector. | 78 # {{{1 |
97 # See http://code.google.com/p/data-race-test/wiki/ThreadSanitizer | 79 PLATFORM=$1 |
98 svn checkout -r "${TSAN_SVN_REV}" http://data-race-test.googlecode.com/svn/t
runk/tsan tsan | 80 CONFIGURE_FLAGS=$2 |
99 mkdir tsan/tests | 81 |
100 touch tsan/tests/Makefile.am | 82 # Output directory for valgrind's bin, include, etc. |
101 patch -p 0 < tsan/valgrind.patch | 83 OUTPUT_DIR="$BINARIES_DIR/$PLATFORM" |
102 fi | 84 |
| 85 cd "$VALGRIND_SOURCE" |
| 86 # Wipe out all Makefiles which could be left by the previous installation. |
| 87 make distclean || true |
103 | 88 |
104 sh autogen.sh | 89 sh autogen.sh |
105 if test -L install-sh | 90 if test -L install-sh |
106 then | 91 then |
107 # replace symlink with actual contents! | 92 # replace symlink with actual contents! |
108 cp install-sh install-sh.new | 93 cp install-sh install-sh.new |
109 mv -f install-sh.new install-sh | 94 mv -f install-sh.new install-sh |
110 chmod +x install-sh | 95 chmod +x install-sh |
111 fi | 96 fi |
112 | 97 |
113 # MacOSX before Snow Leopoard needs newer gdb to be able to handle -O1 chrome | 98 # If gold is installed as a linker, use the old one |
114 # Kludgily download and unpack the sources in a subdirectory. | |
115 if test `uname` = Darwin || test "x${MAKE_TARBALL}" = "xyes" | |
116 then | |
117 curl http://www.opensource.apple.com/tarballs/gdb/gdb-1344.tar.gz | tar -xzf
- | |
118 fi | |
119 cd .. | |
120 | |
121 fi | |
122 | |
123 if test "x${MAKE_TARBALL}" = "xyes" | |
124 then | |
125 tar -czvf "$DIRNAME".tgz "$DIRNAME" | |
126 fi | |
127 | |
128 if test "x${USE_TARBALL}" = "xyes" | |
129 then | |
130 tar -xzvf "$DIRNAME".tgz | |
131 fi | |
132 | |
133 if test "x${MAKE_TARBALL}" != "xyes" | |
134 then | |
135 cd "$DIRNAME" | |
136 | |
137 OVERRIDE_LD_DIR="${THISDIR}/override_ld" | 99 OVERRIDE_LD_DIR="${THISDIR}/override_ld" |
138 if ld --version | grep gold | 100 if ld --version | grep gold |
139 then | 101 then |
140 # build/install-build-deps leaves original ld around, try using that | 102 # build/install-build-deps leaves original ld around, try using that |
141 if test -x /usr/bin/ld.orig | 103 if test -x /usr/bin/ld.orig |
142 then | 104 then |
143 echo "Using /usr/bin/ld.orig instead of gold to link valgrind" | 105 echo "Using /usr/bin/ld.orig instead of gold to link valgrind" |
144 test -d "${OVERRIDE_LD_DIR}" && rm -rf "${OVERRIDE_LD_DIR}" | 106 test -d "${OVERRIDE_LD_DIR}" && rm -rf "${OVERRIDE_LD_DIR}" |
145 mkdir "${OVERRIDE_LD_DIR}" | 107 mkdir "${OVERRIDE_LD_DIR}" |
146 ln -s /usr/bin/ld.orig "${OVERRIDE_LD_DIR}/ld" | 108 ln -s /usr/bin/ld.orig "${OVERRIDE_LD_DIR}/ld" |
147 PATH="${OVERRIDE_LD_DIR}:${PATH}" | 109 PATH="${OVERRIDE_LD_DIR}:${PATH}" |
148 # Ubuntu diverts original ld to ld.single when it installs binutils-gold | 110 # Ubuntu diverts original ld to ld.single when it installs binutils-gold |
149 elif test -x /usr/bin/ld.single | 111 elif test -x /usr/bin/ld.single |
150 then | 112 then |
151 echo "Using /usr/bin/ld.single instead of gold to link valgrind" | 113 echo "Using /usr/bin/ld.single instead of gold to link valgrind" |
152 test -d "${OVERRIDE_LD_DIR}" && rm -rf "${OVERRIDE_LD_DIR}" | 114 test -d "${OVERRIDE_LD_DIR}" && rm -rf "${OVERRIDE_LD_DIR}" |
153 mkdir "${OVERRIDE_LD_DIR}" | 115 mkdir "${OVERRIDE_LD_DIR}" |
154 ln -s /usr/bin/ld.single "${OVERRIDE_LD_DIR}/ld" | 116 ln -s /usr/bin/ld.single "${OVERRIDE_LD_DIR}/ld" |
155 PATH="${OVERRIDE_LD_DIR}:${PATH}" | 117 PATH="${OVERRIDE_LD_DIR}:${PATH}" |
156 else | 118 else |
157 echo "Cannot build valgrind with gold. Please switch to normal /usr/bin/l
d, rerun this script, then switch back to gold." | 119 echo "Cannot build valgrind with gold. Please switch to normal /usr/bin/l
d, rerun this script, then switch back to gold." |
158 exit 1 | 120 exit 1 |
159 fi | 121 fi |
160 fi | 122 fi |
161 | 123 |
162 # Desired parent directory for valgrind's bin, include, etc. | 124 ./configure $CONFIGURE_FLAGS --prefix="${OUTPUT_DIR}" |
163 PREFIX="${1:-/usr/local/$DIRNAME}" | 125 make -j4 |
164 parent_of_prefix=$(dirname "${PREFIX}") | 126 |
165 if test ! -d "${parent_of_prefix}" | 127 # Test if Valgrind binary works on a simple program {{{2 |
| 128 cat > simpletest.c <<EOF |
| 129 #include <stdio.h> |
| 130 int main(void) { |
| 131 printf("OK\n"); |
| 132 return 0; |
| 133 } |
| 134 EOF |
| 135 if echo "$CONFIGURE_FLAGS" | grep "\-\-enable\-only32bit"; |
166 then | 136 then |
167 echo "Directory ${parent_of_prefix} does not exist" | 137 gcc -m32 simpletest.c -o simpletest |
168 exit 1 | 138 else |
| 139 gcc simpletest.c -o simpletest |
169 fi | 140 fi |
170 | 141 |
171 ./configure --prefix="${PREFIX}" | 142 if ! ./vg-in-place ./simpletest |
172 make -j4 | |
173 | |
174 if ./vg-in-place true | |
175 then | 143 then |
176 echo built valgrind passes smoke test, good | |
177 else | |
178 echo built valgrind fails smoke test | 144 echo built valgrind fails smoke test |
179 exit 1 | 145 exit 1 |
180 fi | 146 fi |
| 147 # }}} |
181 | 148 |
182 test -d "${OVERRIDE_LD_DIR}" && rm -rf "${OVERRIDE_LD_DIR}" | 149 test -d "${OVERRIDE_LD_DIR}" && rm -rf "${OVERRIDE_LD_DIR}" |
183 | 150 |
184 # Build and install gdb if needed | 151 # Finally install valgrind to $OUTPUT_DIR. |
185 case `uname` in | 152 make install |
186 Darwin) | 153 |
| 154 if [ "$CONFIGURE_FLAGS" == "" ] ; then |
| 155 ln -s "$OUTPUT_DIR" "$BINARIES_DIR/local" |
| 156 fi |
| 157 |
| 158 maybe_build_gdb_for_mac "$OUTPUT_DIR" |
| 159 |
| 160 # We're done |
| 161 cd $THISDIR |
| 162 # }}} |
| 163 } |
| 164 |
| 165 maybe_build_gdb_for_mac() { |
| 166 # MacOSX before Snow Leopoard needs newer gdb to be able to handle -O1 chrome |
| 167 # Kludgily download and unpack the sources in a subdirectory, |
| 168 # then install into $1. |
| 169 # This is SLOW and we want it to run only once, so we execute it only |
| 170 # if explicitly asked to do so. |
| 171 if [ "${BUILD_GDB}" = "yes" ] |
| 172 then |
| 173 curl http://www.opensource.apple.com/tarballs/gdb/gdb-1344.tar.gz | tar -xzf
- |
187 cd gdb-1344/src | 174 cd gdb-1344/src |
188 ./configure --prefix="${PREFIX}" | 175 ./configure --prefix="$1" |
189 # gdb makefile is not yet parallel-safe | 176 # gdb makefile is not yet parallel-safe |
190 make | 177 make |
191 if test -w "${parent_of_prefix}" | 178 make install |
192 then | 179 cd ../.. |
193 make install | 180 fi |
| 181 } |
| 182 |
| 183 # Check that the binaries directory exists. |
| 184 BINARIES_DIR="$THISDIR/../binaries" |
| 185 if ! [ -a $BINARIES_DIR ] |
| 186 then |
| 187 echo "Error: $BINARIES_DIR doesn't exist!" |
| 188 exit 1 |
| 189 fi |
| 190 |
| 191 set -x |
| 192 set -e |
| 193 |
| 194 checkout_and_patch_valgrind |
| 195 |
| 196 rm -rf $BINARIES_DIR/local |
| 197 |
| 198 # See "*" case for the description of the command-line argument. |
| 199 case `uname -sm` in |
| 200 "Linux x86_64") |
| 201 # We can build both 64/32-bit and 32-bit Valgrinds |
| 202 build_valgrind "linux_x64" |
| 203 build_valgrind "linux_x86" "--enable-only32bit" |
| 204 ;; |
| 205 "Linux x86") |
| 206 build_valgrind "linux_x86" |
| 207 ;; |
| 208 "Darwin i386") |
| 209 if [ `uname -r` != "9.7.0" ]; then |
| 210 echo "You have Darwin kernel different than 9.7.0" |
| 211 echo "We've tested binaries built on 9.7.0 to work with 9.6.1, 9.7.0 and 9
.8.0" |
| 212 build_valgrind "local" |
194 else | 213 else |
195 sudo make install | 214 build_valgrind "mac" |
196 fi | 215 fi |
197 cd ../.. | 216 ;; |
198 ;; | 217 *) |
199 esac | 218 build_valgrind "local" |
200 | 219 ;; |
201 # Finally install valgrind. | 220 esac |
202 # Don't use sudo if we own the destination | |
203 if test -w "${parent_of_prefix}" | |
204 then | |
205 make install | |
206 else | |
207 sudo make install | |
208 fi | |
209 | |
210 cd .. | |
211 fi | |
OLD | NEW |