Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: third_party/instrumented_libraries/download_build_install.py

Issue 96083003: Add instrumented libraries build with msan (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/common.gypi ('k') | third_party/instrumented_libraries/instrumented_libraries.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Downloads, builds (with instrumentation) and installs shared libraries.""" 6 """Downloads, builds (with instrumentation) and installs shared libraries."""
7 7
8 import argparse 8 import argparse
9 import os 9 import os
10 import shutil 10 import shutil
11 import subprocess 11 import subprocess
12 import sys 12 import sys
13 13
14 # Should be a dict from 'sanitizer type' to 'compiler flag'. 14 # Build parameters for different sanitizers
15 SUPPORTED_SANITIZERS = {'asan': 'address'} 15 SUPPORTED_SANITIZERS = {
16 'asan': {
17 'compiler_flags': '-fsanitize=address -gline-tables-only -fPIC -w',
18 'linker_flags': '-fsanitize=address -Wl,-z,origin -Wl,-R,XORIGIN/.'
19 },
20 'msan': {
21 'compiler_flags': '-fsanitize=memory -fsanitize-memory-track-origins '
22 '-gline-tables-only -fPIC -w',
23 'linker_flags': '-fsanitize=memory -Wl,-z,origin -Wl,-R,XORIGIN/.'
24 },
25 }
16 26
17 27
18 class ScopedChangeDirectory(object): 28 class ScopedChangeDirectory(object):
19 """Changes current working directory and restores it back automatically.""" 29 """Changes current working directory and restores it back automatically."""
20 def __init__(self, path): 30 def __init__(self, path):
21 self.path = path 31 self.path = path
22 self.old_path = '' 32 self.old_path = ''
23 33
24 def __enter__(self): 34 def __enter__(self):
25 self.old_path = os.getcwd() 35 self.old_path = os.getcwd()
26 os.chdir(self.path) 36 os.chdir(self.path)
27 37
28 def __exit__(self, exc_type, exc_value, traceback): 38 def __exit__(self, exc_type, exc_value, traceback):
29 os.chdir(self.old_path) 39 os.chdir(self.old_path)
30 40
31 41
32 def get_script_absolute_path(): 42 def get_script_absolute_path():
33 return os.path.dirname(os.path.abspath(__file__)) 43 return os.path.dirname(os.path.abspath(__file__))
34 44
35 45
36 def get_library_build_dependencies(library): 46 def get_library_build_dependencies(library):
37 command = 'apt-get -s build-dep %s | grep Inst | cut -d " " -f 2' % library 47 command = 'apt-get -s build-dep %s | grep Inst | cut -d " " -f 2' % library
38 command_result = subprocess.Popen(command, stdout=subprocess.PIPE, 48 command_result = subprocess.Popen(command, stdout=subprocess.PIPE,
39 shell=True) 49 shell=True)
50 if command_result.wait():
51 raise Exception("Failed to determine build dependencies for %s" % library)
40 build_dependencies = [l.strip() for l in command_result.stdout] 52 build_dependencies = [l.strip() for l in command_result.stdout]
41 return build_dependencies 53 return build_dependencies
42 54
43 55
44 def download_build_install(parsed_arguments): 56 def download_build_install(parsed_arguments):
45 sanitizer_flag = SUPPORTED_SANITIZERS[parsed_arguments.sanitizer_type] 57 sanitizer_params = SUPPORTED_SANITIZERS[parsed_arguments.sanitizer_type]
46 58
47 environment = os.environ.copy() 59 environment = os.environ.copy()
48 environment['CFLAGS'] = '-fsanitize=%s -g -fPIC -w' % sanitizer_flag 60 environment['CFLAGS'] = sanitizer_params['compiler_flags']
49 environment['CXXFLAGS'] = '-fsanitize=%s -g -fPIC -w' % sanitizer_flag 61 environment['CXXFLAGS'] = sanitizer_params['compiler_flags']
50 # We use XORIGIN as RPATH and after building library replace it to $ORIGIN 62 # We use XORIGIN as RPATH and after building library replace it to $ORIGIN
51 # The reason: this flag goes through configure script and makefiles 63 # The reason: this flag goes through configure script and makefiles
52 # differently for different libraries. So the dollar sign '$' should be 64 # differently for different libraries. So the dollar sign '$' should be
53 # differently escaped. Instead of having problems with that it just 65 # differently escaped. Instead of having problems with that it just
54 # uses XORIGIN to build library and after that replaces it to $ORIGIN 66 # uses XORIGIN to build library and after that replaces it to $ORIGIN
55 # directly in .so file. 67 # directly in .so file.
56 environment['LDFLAGS'] = '-Wl,-z,origin -Wl,-R,XORIGIN/.' 68 environment['LDFLAGS'] = sanitizer_params['linker_flags']
57 69
58 library_directory = '%s/%s' % (parsed_arguments.intermediate_directory, 70 library_directory = '%s/%s' % (parsed_arguments.intermediate_directory,
59 parsed_arguments.library) 71 parsed_arguments.library)
60 72
61 install_prefix = '%s/%s/instrumented_libraries/%s' % ( 73 install_prefix = '%s/%s/instrumented_libraries/%s' % (
62 get_script_absolute_path(), 74 get_script_absolute_path(),
63 parsed_arguments.product_directory, 75 parsed_arguments.product_directory,
64 parsed_arguments.sanitizer_type) 76 parsed_arguments.sanitizer_type)
65 77
66 if not os.path.exists(library_directory): 78 if not os.path.exists(library_directory):
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 print >> sys.stderr, 'One-liner for APT:' 134 print >> sys.stderr, 'One-liner for APT:'
123 print >> sys.stderr, 'sudo apt-get -y --no-remove build-dep %s' % \ 135 print >> sys.stderr, 'sudo apt-get -y --no-remove build-dep %s' % \
124 parsed_arguments.library 136 parsed_arguments.library
125 sys.exit(1) 137 sys.exit(1)
126 138
127 download_build_install(parsed_arguments) 139 download_build_install(parsed_arguments)
128 140
129 141
130 if __name__ == '__main__': 142 if __name__ == '__main__':
131 main() 143 main()
OLDNEW
« no previous file with comments | « build/common.gypi ('k') | third_party/instrumented_libraries/instrumented_libraries.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698