Adds a flag "use_instrumented_libraries" and corresponding target with 2 simple libraries
BUG=313751 R=glider@chromium.org,thakis@chromium.org TBR=cpu@chromium.org Review URL: https://codereview.chromium.org/50423003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@234498 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
build
third_party/instrumented_libraries
@@ -317,6 +317,10 @@
|
|||||||
# See http://clang.llvm.org/docs/MemorySanitizer.html
|
# See http://clang.llvm.org/docs/MemorySanitizer.html
|
||||||
'msan%': 0,
|
'msan%': 0,
|
||||||
|
|
||||||
|
# Use the dynamic libraries instrumented by one of the sanitizers
|
||||||
|
# instead of the standard system libraries.
|
||||||
|
'use_instrumented_libraries%': 0,
|
||||||
|
|
||||||
# Use a modified version of Clang to intercept allocated types and sizes
|
# Use a modified version of Clang to intercept allocated types and sizes
|
||||||
# for allocated objects. clang_type_profiler=1 implies clang=1.
|
# for allocated objects. clang_type_profiler=1 implies clang=1.
|
||||||
# See http://dev.chromium.org/developers/deep-memory-profiler/cpp-object-type-identifier
|
# See http://dev.chromium.org/developers/deep-memory-profiler/cpp-object-type-identifier
|
||||||
@@ -854,6 +858,7 @@
|
|||||||
'msan%': '<(msan)',
|
'msan%': '<(msan)',
|
||||||
'tsan%': '<(tsan)',
|
'tsan%': '<(tsan)',
|
||||||
'tsan_blacklist%': '<(tsan_blacklist)',
|
'tsan_blacklist%': '<(tsan_blacklist)',
|
||||||
|
'use_instrumented_libraries%': '<(use_instrumented_libraries)',
|
||||||
'clang_type_profiler%': '<(clang_type_profiler)',
|
'clang_type_profiler%': '<(clang_type_profiler)',
|
||||||
'order_profiling%': '<(order_profiling)',
|
'order_profiling%': '<(order_profiling)',
|
||||||
'order_text_section%': '<(order_text_section)',
|
'order_text_section%': '<(order_text_section)',
|
||||||
@@ -3420,6 +3425,24 @@
|
|||||||
}],
|
}],
|
||||||
],
|
],
|
||||||
}],
|
}],
|
||||||
|
['use_instrumented_libraries==1', {
|
||||||
|
'dependencies': [
|
||||||
|
'<(DEPTH)/third_party/instrumented_libraries/instrumented_libraries.gyp:instrumented_libraries',
|
||||||
|
],
|
||||||
|
'conditions': [
|
||||||
|
['asan==1', {
|
||||||
|
'target_conditions': [
|
||||||
|
['_toolset=="target"', {
|
||||||
|
'ldflags': [
|
||||||
|
# Add RPATH to result binary to make it linking instrumented libraries ($ORIGIN means relative RPATH)
|
||||||
|
'-Wl,-R,\$$ORIGIN/instrumented_libraries/asan/lib/:\$$ORIGIN/instrumented_libraries/asan/usr/lib/x86_64-linux-gnu/',
|
||||||
|
'-Wl,-z,origin',
|
||||||
|
],
|
||||||
|
}],
|
||||||
|
],
|
||||||
|
}],
|
||||||
|
],
|
||||||
|
}],
|
||||||
['order_profiling!=0 and (chromeos==1 or OS=="linux" or OS=="android")', {
|
['order_profiling!=0 and (chromeos==1 or OS=="linux" or OS=="android")', {
|
||||||
'target_conditions' : [
|
'target_conditions' : [
|
||||||
['_toolset=="target"', {
|
['_toolset=="target"', {
|
||||||
|
14
third_party/instrumented_libraries/README.chromium
vendored
Normal file
14
third_party/instrumented_libraries/README.chromium
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
Name: instrumented_libbraries
|
||||||
|
URL: n/a
|
||||||
|
Version: 0
|
||||||
|
Security Critical: no
|
||||||
|
License: n/a
|
||||||
|
License File: NOT_SHIPPED
|
||||||
|
|
||||||
|
Description:
|
||||||
|
Scripts which can download and build several third party libraries
|
||||||
|
using different instrumentation tools (AddressSanitizer, etc.).
|
||||||
|
|
||||||
|
Flag "use_instrumented_libraries=1" in GYP_DEFINES enables usage of
|
||||||
|
instrumented libraries and final binary will use them instead of standard
|
||||||
|
system shared libraries.
|
138
third_party/instrumented_libraries/download_build_install.sh
vendored
Executable file
138
third_party/instrumented_libraries/download_build_install.sh
vendored
Executable file
@@ -0,0 +1,138 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Copyright 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.
|
||||||
|
|
||||||
|
# Downloads, builds (with instrumentation) and installs shared libraries.
|
||||||
|
|
||||||
|
# Go to this shell script directory
|
||||||
|
cd $(dirname "$0")
|
||||||
|
|
||||||
|
# Colored print.
|
||||||
|
|
||||||
|
RED_COLOR='\e[0;31m'
|
||||||
|
GREEN_COLOR='\e[0;32m'
|
||||||
|
NO_COLOR='\e[0m'
|
||||||
|
|
||||||
|
function echo_red {
|
||||||
|
echo -e "${RED_COLOR}$1${NO_COLOR}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function echo_green {
|
||||||
|
echo -e "${GREEN_COLOR}$1${NO_COLOR}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Default values.
|
||||||
|
|
||||||
|
product_dir=$(pwd)
|
||||||
|
intermediate_dir=$(pwd)
|
||||||
|
|
||||||
|
# Should be without spaces to pass it to dpkg-buildpackage.
|
||||||
|
makejobs="-j14"
|
||||||
|
|
||||||
|
# Parsing args.
|
||||||
|
|
||||||
|
while getopts ":i:l:m:hp:s:j:" opt; do
|
||||||
|
case ${opt} in
|
||||||
|
p)
|
||||||
|
echo_green "Only installing dependencies (requires root access)"
|
||||||
|
echo_green "Installing dependencies for: ${OPTARG}"
|
||||||
|
sudo apt-get -y --no-remove build-dep ${OPTARG}
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
h)
|
||||||
|
echo "Possible flags:
|
||||||
|
-p - install dependencies for packages,
|
||||||
|
-h - this help,
|
||||||
|
-l - which library to build,
|
||||||
|
-i - sets relative product_dir,
|
||||||
|
-s - sanitizer (only asan is supported now)."
|
||||||
|
echo "Environment variabless, which affect this script: CC and CXX"
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
i)
|
||||||
|
product_dir="$(pwd)/${OPTARG}"
|
||||||
|
;;
|
||||||
|
l)
|
||||||
|
library="${OPTARG}"
|
||||||
|
;;
|
||||||
|
m)
|
||||||
|
intermediate_dir="${OPTARG}"
|
||||||
|
;;
|
||||||
|
j)
|
||||||
|
makejobs="-j${OPTARG}"
|
||||||
|
;;
|
||||||
|
s)
|
||||||
|
sanitizer_type="${OPTARG}"
|
||||||
|
if [[ "${OPTARG}" == "asan" ]]; then
|
||||||
|
sanitizer_flag_string="address"
|
||||||
|
else
|
||||||
|
echo_red "Invalid sanitizer: ${OPTARG}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo_red "Invalid option: -${OPTARG}" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -z "${library}" ]]; then
|
||||||
|
echo_red "No library specified to build" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${sanitizer_type}" ]]; then
|
||||||
|
echo_red "No sanitizer specified" >&2
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
export CFLAGS="-fsanitize=${sanitizer_flag_string} -g -fPIC -w"
|
||||||
|
export CXXFLAGS="-fsanitize=${sanitizer_flag_string} -g -fPIC -w"
|
||||||
|
|
||||||
|
# We use XORIGIN as RPATH and after building library replace it to $ORIGIN
|
||||||
|
# The reason: this flag goes through configure script and makefiles
|
||||||
|
# differently for different libraries. So the dollar sign "$" should be
|
||||||
|
# differently escaped. Instead of having problems with that it just
|
||||||
|
# uses XORIGIN to build library and after that replaces it to $ORIGIN
|
||||||
|
# directly in .so file.
|
||||||
|
export LDFLAGS="-Wl,-z,origin -Wl,-R,XORIGIN/."
|
||||||
|
|
||||||
|
mkdir -p ${product_dir}/instrumented_libraries/${sanitizer_type}
|
||||||
|
|
||||||
|
needed_dependencies=$(apt-get -s build-dep ${library} | grep Inst \
|
||||||
|
| cut -d " " -f 2)
|
||||||
|
|
||||||
|
if [[ -n "${needed_dependencies}" ]]; then
|
||||||
|
echo_red "Library ${library} needs dependencies: ${needed_dependencies}" >&2
|
||||||
|
echo_red "Please, install dependencies using:
|
||||||
|
third_party/instrumented_libraries/download_build_install -p ${library}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
(
|
||||||
|
# Downloading library
|
||||||
|
mkdir -p ${intermediate_dir}/${library}
|
||||||
|
cd ${intermediate_dir}/${library}
|
||||||
|
apt-get source ${library} 2>&1
|
||||||
|
|
||||||
|
# cd into the only directory in the current folder
|
||||||
|
# where our package has been unpacked.
|
||||||
|
cd $(ls -F |grep \/$)
|
||||||
|
|
||||||
|
# Build library
|
||||||
|
./configure --prefix="${product_dir}/instrumented_libraries/${sanitizer_type}"
|
||||||
|
make ${makejobs}
|
||||||
|
|
||||||
|
# Install library
|
||||||
|
make ${makejobs} install 2>&1
|
||||||
|
) > /dev/null
|
||||||
|
|
||||||
|
# Mark that library is installed.
|
||||||
|
# This file is used by GYP as 'output' to mark that it's already build
|
||||||
|
# while making incremental build.
|
||||||
|
touch ${product_dir}/instrumented_libraries/${sanitizer_type}/${library}.txt
|
||||||
|
|
||||||
|
# Clean up.
|
||||||
|
rm -rf ${intermediate_dir}/${library}
|
22
third_party/instrumented_libraries/fix_rpaths.sh
vendored
Executable file
22
third_party/instrumented_libraries/fix_rpaths.sh
vendored
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Copyright 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.
|
||||||
|
|
||||||
|
# Changes all RPATHs in a given directory from XORIGIN to $ORIGIN
|
||||||
|
# See the comment about XORIGIN in download_build_install.sh
|
||||||
|
|
||||||
|
# Fixes rpath from XORIGIN to $ORIGIN in a single file $1.
|
||||||
|
function fix_rpath {
|
||||||
|
chrpath -r $(chrpath $1 | cut -d " " -f 2 | sed s/XORIGIN/\$ORIGIN/g \
|
||||||
|
| sed s/RPATH=//g) $1 > /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in $(find $1 | grep "\.so$"); do
|
||||||
|
fix_rpath $i
|
||||||
|
done
|
||||||
|
|
||||||
|
# Mark that rpaths are fixed.
|
||||||
|
# This file is used by GYP as 'output' to mark that RPATHs are already fixed
|
||||||
|
# for incremental builds.
|
||||||
|
touch $1/rpaths.fixed.txt
|
41
third_party/instrumented_libraries/instrumented_libraries.gyp
vendored
Normal file
41
third_party/instrumented_libraries/instrumented_libraries.gyp
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# Copyright 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.
|
||||||
|
|
||||||
|
{
|
||||||
|
'targets': [
|
||||||
|
{
|
||||||
|
'target_name': 'instrumented_libraries',
|
||||||
|
'type': 'none',
|
||||||
|
'variables': {
|
||||||
|
'prune_self_dependency': 1,
|
||||||
|
},
|
||||||
|
'dependencies': [
|
||||||
|
'libpng12-0',
|
||||||
|
'libxau6',
|
||||||
|
],
|
||||||
|
'actions': [
|
||||||
|
{
|
||||||
|
'action_name': 'fix_rpaths',
|
||||||
|
'inputs': [
|
||||||
|
'fix_rpaths.sh',
|
||||||
|
],
|
||||||
|
'outputs': [
|
||||||
|
'<(PRODUCT_DIR)/instrumented_libraries/asan/rpaths.fixed.txt',
|
||||||
|
],
|
||||||
|
'action': ['./fix_rpaths.sh', '<(PRODUCT_DIR)/instrumented_libraries/asan'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'target_name': 'libpng12-0',
|
||||||
|
'dependencies=': [],
|
||||||
|
'includes': ['standard_instrumented_library_target.gypi'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'target_name': 'libxau6',
|
||||||
|
'dependencies=': [],
|
||||||
|
'includes': ['standard_instrumented_library_target.gypi'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
22
third_party/instrumented_libraries/standard_instrumented_library_target.gypi
vendored
Normal file
22
third_party/instrumented_libraries/standard_instrumented_library_target.gypi
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# Copyright 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.
|
||||||
|
|
||||||
|
# This file is meant to be included into a target for instrumented dynamic
|
||||||
|
# libraries and describes standard build action for most of the libraries.
|
||||||
|
|
||||||
|
{
|
||||||
|
'type': 'none',
|
||||||
|
'actions': [
|
||||||
|
{
|
||||||
|
'action_name': '<(_target_name)',
|
||||||
|
'inputs': [
|
||||||
|
'download_build_install.sh',
|
||||||
|
],
|
||||||
|
'outputs': [
|
||||||
|
'<(PRODUCT_DIR)/instrumented_libraries/asan/<(_target_name).txt',
|
||||||
|
],
|
||||||
|
'action': ['./download_build_install.sh', '-i', '<(PRODUCT_DIR)', '-l', '<(_target_name)', '-m', '<(INTERMEDIATE_DIR)', '-s', 'asan'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
Reference in New Issue
Block a user