Skip to content

Commit

Permalink
cc link puts target_linkflags into rspfile to resolve --whole-archive…
Browse files Browse the repository at this point in the history
… input exceed maximal length of bash (#1049)

* put target_linkflags into rspfile to resolve --whole-archive input too long
---------
Co-authored-by: jefferydeng <jefferydeng@tencent.com>
  • Loading branch information
noanswer authored Dec 27, 2024
1 parent 3c42452 commit de255d4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/blade/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,17 @@ def _generate_cc_link_rules(self, ld, linkflags):
# Linking might have a lot of object files exceeding maximal length of a bash command line.
# Using response file can resolve this problem.
# Refer to: https://ninja-build.org/manual.html
link_args = '-o ${out} ${intrinsic_linkflags} ${linkflags} ${target_linkflags} @${out}.rsp ${extra_linkflags}'
link_args = '-o ${out} ${intrinsic_linkflags} ${linkflags} @${out}.rsp ${extra_linkflags}'
self.generate_rule(name='link',
command=ld + ' ' + link_args,
rspfile='${out}.rsp',
rspfile_content='${in}',
rspfile_content='${target_linkflags} ${in}',
description='LINK BINARY ${out}',
pool=pool)
self.generate_rule(name='solink',
command=ld + ' -shared ' + link_args,
rspfile='${out}.rsp',
rspfile_content='${in}',
rspfile_content='${target_linkflags} ${in}',
description='LINK SHARED ${out}',
pool=pool)

Expand Down
2 changes: 1 addition & 1 deletion src/test/blade_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def assertNoWarningCxxFlags(self, cmdline):
self._assertCxxNoWarningFlags(cmdline)

def assertLinkFlags(self, cmdline):
self.assertIn('-static-libgcc -static-libstdc++', cmdline)
self.assertNotIn('-static-libgcc -static-libstdc++', cmdline)

def assertStaticLinkFlags(self, cmdline):
self.assertNotIn('-shared', cmdline)
Expand Down
4 changes: 2 additions & 2 deletions src/test/cc_binary_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def testGenerateRules(self):
self.assertCxxFlags(com_string_line)

self.assertLinkFlags(string_main_depends_libs)
self.assertIn('liblowercase.a', string_main_depends_libs)
self.assertIn('libuppercase.a', string_main_depends_libs)
self.assertNotIn('liblowercase.a', string_main_depends_libs)
self.assertNotIn('libuppercase.a', string_main_depends_libs)
self.assertTrue(self.findCommand(['Hello, world']))


Expand Down
4 changes: 2 additions & 2 deletions src/test/cc_plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def testGenerateRules(self):

self.assertDynamicLinkFlags(string_plugin_depends_libs)
self.assertIn('-Wl,-Bsymbolic', string_plugin_depends_libs)
self.assertIn('liblowercase.a', string_plugin_depends_libs)
self.assertIn('libuppercase.a', string_plugin_depends_libs)
self.assertNotIn('liblowercase.a', string_plugin_depends_libs)
self.assertNotIn('libuppercase.a', string_plugin_depends_libs)


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions src/test/cc_test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def testGenerateRules(self):
self.assertCxxFlags(com_string_line)

self.assertLinkFlags(string_main_depends_libs)
self.assertIn('liblowercase.a', string_main_depends_libs)
self.assertIn('libuppercase.a', string_main_depends_libs)
self.assertNotIn('liblowercase.a', string_main_depends_libs)
self.assertNotIn('libuppercase.a', string_main_depends_libs)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion src/test/test_target_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def testTestRunnerCorrectly(self):
self.assertCxxFlags(com_string_line)

self.assertLinkFlags(string_main_depends_libs)
self.assertIn('liblowercase.a', string_main_depends_libs)
self.assertNotIn('liblowercase.a', string_main_depends_libs)


if __name__ == '__main__':
Expand Down

0 comments on commit de255d4

Please sign in to comment.