OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 """A script to compile the integration tests with llvm's clang, | 5 """A script to compile the integration tests with llvm's clang, |
6 instrument the code with llvm's Asan, and link it to the syzyasan_rtl | 6 instrument the code with llvm's Asan, and link it to the syzyasan_rtl |
7 runtime environment. | 7 runtime environment. |
8 """ | 8 """ |
9 | 9 |
10 import optparse | 10 import optparse |
(...skipping 30 matching lines...) Expand all Loading... |
41 '-m32', | 41 '-m32', |
42 '-fsanitize=address', | 42 '-fsanitize=address', |
43 '-mllvm', | 43 '-mllvm', |
44 '-asan-instrumentation-with-call-threshold=0', | 44 '-asan-instrumentation-with-call-threshold=0', |
45 '-mllvm', | 45 '-mllvm', |
46 '-asan-stack=0', | 46 '-asan-stack=0', |
47 '-DUNICODE', | 47 '-DUNICODE', |
48 '-D_UNICODE', | 48 '-D_UNICODE', |
49 '-DNOMINMAX', | 49 '-DNOMINMAX', |
50 '-D_CRT_SECURE_NO_WARNINGS', | 50 '-D_CRT_SECURE_NO_WARNINGS', |
| 51 '/Zi', |
51 '-I', | 52 '-I', |
52 src_dir, | 53 src_dir, |
53 ] | 54 ] |
54 | 55 |
55 compile_command_base = [clang_path] | 56 compile_command_base = [clang_path] |
56 compile_command_base.extend(compiler_flags) | 57 compile_command_base.extend(compiler_flags) |
57 | 58 |
58 for source_file, object_file in zip(source_files, object_files): | 59 for source_file, object_file in zip(source_files, object_files): |
59 compile_command = list(compile_command_base) | 60 compile_command = list(compile_command_base) |
60 compile_command.extend([source_file, '-o', object_file]) | 61 compile_command.extend([source_file, '-o', object_file]) |
61 ret = subprocess.call(compile_command) | 62 ret = subprocess.call(compile_command) |
62 if ret != 0: | 63 if ret != 0: |
63 print 'ERROR: Failed compiling %s using clang-cl.' % target_name | 64 print 'ERROR: Failed compiling %s using clang-cl.' % target_name |
64 return ret | 65 return ret |
65 return ret | 66 return ret |
66 | 67 |
67 | 68 |
68 def link(clang_path, object_files, build_dir, target_name): | 69 def link(clang_path, object_files, build_dir, target_name, def_file): |
69 """ Links the object files and produces the integration_tests_clang_dll.dll. | 70 """ Links the object files and produces the integration_tests_clang_dll.dll. |
70 | 71 |
71 Links the object files and produces the dll. The object files have to be | 72 Links the object files and produces the dll. The object files have to be |
72 produced by the compile method above. | 73 produced by the compile method above. |
73 | 74 |
74 Args: | 75 Args: |
75 clang_path: Path to the clang-cl compiler in the syzygy project. | 76 clang_path: Path to the clang-cl compiler in the syzygy project. |
76 source_files: The source file names which are converted to obj filenames. | 77 source_files: The source file names which are converted to obj filenames. |
77 build_dir: The directory where to produce the linked dll. | 78 build_dir: The directory where to produce the linked dll. |
78 target_name: The name of the target being build. | 79 target_name: The name of the target being build. |
79 """ | 80 """ |
80 | 81 |
81 linker_flags = [ | 82 linker_flags = [ |
82 '-o', | 83 '-o', |
83 os.path.join(build_dir, target_name + '.dll'), | 84 os.path.join(build_dir, target_name + '.dll'), |
84 '/link', | 85 '/link', |
85 '/dll', | 86 '/dll', |
86 os.path.join(build_dir, 'export_dll.dll.lib'), | 87 os.path.join(build_dir, 'export_dll.dll.lib'), |
87 os.path.join(build_dir, 'syzyasan_rtl.dll.lib'), | 88 os.path.join(build_dir, 'syzyasan_rtl.dll.lib'), |
88 '-defaultlib:libcmt' | 89 '-defaultlib:libcmt', |
| 90 '/debug', |
| 91 '/def:' + def_file, |
89 ] | 92 ] |
90 | 93 |
91 linker_command = [clang_path, '-m32'] | 94 linker_command = [clang_path, '-m32'] |
92 linker_command.extend(object_files) | 95 linker_command.extend(object_files) |
93 linker_command.extend(linker_flags) | 96 linker_command.extend(linker_flags) |
| 97 |
94 ret = subprocess.call(linker_command) | 98 ret = subprocess.call(linker_command) |
95 | 99 |
96 if ret != 0: | 100 if ret != 0: |
97 print 'ERROR: Failed to link %s using clang-cl.' % target_name | 101 print 'ERROR: Failed to link %s using clang-cl.' % target_name |
98 return ret | 102 return ret |
99 | 103 |
100 | 104 |
101 def main(): | 105 def main(): |
102 parser = optparse.OptionParser(usage='%prog [options]') | 106 parser = optparse.OptionParser(usage='%prog [options]') |
103 parser.add_option('--output-dir', | 107 parser.add_option('--output-dir', |
104 help='Path to the Syzygy Release directory.') | 108 help='Path to the Syzygy Release directory.') |
105 parser.add_option('--input-files', help='Files to be compiled and linked.') | 109 parser.add_option('--input-files', help='Files to be compiled and linked.') |
106 parser.add_option('--target-name', help='Name of the target to be compiled.') | 110 parser.add_option('--target-name', help='Name of the target to be compiled.') |
| 111 parser.add_option('--def-file', help='Definition file for the dll.') |
107 | 112 |
108 options, _ = parser.parse_args() | 113 options, _ = parser.parse_args() |
109 | 114 |
110 if not options.output_dir: | 115 if not options.output_dir: |
111 parser.error('--output-dir is required.') | 116 parser.error('--output-dir is required.') |
112 if not options.input_files: | 117 if not options.input_files: |
113 parser.error('--input-files is required.') | 118 parser.error('--input-files is required.') |
114 if not options.target_name: | 119 if not options.target_name: |
115 parser.error('--target-name is required.') | 120 parser.error('--target-name is required.') |
| 121 if not options.def_file: |
| 122 parser.error('--def-file is required.') |
116 | 123 |
117 def get_object_file_location(source_file, | 124 def get_object_file_location(source_file, |
118 output_dir, target_name): | 125 output_dir, target_name): |
119 return os.path.join(output_dir, 'obj', | 126 return os.path.join(output_dir, 'obj', |
120 os.path.dirname(os.path.relpath(source_file, _SRC_DIR)), | 127 os.path.dirname(os.path.relpath(source_file, _SRC_DIR)), |
121 '%s.%s.obj' % (target_name, | 128 '%s.%s.obj' % (target_name, |
122 os.path.splitext(os.path.basename(source_file))[0])) | 129 os.path.splitext(os.path.basename(source_file))[0])) |
123 | 130 |
124 source_files = options.input_files.split() | 131 source_files = options.input_files.split() |
125 object_files = [] | 132 object_files = [] |
126 | 133 |
127 for source_file in source_files: | 134 for source_file in source_files: |
128 object_files.append(get_object_file_location(source_file, | 135 object_files.append(get_object_file_location(source_file, |
129 options.output_dir, | 136 options.output_dir, |
130 options.target_name)) | 137 options.target_name)) |
131 | 138 |
132 ret = compile_with_asan(_CLANG_CL_PATH, source_files, _SRC_DIR, | 139 ret = compile_with_asan(_CLANG_CL_PATH, source_files, _SRC_DIR, |
133 object_files, options.target_name) | 140 object_files, options.target_name) |
134 | 141 |
135 if ret == 0: | 142 if ret == 0: |
136 ret = link(_CLANG_CL_PATH, object_files, options.output_dir, | 143 ret = link(_CLANG_CL_PATH, object_files, options.output_dir, |
137 options.target_name) | 144 options.target_name, options.def_file) |
138 else: | 145 else: |
139 print ('ERROR: Compilation of %s failed, skipping link step.' | 146 print ('ERROR: Compilation of %s failed, skipping link step.' |
140 % options.target_name) | 147 % options.target_name) |
141 | 148 |
142 return ret | 149 return ret |
143 | 150 |
144 | 151 |
145 if __name__ == '__main__': | 152 if __name__ == '__main__': |
146 sys.exit(main()) | 153 sys.exit(main()) |
OLD | NEW |