diff options
author | sammc <sammc@chromium.org> | 2015-05-31 18:09:36 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-01 01:10:10 +0000 |
commit | 74f1d187956e64c25724b116ed06ca7d00b89917 (patch) | |
tree | 06691d49eb471280c56b0a4d6bf8374954b957f1 | |
parent | b45962be3b0ac2a4133290e4e02b4f9fdec012a6 (diff) | |
download | chromium_src-74f1d187956e64c25724b116ed06ca7d00b89917.zip chromium_src-74f1d187956e64c25724b116ed06ca7d00b89917.tar.gz chromium_src-74f1d187956e64c25724b116ed06ca7d00b89917.tar.bz2 |
GN: Add support for prebuilt instrumented libraries.
TBR=glider@chromium.org
Review URL: https://codereview.chromium.org/1150193002
Cr-Commit-Position: refs/heads/master@{#332148}
-rw-r--r-- | build/config/compiler/BUILD.gn | 7 | ||||
-rw-r--r-- | build/config/sanitizers/BUILD.gn | 4 | ||||
-rw-r--r-- | build/config/sanitizers/sanitizers.gni | 10 | ||||
-rw-r--r-- | third_party/instrumented_libraries/BUILD.gn | 67 | ||||
-rw-r--r-- | third_party/instrumented_libraries/instrumented_libraries.gyp | 20 | ||||
-rwxr-xr-x | third_party/instrumented_libraries/scripts/unpack_binaries.py | 42 | ||||
-rwxr-xr-x | third_party/instrumented_libraries/scripts/unpack_binaries.sh | 15 |
7 files changed, 132 insertions, 33 deletions
diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index 3961b8c..30872ae 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -57,11 +57,6 @@ declare_args() { # The patch is preapplied to the internal toolchain and hence all bots. msvs_xtree_patched = false } - - # Track where uninitialized memory originates from. From fastest to slowest: - # 0 - no tracking, 1 - track only the initial allocation site, 2 - track the - # chain of stores leading from allocation site to use site. - msan_track_origins = 2 } # default_include_dirs --------------------------------------------------------- @@ -175,8 +170,6 @@ config("compiler") { "-fsanitize-memory-track-origins=$msan_track_origins", "-fsanitize-blacklist=$msan_blacklist_path", ] - - # TODO(GYP): Support instrumented libraries. } if (use_custom_libcxx) { diff --git a/build/config/sanitizers/BUILD.gn b/build/config/sanitizers/BUILD.gn index 40d476e..8996951 100644 --- a/build/config/sanitizers/BUILD.gn +++ b/build/config/sanitizers/BUILD.gn @@ -8,7 +8,9 @@ import("//build/config/sanitizers/sanitizers.gni") # shared_libraries. Unconditionally depend upon this target as it is empty if # |is_asan|, |is_lsan|, |is_tsan|, |is_msan| and |use_custom_libcxx| are false. group("deps") { - deps = [] + deps = [ + "//third_party/instrumented_libraries:deps", + ] if (is_asan || is_lsan || is_tsan || is_msan) { public_configs = [ ":sanitizer_options_link_helper" ] deps += [ ":options_sources" ] diff --git a/build/config/sanitizers/sanitizers.gni b/build/config/sanitizers/sanitizers.gni index e9aeeae..a7b9658 100644 --- a/build/config/sanitizers/sanitizers.gni +++ b/build/config/sanitizers/sanitizers.gni @@ -7,4 +7,14 @@ declare_args() { # buildtools/third_party/libc++abi) instead of stdlibc++ as standard library. # This is intended to be used for instrumented builds. use_custom_libcxx = (is_asan && is_linux) || is_tsan || is_msan + + # Track where uninitialized memory originates from. From fastest to slowest: + # 0 - no tracking, 1 - track only the initial allocation site, 2 - track the + # chain of stores leading from allocation site to use site. + msan_track_origins = 2 + + # Use dynamic libraries instrumented by one of the sanitizers instead of the + # standard system libraries. Set this flag to download prebuilt binaries from + # GCS. + use_prebuilt_instrumented_libraries = false } diff --git a/third_party/instrumented_libraries/BUILD.gn b/third_party/instrumented_libraries/BUILD.gn new file mode 100644 index 0000000..8d113ef --- /dev/null +++ b/third_party/instrumented_libraries/BUILD.gn @@ -0,0 +1,67 @@ +# Copyright 2015 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. + +import("//build/config/sanitizers/sanitizers.gni") + +prebuilt_available = + is_msan && (msan_track_origins == 0 || msan_track_origins == 2) + +group("deps") { + if (use_prebuilt_instrumented_libraries) { + assert(prebuilt_available, + "Prebuilt instrumented libraries are only available when " + + "is_msan = true and msan_track_origins = {0, 2}") + deps = [ + ":prebuilt", + ] + } +} + +if (prebuilt_available) { + group("prebuilt") { + visibility = [ ":deps" ] + public_configs = [ ":prebuilt_link_helper" ] + deps = [ + ":extract_prebuilt_instrumented_libraries", + ] + } + + if (is_msan) { + sanitizer_type = "msan" + if (msan_track_origins == 0) { + archive_prefix = "msan-no-origins" + } else if (msan_track_origins == 2) { + archive_prefix = "msan-chained-origins" + } + } + + # TODO(GYP): scripts/download_binaries.py uses GYP_DEFINES to decide whether + # to download the archives extracted here. + # Note: This requires a clobber whenever Ubuntu version changes. + action("extract_prebuilt_instrumented_libraries") { + visibility = [ ":prebuilt" ] + script = "scripts/unpack_binaries.py" + depfile = "$target_out_dir/$archive_prefix.d" + args = [ + archive_prefix, + rebase_path("binaries"), + rebase_path(root_build_dir + "/instrumented_libraries_prebuilt"), + rebase_path(target_out_dir, root_build_dir), + ] + outputs = [ + "$target_out_dir/$archive_prefix.txt", + ] + } + + config("prebuilt_link_helper") { + visibility = [ ":prebuilt" ] + ldflags = [ + # Add a relative RPATH entry to Chromium binaries. This puts instrumented + # DSOs before system-installed versions in library search path. + "-Wl,-R,\$ORIGIN/instrumented_libraries_prebuilt/$sanitizer_type/lib", + "-Wl,-z,origin", + ] + } +} +# TODO(GYP): Support building instrumented libraries from source. diff --git a/third_party/instrumented_libraries/instrumented_libraries.gyp b/third_party/instrumented_libraries/instrumented_libraries.gyp index 8f0bdda..307aed1 100644 --- a/third_party/instrumented_libraries/instrumented_libraries.gyp +++ b/third_party/instrumented_libraries/instrumented_libraries.gyp @@ -94,34 +94,34 @@ ['msan==1', { 'conditions': [ ['msan_track_origins==2', { - 'archive_name': 'msan-chained-origins-<(_ubuntu_release)', + 'archive_prefix': 'msan-chained-origins', }, { 'conditions': [ ['msan_track_origins==0', { - 'archive_name': 'msan-no-origins-<(_ubuntu_release)', + 'archive_prefix': 'msan-no-origins', }, { - 'archive_name': 'UNSUPPORTED_CONFIGURATION' + 'archive_prefix': 'UNSUPPORTED_CONFIGURATION' }], ]}], ]}, { - 'archive_name': 'UNSUPPORTED_CONFIGURATION' + 'archive_prefix': 'UNSUPPORTED_CONFIGURATION' }], ], }, 'actions': [ { - 'action_name': 'unpack_<(archive_name).tgz', + 'action_name': 'unpack_<(archive_prefix)-<(_ubuntu_release).tgz', 'inputs': [ - 'binaries/<(archive_name).tgz', + 'binaries/<(archive_prefix)-<(_ubuntu_release).tgz', ], 'outputs': [ - '<(PRODUCT_DIR)/instrumented_libraries_prebuilt/<(archive_name).txt', + '<(PRODUCT_DIR)/instrumented_libraries_prebuilt/<(archive_prefix).txt', ], 'action': [ - 'scripts/unpack_binaries.sh', - 'binaries/<(archive_name).tgz', + 'scripts/unpack_binaries.py', + '<(archive_prefix)', + 'binaries', '<(PRODUCT_DIR)/instrumented_libraries_prebuilt/', - '<(PRODUCT_DIR)/instrumented_libraries_prebuilt/<(archive_name).txt', ], }, ], diff --git a/third_party/instrumented_libraries/scripts/unpack_binaries.py b/third_party/instrumented_libraries/scripts/unpack_binaries.py new file mode 100755 index 0000000..3e17790 --- /dev/null +++ b/third_party/instrumented_libraries/scripts/unpack_binaries.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +# Copyright 2015 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. + +"""Unpacks pre-built sanitizer-instrumented third-party libraries.""" + +import os +import subprocess +import shutil +import sys + +import download_binaries + + +def get_archive_name(archive_prefix): + return '%s-%s.tgz' % (archive_prefix, download_binaries.get_ubuntu_release()) + + +def main(archive_prefix, archive_dir, target_dir, stamp_dir=None): + shutil.rmtree(target_dir, ignore_errors=True) + + os.mkdir(target_dir) + subprocess.check_call([ + 'tar', + '-zxf', + os.path.join(archive_dir, get_archive_name(archive_prefix)), + '-C', + target_dir]) + stamp_file = os.path.join(stamp_dir or target_dir, '%s.txt' % archive_prefix) + open(stamp_file, 'w').close() + + if stamp_dir: + with open(os.path.join(stamp_dir, '%s.d' % archive_prefix), 'w') as f: + f.write('%s: %s' % ( + stamp_file, os.path.join(archive_dir, + get_archive_name(archive_prefix)))) + return 0 + + +if __name__ == '__main__': + sys.exit(main(*sys.argv[1:])) diff --git a/third_party/instrumented_libraries/scripts/unpack_binaries.sh b/third_party/instrumented_libraries/scripts/unpack_binaries.sh deleted file mode 100755 index 12af6ad..0000000 --- a/third_party/instrumented_libraries/scripts/unpack_binaries.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -# Copyright 2015 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. - -# Unpacks an archive containing prebuilt instrumented libraries into output dir. - -archive_file=$1 -target_dir=$2 -stamp_file=$3 - -rm ${target_dir}/* -rf -tar -zxf ${archive_file} -C ${target_dir} - -touch ${stamp_file} |