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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 for source_file, object_file in zip(source_files, object_files): | 58 for source_file, object_file in zip(source_files, object_files): |
59 compile_command = list(compile_command_base) | 59 compile_command = list(compile_command_base) |
60 compile_command.extend([source_file, '-o', object_file]) | 60 compile_command.extend([source_file, '-o', object_file]) |
61 ret = subprocess.call(compile_command) | 61 ret = subprocess.call(compile_command) |
62 if ret != 0: | 62 if ret != 0: |
63 print 'ERROR: Failed compiling %s using clang-cl.' % target_name | 63 print 'ERROR: Failed compiling %s using clang-cl.' % target_name |
64 return ret | 64 return ret |
65 return ret | 65 return ret |
66 | 66 |
67 | 67 |
68 def link(clang_path, object_files, build_dir, target_name): | 68 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. | 69 """ Links the object files and produces the integration_tests_clang_dll.dll. |
70 | 70 |
71 Links the object files and produces the dll. The object files have to be | 71 Links the object files and produces the dll. The object files have to be |
72 produced by the compile method above. | 72 produced by the compile method above. |
73 | 73 |
74 Args: | 74 Args: |
75 clang_path: Path to the clang-cl compiler in the syzygy project. | 75 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. | 76 source_files: The source file names which are converted to obj filenames. |
77 build_dir: The directory where to produce the linked dll. | 77 build_dir: The directory where to produce the linked dll. |
78 target_name: The name of the target being build. | 78 target_name: The name of the target being build. |
79 """ | 79 """ |
80 | 80 |
81 linker_flags = [ | 81 linker_flags = [ |
82 '-o', | 82 '-o', |
83 os.path.join(build_dir, target_name + '.dll'), | 83 os.path.join(build_dir, target_name + '.dll'), |
84 '/link', | 84 '/link', |
85 '/dll', | 85 '/dll', |
86 os.path.join(build_dir, 'export_dll.dll.lib'), | 86 os.path.join(build_dir, 'export_dll.dll.lib'), |
87 os.path.join(build_dir, 'syzyasan_rtl.dll.lib'), | 87 os.path.join(build_dir, 'syzyasan_rtl.dll.lib'), |
88 '-defaultlib:libcmt' | 88 '-defaultlib:libcmt', |
89 '/debug:full', | |
Sébastien Marchand
2017/07/19 15:27:26
You also need to specify /Zi during the compile st
| |
90 '/def:' + def_file, | |
89 ] | 91 ] |
90 | 92 |
91 linker_command = [clang_path, '-m32'] | 93 linker_command = [clang_path, '-m32'] |
92 linker_command.extend(object_files) | 94 linker_command.extend(object_files) |
93 linker_command.extend(linker_flags) | 95 linker_command.extend(linker_flags) |
96 print linker_command | |
Sébastien Marchand
2017/07/19 15:27:26
Remove the debugging code.
njanevsk
2017/07/19 16:00:35
Done.
| |
94 ret = subprocess.call(linker_command) | 97 ret = subprocess.call(linker_command) |
95 | 98 |
96 if ret != 0: | 99 if ret != 0: |
97 print 'ERROR: Failed to link %s using clang-cl.' % target_name | 100 print 'ERROR: Failed to link %s using clang-cl.' % target_name |
98 return ret | 101 return ret |
99 | 102 |
100 | 103 |
101 def main(): | 104 def main(): |
102 parser = optparse.OptionParser(usage='%prog [options]') | 105 parser = optparse.OptionParser(usage='%prog [options]') |
103 parser.add_option('--output-dir', | 106 parser.add_option('--output-dir', |
104 help='Path to the Syzygy Release directory.') | 107 help='Path to the Syzygy Release directory.') |
105 parser.add_option('--input-files', help='Files to be compiled and linked.') | 108 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.') | 109 parser.add_option('--target-name', help='Name of the target to be compiled.') |
110 parser.add_option('--def-file', help='Definition file for the dll.') | |
107 | 111 |
108 options, _ = parser.parse_args() | 112 options, _ = parser.parse_args() |
109 | 113 |
110 if not options.output_dir: | 114 if not options.output_dir: |
111 parser.error('--output-dir is required.') | 115 parser.error('--output-dir is required.') |
112 if not options.input_files: | 116 if not options.input_files: |
113 parser.error('--input-files is required.') | 117 parser.error('--input-files is required.') |
114 if not options.target_name: | 118 if not options.target_name: |
115 parser.error('--target-name is required.') | 119 parser.error('--target-name is required.') |
120 if not options.def_file: | |
121 parser.error('--def-file is required.') | |
116 | 122 |
117 def get_object_file_location(source_file, | 123 def get_object_file_location(source_file, |
118 output_dir, target_name): | 124 output_dir, target_name): |
119 return os.path.join(output_dir, 'obj', | 125 return os.path.join(output_dir, 'obj', |
120 os.path.dirname(os.path.relpath(source_file, _SRC_DIR)), | 126 os.path.dirname(os.path.relpath(source_file, _SRC_DIR)), |
121 '%s.%s.obj' % (target_name, | 127 '%s.%s.obj' % (target_name, |
122 os.path.splitext(os.path.basename(source_file))[0])) | 128 os.path.splitext(os.path.basename(source_file))[0])) |
123 | 129 |
124 source_files = options.input_files.split() | 130 source_files = options.input_files.split() |
125 object_files = [] | 131 object_files = [] |
126 | 132 |
127 for source_file in source_files: | 133 for source_file in source_files: |
128 object_files.append(get_object_file_location(source_file, | 134 object_files.append(get_object_file_location(source_file, |
129 options.output_dir, | 135 options.output_dir, |
130 options.target_name)) | 136 options.target_name)) |
131 | 137 |
132 ret = compile_with_asan(_CLANG_CL_PATH, source_files, _SRC_DIR, | 138 ret = compile_with_asan(_CLANG_CL_PATH, source_files, _SRC_DIR, |
133 object_files, options.target_name) | 139 object_files, options.target_name) |
134 | 140 |
135 if ret == 0: | 141 if ret == 0: |
136 ret = link(_CLANG_CL_PATH, object_files, options.output_dir, | 142 ret = link(_CLANG_CL_PATH, object_files, options.output_dir, |
137 options.target_name) | 143 options.target_name, options.def_file) |
138 else: | 144 else: |
139 print ('ERROR: Compilation of %s failed, skipping link step.' | 145 print ('ERROR: Compilation of %s failed, skipping link step.' |
140 % options.target_name) | 146 % options.target_name) |
141 | 147 |
142 return ret | 148 return ret |
143 | 149 |
144 | 150 |
145 if __name__ == '__main__': | 151 if __name__ == '__main__': |
146 sys.exit(main()) | 152 sys.exit(main()) |
OLD | NEW |