def test_distributed_lto_common_objs(self): with named_directory() as d, working_directory(d): _create_inputs(d) os.makedirs('obj') subprocess.check_call([ self.clangcl(), '-c', '-Os', '-flto=thin', 'main.cpp', '-Foobj/main.obj' ]) subprocess.check_call([ self.clangcl(), '-c', '-Os', '-flto=thin', 'foo.cpp', '-Foobj/foo.obj' ]) subprocess.check_call([ self.clangcl(), '-c', '-Os', '-flto=thin', 'bar.cpp', '-Foobj/bar.obj' ]) subprocess.check_call([ 'llvm-ar', 'crsT', 'obj/foobar.lib', 'obj/bar.obj', 'obj/foo.obj' ]) with open('main.rsp', 'w') as f: f.write('obj/main.obj\n' 'obj/foobar.lib\n') with open('my_goma.sh', 'w') as f: f.write('#! /bin/sh\n\ngomacc "$@"\n') os.chmod('my_goma.sh', 0o755) rc = goma_link.GomaLinkWindows().main([ 'goma_link.py', '--gomacc', './my_goma.sh', '--', self.lld_link(), '-nodefaultlib', '-entry:main', '-out:main.exe', '@main.rsp' ]) # Should succeed. self.assertEqual(rc, 0) # Check codegen parameters. with open(os.path.join(d, 'lto.main.exe', 'build.ninja')) as f: buildrules = f.read() codegen_match = re.search('^rule codegen\\b.*?^[^ ]', buildrules, re.MULTILINE | re.DOTALL) self.assertIsNotNone(codegen_match) codegen_text = codegen_match.group(0) self.assertIn('my_goma.sh', codegen_text) self.assertNotIn('-flto', codegen_text) self.assertIn( 'build common_objs/obj/main.obj.stamp : codegen ', buildrules) self.assertIn('build common_objs/obj/foo.obj.stamp : codegen ', buildrules) self.assertIn(' index = common_objs/empty.thinlto.bc', buildrules) link_match = re.search( '^build main.exe : native-link\\b.*?^[^ ]', buildrules, re.MULTILINE | re.DOTALL) self.assertIsNotNone(link_match) link_text = link_match.group(0) self.assertNotIn('main.exe.split.obj', link_text) # Check that main does not call foo. disasm = subprocess.check_output( ['llvm-objdump', '-d', 'main.exe']) # There are no symbols in the disassembly, but we're expecting two # functions, one of which calls the other. self.assertTrue(b'call' in disasm or b'jmp' in disasm)
def test_codegen_params_explicit_data_and_function_sections_cl(self): with FakeFs(bitcode_files=['foo.obj'], other_files=['bar.obj']): result = goma_link.GomaLinkWindows().analyze_expanded_args( ['clang-cl', '/Gy', '-Gw', 'foo.obj', 'bar.obj', '/Fefoo.exe'], 'foo.exe', 'clang-cl', 'lto.foo', 'common', False) self.assertIn('-Gw', result.codegen_params) self.assertIn('/Gy', result.codegen_params) self.assertNotIn('-fdata-sections', result.codegen_params) self.assertNotIn('-ffunction-sections', result.codegen_params)
def test_codegen_params_default_cl(self): with FakeFs(bitcode_files=['foo.obj'], other_files=['bar.obj']): result = goma_link.GomaLinkWindows().analyze_expanded_args( ['clang-cl', 'foo.obj', 'bar.obj', '-Fefoo.exe'], 'foo.exe', 'clang-cl', 'lto.foo', 'common', False) # Codegen optimization level should default to 2. self.assertIn('-O2', result.codegen_params) # -Gw and -Gy default to on to match the behavior of local linking. self.assertIn('-Gw', result.codegen_params) self.assertIn('-Gy', result.codegen_params)
def test_override_allowlist(self): with named_directory() as d, working_directory(d): _create_inputs(d) os.makedirs('obj') subprocess.check_call([ self.clangcl(), '-c', '-O2', '-flto=thin', 'main.cpp', '-Foobj/main.obj' ]) subprocess.check_call([ self.clangcl(), '-c', '-O2', '-flto=thin', 'foo.cpp', '-Foobj/foo.obj' ]) rc = goma_link.GomaLinkWindows().main([ 'goma_link.py', '--generate', '--allowlist', '--', self.lld_link(), '-nodefaultlib', '-entry:main', '-opt:lldlto=2', '-out:main.exe', 'obj/main.obj', 'obj/foo.obj' ]) # Should succeed. self.assertEqual(rc, 0) # Check that we have rules for main and foo, and that they are # not common objects. with open(os.path.join(d, 'lto.main.exe', 'build.ninja')) as f: buildrules = f.read() codegen_match = re.search(r'^rule codegen\b.*?^[^ ]', buildrules, re.MULTILINE | re.DOTALL) self.assertIsNotNone(codegen_match) codegen_text = codegen_match.group(0) self.assertNotIn('-flto', codegen_text) self.assertIn( 'build lto.main.exe/obj/main.obj.stamp : codegen ', buildrules) self.assertIn( 'build lto.main.exe/obj/foo.obj.stamp : codegen ', buildrules) link_match = re.search( r'^build main.exe : native-link\b.*?^[^ ]', buildrules, re.MULTILINE | re.DOTALL) self.assertIsNotNone(link_match)