| #!/bin/sh |
| |
| # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # Script to build valgrind binaries for use with chromium |
| |
| THISDIR=$(dirname "${0}") |
| THISDIR=$(cd "${THISDIR}" && /bin/pwd) |
| |
| checkout_and_patch_valgrind() { |
| # {{{1 |
| # Checkout Valgrind and ThreadSanitizer, apply our patches to Valgrind. |
| # The source will be put in $THISDIR/valgrind-source |
| cd $THISDIR |
| VALGRIND_SOURCE="$THISDIR/valgrind-source" |
| |
| # Checkout by date doesn't work unless you specify the friggin' timezone |
| # and svn isn't smart enough to figure out what rev of VEX to get |
| # and TSAN may be out of sync, so you have to check that out by rev anyway. |
| VALGRIND_SVN_REV=10880 |
| VEX_SVN_REV=1914 |
| TSAN_SVN_REV=1274 |
| |
| test -d "$VALGRIND_SOURCE" && rm -rf "$VALGRIND_SOURCE" |
| mkdir "$VALGRIND_SOURCE" |
| |
| # Check out latest version that following patches known to apply against |
| svn co -r "${VALGRIND_SVN_REV}" "svn://svn.valgrind.org/valgrind/trunk" "$VALGRIND_SOURCE" |
| cd "$VALGRIND_SOURCE" |
| # Make sure svn gets the right version of the external VEX repo, too |
| svn update -r "${VEX_SVN_REV}" VEX/ |
| |
| # Apply patches to Valgrind {{{2 |
| # Work around bug https://bugs.kde.org/show_bug.cgi?id=162848 |
| # "fork() not handled properly" |
| patch -p0 < "${THISDIR}/fork.patch" |
| |
| # Add feature bug https://bugs.kde.org/show_bug.cgi?id=201170 |
| # "Want --show-possible option so I can ignore the bazillion possible leaks..." |
| patch -p0 < "${THISDIR}/possible.patch" |
| |
| # Add feature bug https://bugs.kde.org/show_bug.cgi?id=205000 |
| # "Need library load address in log files" |
| patch -p0 < "${THISDIR}/xml-loadadr.patch" |
| |
| # Make red zone 64 bytes bigger to catch more buffer overruns |
| patch -p0 < "${THISDIR}/redzone.patch" |
| |
| # Fix/work around https://bugs.kde.org/show_bug.cgi?id=210481 |
| # which prevented valgrind from handling v8 on 64 bits |
| patch -p0 < "${THISDIR}/vbug210481.patch" |
| |
| # Fix/work around https://bugs.kde.org/show_bug.cgi?id=205541 |
| # which prevented valgrind from handling wine |
| patch -p0 < "${THISDIR}/vbug205541.patch" |
| |
| # Add intercepts for tcmalloc memory functions. |
| # The corresponding feature request for Valgrind is at |
| # https://bugs.kde.org/show_bug.cgi?id=219156. |
| patch -p0 < "${THISDIR}/intercept_tcmalloc.patch" |
| # }}} |
| |
| # Add ThreadSanitier to the installation. |
| # ThreadSanitizer is an experimental dynamic data race detector. |
| # See http://code.google.com/p/data-race-test/wiki/ThreadSanitizer |
| svn checkout -r "${TSAN_SVN_REV}" http://data-race-test.googlecode.com/svn/trunk/tsan tsan |
| mkdir tsan/tests |
| touch tsan/tests/Makefile.am |
| patch -p0 < tsan/valgrind.patch |
| # }}} |
| } |
| |
| build_valgrind() { |
| # $1 = platform name to build; also, the name of the output subdirectory. |
| # $2 = flags to pass to configure |
| # {{{1 |
| PLATFORM=$1 |
| CONFIGURE_FLAGS=$2 |
| |
| # Output directory for valgrind's bin, include, etc. |
| OUTPUT_DIR="$BINARIES_DIR/$PLATFORM" |
| |
| cd "$VALGRIND_SOURCE" |
| # Wipe out all Makefiles which could be left by the previous installation. |
| make distclean || true |
| |
| sh autogen.sh |
| if test -L install-sh |
| then |
| # replace symlink with actual contents! |
| cp install-sh install-sh.new |
| mv -f install-sh.new install-sh |
| chmod +x install-sh |
| fi |
| |
| # If gold is installed as a linker, use the old one |
| OVERRIDE_LD_DIR="${THISDIR}/override_ld" |
| if ld --version | grep gold |
| then |
| # build/install-build-deps leaves original ld around, try using that |
| if test -x /usr/bin/ld.orig |
| then |
| echo "Using /usr/bin/ld.orig instead of gold to link valgrind" |
| test -d "${OVERRIDE_LD_DIR}" && rm -rf "${OVERRIDE_LD_DIR}" |
| mkdir "${OVERRIDE_LD_DIR}" |
| ln -s /usr/bin/ld.orig "${OVERRIDE_LD_DIR}/ld" |
| PATH="${OVERRIDE_LD_DIR}:${PATH}" |
| # Ubuntu diverts original ld to ld.single when it installs binutils-gold |
| elif test -x /usr/bin/ld.single |
| then |
| echo "Using /usr/bin/ld.single instead of gold to link valgrind" |
| test -d "${OVERRIDE_LD_DIR}" && rm -rf "${OVERRIDE_LD_DIR}" |
| mkdir "${OVERRIDE_LD_DIR}" |
| ln -s /usr/bin/ld.single "${OVERRIDE_LD_DIR}/ld" |
| PATH="${OVERRIDE_LD_DIR}:${PATH}" |
| else |
| echo "Cannot build valgrind with gold. Please switch to normal /usr/bin/ld, rerun this script, then switch back to gold." |
| exit 1 |
| fi |
| fi |
| |
| ./configure $CONFIGURE_FLAGS --prefix="${OUTPUT_DIR}" |
| make -j4 |
| |
| # Test if Valgrind binary works on a simple program {{{2 |
| cat > simpletest.c <<EOF |
| #include <stdio.h> |
| int main(void) { |
| printf("OK\n"); |
| return 0; |
| } |
| EOF |
| if echo "$CONFIGURE_FLAGS" | grep "\-\-enable\-only32bit"; |
| then |
| gcc -m32 simpletest.c -o simpletest |
| else |
| gcc simpletest.c -o simpletest |
| fi |
| |
| if ! ./vg-in-place ./simpletest |
| then |
| echo built valgrind fails smoke test |
| exit 1 |
| fi |
| # }}} |
| |
| test -d "${OVERRIDE_LD_DIR}" && rm -rf "${OVERRIDE_LD_DIR}" |
| |
| # Finally install valgrind to $OUTPUT_DIR. |
| make install |
| |
| if [ "$CONFIGURE_FLAGS" == "" ] ; then |
| ln -s "$OUTPUT_DIR" "$BINARIES_DIR/local" |
| fi |
| |
| maybe_build_gdb_for_mac "$OUTPUT_DIR" |
| |
| # Delete un-needed stuff from the $OUTPUT_DIR |
| # TODO(timurrrr): probably, we should just don't build the unused tools |
| cd $OUTPUT_DIR |
| rm -rf include |
| rm -rf lib/pkgconfig lib/*.a |
| rm bin/*cg_* bin/callgrind* |
| cd lib/valgrind |
| rm -rf *.a \ |
| *drd* \ |
| *exp-* \ |
| *none* \ |
| *lackey* \ |
| *massif* \ |
| *helgrind* \ |
| *callgrind* \ |
| *cachegrind* |
| |
| # Strip all binaries except "vgpreload" (we do need their symbols). |
| strip `ls -1 | grep "tsan\|memcheck" | grep -v "dSYM" | grep -v "vgpreload"` |
| |
| # We're done |
| cd $THISDIR |
| # }}} |
| } |
| |
| maybe_build_gdb_for_mac() { |
| # MacOSX before Snow Leopoard needs newer gdb to be able to handle -O1 chrome |
| # Kludgily download and unpack the sources in a subdirectory, |
| # then install into $1. |
| # This is SLOW and we want it to run only once, so we execute it only |
| # if explicitly asked to do so. |
| if [ "${BUILD_GDB}" = "yes" ] |
| then |
| curl http://www.opensource.apple.com/tarballs/gdb/gdb-1344.tar.gz | tar -xzf - |
| cd gdb-1344/src |
| ./configure --prefix="$1" |
| # gdb makefile is not yet parallel-safe |
| make |
| make install |
| cd ../.. |
| fi |
| } |
| |
| # Check that the binaries directory exists. |
| BINARIES_DIR="$THISDIR/../binaries" |
| if ! [ -a $BINARIES_DIR ] |
| then |
| echo "Error: $BINARIES_DIR doesn't exist!" |
| exit 1 |
| fi |
| |
| set -x |
| set -e |
| |
| checkout_and_patch_valgrind |
| |
| rm -rf $BINARIES_DIR/local |
| |
| # See "*" case for the description of the command-line argument. |
| case `uname -sm` in |
| "Linux x86_64") |
| # We can build both 64/32-bit and 32-bit Valgrinds |
| build_valgrind "linux_x64" |
| build_valgrind "linux_x86" "--enable-only32bit" |
| ;; |
| "Linux x86") |
| build_valgrind "linux_x86" |
| ;; |
| "Darwin i386") |
| if [ `uname -r` != "9.7.0" ]; then |
| echo "You have Darwin kernel different than 9.7.0" |
| echo "We've tested binaries built on 9.7.0 to work with 9.6.1, 9.7.0 and 9.8.0" |
| build_valgrind "local" |
| else |
| build_valgrind "mac" |
| fi |
| ;; |
| *) |
| build_valgrind "local" |
| ;; |
| esac |