Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2017 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 """ A script to compile the integration tests with llvm's clang, | |
|
Sébastien Marchand
2017/06/23 18:01:54
Remove the space before the 'A'
| |
| 6 instrument the code with llvm's Asan, and link it to the syzyasan_rtl | |
| 7 runtime environment. | |
| 8 """ | |
| 9 | |
| 10 import optparse | |
| 11 import os | |
| 12 import re | |
| 13 import subprocess | |
| 14 import sys | |
| 15 | |
| 16 | |
| 17 _SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) | |
| 18 _SRC_DIR = os.path.abspath(os.path.join(_SCRIPT_DIR, os.pardir, os.pardir)) | |
| 19 _CLANG_CL_PATH = (_SRC_DIR, | |
| 20 "/third_party/llvm-build/Release+Asserts/bin/clang-cl.exe") | |
| 21 | |
| 22 | |
| 23 def compile_with_asan(clang_path, source_files, src_dir): | |
| 24 """Only compiles with clang but does not link. | |
| 25 | |
| 26 Only compiles the files and isntruments them with LLVM's Asan but does not | |
| 27 link them. The linking is done separately in the method link. | |
| 28 | |
| 29 Args: | |
| 30 clang_path: Path to the clang-cl compiler. | |
| 31 source_files: The source files to be compiled. | |
| 32 src_dir: The repository where the syzgy src is located. | |
| 33 """ | |
| 34 compiler_flags = [ | |
| 35 '-c', | |
| 36 '-fsanitize=address', | |
| 37 '-mllvm', | |
| 38 '-asan-instrumentation-with-call-threshold=0', | |
| 39 '-mllvm', | |
| 40 '-asan-stack=0', | |
| 41 '-DUNICODE', | |
| 42 '-D_UNICODE', | |
| 43 '-DNOMINMAX', | |
| 44 '-D_CRT_SECURE_NO_WARNINGS', | |
| 45 '-I', | |
| 46 src_dir | |
| 47 ] | |
| 48 | |
| 49 compile_command = [clang_path] | |
| 50 compile_command.extend(compiler_flags) | |
| 51 compile_command.extend(source_files) | |
| 52 | |
| 53 ret = subprocess.call(compile_command) | |
|
Sébastien Marchand
2017/06/23 18:01:54
The object files seems to be produced next to thei
| |
| 54 if ret != 0: | |
| 55 print "Failed compiling the integration_tests using clang-cl" | |
| 56 return ret | |
| 57 | |
| 58 | |
| 59 def link(clang_path, source_files, build_dir): | |
| 60 """ Links the object files and produces the integration_tests_clang_dll.dll. | |
| 61 | |
| 62 | |
| 63 Links the object files and produces the dll. The object files have to be | |
| 64 produced by the compile method above. | |
| 65 | |
| 66 Args: | |
| 67 clang_path: Path to the clang-cl compiler in the syzygy project. | |
| 68 source_files: The source file names which are converted to obj filenames. | |
| 69 build_dir: The directory where to produce the linked dll. | |
| 70 """ | |
| 71 object_files = ([os.path.splitext(filename)[0] + | |
| 72 ".o" for filename in source_files]) | |
| 73 | |
| 74 compiler_controlled_linker_flags = [ | |
|
Sébastien Marchand
2017/06/23 18:01:54
this name is confusing, why not just call it linke
| |
| 75 '-o', | |
| 76 (build_dir, '\integration_tests_clang_dll.dll') | |
| 77 ] | |
| 78 | |
| 79 linker_flags = [ | |
| 80 '/link', | |
| 81 '/dll', | |
| 82 build_dir + '\export_dll.dll.lib', | |
| 83 build_dir + '\syzyasan_rtl.dll.lib', | |
| 84 '-defaultlib:libcmt' | |
| 85 ] | |
| 86 | |
| 87 linker_command = [clang_path, '-m32'] | |
| 88 linker_command.extend(object_files) | |
| 89 linker_command.extend(compiler_controlled_linker_flags) | |
| 90 linker_command.extend(linker_flags) | |
| 91 ret = subprocess.call(linker_command) | |
| 92 | |
| 93 if ret != 0: | |
| 94 print "Failed to link the integration_tests using clang-cl" | |
| 95 return ret | |
| 96 | |
| 97 | |
| 98 def main(): | |
| 99 parser = optparse.OptionParser(usage='%prog [options]') | |
| 100 parser.add_option('--build-dir', | |
| 101 help='Path to the Syzygy Release directory.') | |
| 102 parser.add_option('--input-files', help='files to be compiled and linked') | |
| 103 | |
| 104 options, _ = parser.parse_args() | |
| 105 | |
| 106 if not options.build_dir: | |
| 107 parser.error('--build-dir is required') | |
| 108 if not options.input_files: | |
| 109 parser.error('--input-files is required') | |
|
Sébastien Marchand
2017/06/23 18:01:54
Could you add a "target-name" flag and use it ever
| |
| 110 | |
| 111 source_files = options.input_files.split() | |
| 112 | |
| 113 ret = compile_with_asan(_CLANG_CL_PATH, source_files, _SRC_DIR) | |
| 114 if ret == 0: | |
| 115 ret = link(_CLANG_CL_PATH, source_files, options.build_dir) | |
| 116 else: | |
| 117 print "Compilation of integration_tests_clang_dll failed." | |
|
Sébastien Marchand
2017/06/23 18:01:54
Add "ERROR" at the beginning of this line, so it'l
| |
| 118 print "Skipping link step." | |
|
Sébastien Marchand
2017/06/23 18:01:54
Print these 2 messages on the same line.
| |
| 119 | |
| 120 return ret | |
| 121 | |
| 122 | |
| 123 if __name__ == '__main__': | |
| 124 sys.exit(main()) | |
| OLD | NEW |