summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorglider@chromium.org <glider@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-11 15:30:18 +0000
committerglider@chromium.org <glider@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-11 15:30:18 +0000
commitb9ff654d9d0e16a0e74ed7b164dedd6401e342c8 (patch)
tree46067d7b226b0d775145bcb00f5c63950bf206d7 /build
parent77070f6d755000e181f63ff2febee5b220737c59 (diff)
downloadchromium_src-b9ff654d9d0e16a0e74ed7b164dedd6401e342c8.zip
chromium_src-b9ff654d9d0e16a0e74ed7b164dedd6401e342c8.tar.gz
chromium_src-b9ff654d9d0e16a0e74ed7b164dedd6401e342c8.tar.bz2
Add a postbuild action for executables built with ASan on Mac OS.
The action will copy the ASan dynamic runtime to the same dir where the executable is. BUG=170629 Review URL: https://codereview.chromium.org/11642018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187297 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build')
-rw-r--r--build/all.gyp1
-rw-r--r--build/common.gypi28
-rw-r--r--build/mac/asan.gyp32
-rwxr-xr-xbuild/mac/copy_asan_runtime_dylib.sh53
4 files changed, 114 insertions, 0 deletions
diff --git a/build/all.gyp b/build/all.gyp
index 58e8b09..a071908 100644
--- a/build/all.gyp
+++ b/build/all.gyp
@@ -11,6 +11,7 @@
'dependencies': [
'some.gyp:*',
'../base/base.gyp:*',
+ '../build/mac/asan.gyp:*',
'../chrome/chrome.gyp:*',
'../content/content.gyp:*',
'../crypto/crypto.gyp:*',
diff --git a/build/common.gypi b/build/common.gypi
index f22c58c..c861e63 100644
--- a/build/common.gypi
+++ b/build/common.gypi
@@ -1658,6 +1658,11 @@
# throughout the codebase.
'defines' : ['USE_SKIA'],
'conditions': [
+ ['asan==1', {
+ 'dependencies': [
+ '<(DEPTH)/build/mac/asan.gyp:asan_dynamic_runtime',
+ ],
+ }],
['OS=="linux" and linux_use_tcmalloc==1 and clang_type_profiler==1', {
'cflags_cc!': ['-fno-rtti'],
'cflags_cc+': [
@@ -3530,6 +3535,29 @@
}],
['_mac_bundle', {
'xcode_settings': {'OTHER_LDFLAGS': ['-Wl,-ObjC']},
+ 'target_conditions': [
+ ['_type=="executable"', {
+ 'conditions': [
+ ['asan==1', {
+ 'postbuilds': [
+ {
+ 'variables': {
+ # Define copy_asan_dylib_path in a variable ending in
+ # _path so that gyp understands it's a path and
+ # performs proper relativization during dict merging.
+ 'copy_asan_dylib_path':
+ 'mac/copy_asan_runtime_dylib.sh',
+ },
+ 'postbuild_name': 'Copy ASan runtime dylib',
+ 'action': [
+ '<(copy_asan_dylib_path)',
+ ],
+ },
+ ],
+ }],
+ ],
+ }],
+ ],
}],
], # target_conditions
}, # target_defaults
diff --git a/build/mac/asan.gyp b/build/mac/asan.gyp
new file mode 100644
index 0000000..4a0cef9
--- /dev/null
+++ b/build/mac/asan.gyp
@@ -0,0 +1,32 @@
+# Copyright (c) 2012 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.
+
+{
+ 'targets': [
+ {
+ 'target_name': 'asan_dynamic_runtime',
+ 'type': 'none',
+ 'variables': {
+ # Every target is going to depend on asan_dynamic_runtime, so allow
+ # this one to depend on itself.
+ 'prune_self_dependency': 1,
+ # Path is relative to this GYP file.
+ 'asan_rtl_mask_path':
+ '../../third_party/llvm-build/Release+Asserts/lib/clang/*/lib/darwin/libclang_rt.asan_osx_dynamic.dylib',
+ },
+ 'conditions': [
+ ['OS=="mac"', {
+ 'copies': [
+ {
+ 'destination': '<(PRODUCT_DIR)',
+ 'files': [
+ '<!(/bin/ls <(asan_rtl_mask_path))',
+ ],
+ },
+ ],
+ }],
+ ],
+ },
+ ],
+}
diff --git a/build/mac/copy_asan_runtime_dylib.sh b/build/mac/copy_asan_runtime_dylib.sh
new file mode 100755
index 0000000..beefe79
--- /dev/null
+++ b/build/mac/copy_asan_runtime_dylib.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+# Copyright (c) 2013 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.
+
+# For app bundles built with ASan, copies the runtime lib
+# (libclang_rt.asan_osx_dynamic.dylib), on which their executables depend, from
+# the compiler installation path to appname.app/Contents/Resources and fixes the
+# dylib's install name in the binary to be relative to @executable_path.
+
+set -e
+
+BINARY="${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}"
+BINARY_DIR="$(dirname "${BINARY}")"
+ASAN_DYLIB_NAME=libclang_rt.asan_osx_dynamic.dylib
+ASAN_DYLIB=$(find \
+ "${BUILT_PRODUCTS_DIR}/../../third_party/llvm-build/Release+Asserts/lib/clang/" \
+ -type f -path "*${ASAN_DYLIB_NAME}")
+
+# Find the link to the ASan runtime encoded in the binary.
+BUILTIN_DYLIB_PATH=$(otool -L "${BINARY}" | \
+ sed -Ene 's/^[[:blank:]]+(.*libclang_rt\.asan_osx_dynamic\.dylib).*$/\1/p')
+
+if [[ -z "${BUILTIN_DYLIB_PATH}" ]]; then
+ echo "${BINARY} does not depend on the ASan runtime library!" >&2
+ # TODO(glider): make this return 1 when we fully switch to the dynamic
+ # runtime in ASan.
+ exit 0
+fi
+
+DYLIB_BASENAME=$(basename "${ASAN_DYLIB}")
+if [[ "${DYLIB_BASENAME}" != "${ASAN_DYLIB_NAME}" ]]; then
+ echo "basename(${ASAN_DYLIB}) != ${ASAN_DYLIB_NAME}" >&2
+ exit 1
+fi
+
+LIBRARIES_DIR="$(dirname "${BINARY_DIR}")/Libraries"
+mkdir -p "${LIBRARIES_DIR}"
+cp "${ASAN_DYLIB}" "${LIBRARIES_DIR}"
+
+NEW_LC_ID_DYLIB="@executable_path/../Libraries/${ASAN_DYLIB_NAME}"
+
+# Make LC_ID_DYLIB of the runtime copy point to its location.
+install_name_tool \
+ -id "${NEW_LC_ID_DYLIB}" \
+ "${LIBRARIES_DIR}/${ASAN_DYLIB_NAME}"
+
+# Fix the rpath to the runtime library recorded in the binary.
+install_name_tool \
+ -change "${BUILTIN_DYLIB_PATH}" \
+ "${NEW_LC_ID_DYLIB}" \
+ "${BINARY}"