Add instrumented libraries build with msan

BUG=313751
R=glider@chromium.org
TBR=cpu@chromium.org

Review URL: https://codereview.chromium.org/96083003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238394 0039d316-1c4b-4281-b951-d872f2087c98
parent 4fccbc82
...@@ -3447,6 +3447,16 @@ ...@@ -3447,6 +3447,16 @@
}], }],
], ],
}], }],
['msan==1', {
'target_conditions': [
['_toolset=="target"', {
'ldflags': [
'-Wl,-R,\$$ORIGIN/instrumented_libraries/msan/lib/:\$$ORIGIN/instrumented_libraries/msan/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")', {
......
...@@ -11,8 +11,18 @@ import shutil ...@@ -11,8 +11,18 @@ import shutil
import subprocess import subprocess
import sys import sys
# Should be a dict from 'sanitizer type' to 'compiler flag'. # Build parameters for different sanitizers
SUPPORTED_SANITIZERS = {'asan': 'address'} SUPPORTED_SANITIZERS = {
'asan': {
'compiler_flags': '-fsanitize=address -gline-tables-only -fPIC -w',
'linker_flags': '-fsanitize=address -Wl,-z,origin -Wl,-R,XORIGIN/.'
},
'msan': {
'compiler_flags': '-fsanitize=memory -fsanitize-memory-track-origins '
'-gline-tables-only -fPIC -w',
'linker_flags': '-fsanitize=memory -Wl,-z,origin -Wl,-R,XORIGIN/.'
},
}
class ScopedChangeDirectory(object): class ScopedChangeDirectory(object):
...@@ -37,23 +47,25 @@ def get_library_build_dependencies(library): ...@@ -37,23 +47,25 @@ def get_library_build_dependencies(library):
command = 'apt-get -s build-dep %s | grep Inst | cut -d " " -f 2' % library command = 'apt-get -s build-dep %s | grep Inst | cut -d " " -f 2' % library
command_result = subprocess.Popen(command, stdout=subprocess.PIPE, command_result = subprocess.Popen(command, stdout=subprocess.PIPE,
shell=True) shell=True)
if command_result.wait():
raise Exception("Failed to determine build dependencies for %s" % library)
build_dependencies = [l.strip() for l in command_result.stdout] build_dependencies = [l.strip() for l in command_result.stdout]
return build_dependencies return build_dependencies
def download_build_install(parsed_arguments): def download_build_install(parsed_arguments):
sanitizer_flag = SUPPORTED_SANITIZERS[parsed_arguments.sanitizer_type] sanitizer_params = SUPPORTED_SANITIZERS[parsed_arguments.sanitizer_type]
environment = os.environ.copy() environment = os.environ.copy()
environment['CFLAGS'] = '-fsanitize=%s -g -fPIC -w' % sanitizer_flag environment['CFLAGS'] = sanitizer_params['compiler_flags']
environment['CXXFLAGS'] = '-fsanitize=%s -g -fPIC -w' % sanitizer_flag environment['CXXFLAGS'] = sanitizer_params['compiler_flags']
# We use XORIGIN as RPATH and after building library replace it to $ORIGIN # We use XORIGIN as RPATH and after building library replace it to $ORIGIN
# The reason: this flag goes through configure script and makefiles # The reason: this flag goes through configure script and makefiles
# differently for different libraries. So the dollar sign '$' should be # differently for different libraries. So the dollar sign '$' should be
# differently escaped. Instead of having problems with that it just # differently escaped. Instead of having problems with that it just
# uses XORIGIN to build library and after that replaces it to $ORIGIN # uses XORIGIN to build library and after that replaces it to $ORIGIN
# directly in .so file. # directly in .so file.
environment['LDFLAGS'] = '-Wl,-z,origin -Wl,-R,XORIGIN/.' environment['LDFLAGS'] = sanitizer_params['linker_flags']
library_directory = '%s/%s' % (parsed_arguments.intermediate_directory, library_directory = '%s/%s' % (parsed_arguments.intermediate_directory,
parsed_arguments.library) parsed_arguments.library)
......
...@@ -3,6 +3,14 @@ ...@@ -3,6 +3,14 @@
# found in the LICENSE file. # found in the LICENSE file.
{ {
'conditions': [
['asan==1', {
'sanitizer_type': 'asan',
}],
['msan==1', {
'sanitizer_type': 'msan',
}],
],
'targets': [ 'targets': [
{ {
'target_name': 'instrumented_libraries', 'target_name': 'instrumented_libraries',
...@@ -22,9 +30,12 @@ ...@@ -22,9 +30,12 @@
'fix_rpaths.sh', 'fix_rpaths.sh',
], ],
'outputs': [ 'outputs': [
'<(PRODUCT_DIR)/instrumented_libraries/asan/rpaths.fixed.txt', '<(PRODUCT_DIR)/instrumented_libraries/<(_sanitizer_type)/rpaths.fixed.txt',
],
'action': [
'<(DEPTH)/third_party/instrumented_libraries/fix_rpaths.sh',
'<(PRODUCT_DIR)/instrumented_libraries/<(_sanitizer_type)'
], ],
'action': ['./fix_rpaths.sh', '<(PRODUCT_DIR)/instrumented_libraries/asan'],
}, },
], ],
}, },
......
...@@ -14,9 +14,14 @@ ...@@ -14,9 +14,14 @@
'download_build_install.py', 'download_build_install.py',
], ],
'outputs': [ 'outputs': [
'<(PRODUCT_DIR)/instrumented_libraries/asan/<(_target_name).txt', '<(PRODUCT_DIR)/instrumented_libraries/<(_sanitizer_type)/<(_target_name).txt',
],
'action': ['<(DEPTH)/third_party/instrumented_libraries/download_build_install.py',
'--product-directory=<(PRODUCT_DIR)',
'--library=<(_target_name)',
'--intermediate-directory=<(INTERMEDIATE_DIR)',
'--sanitizer-type=<(_sanitizer_type)',
], ],
'action': ['./download_build_install.py', '-i', '<(PRODUCT_DIR)', '-l', '<(_target_name)', '-m', '<(INTERMEDIATE_DIR)', '-s', 'asan'],
}, },
], ],
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment