compilers: only wrap multiple input libraries with start/end group

When only a single input file shows up in an arglist, it makes no sense
to inject `-W,--start-group -lone -Wl,--end-group`, since there is
nothing being grouped together. It's just longer command lines for
nothing.
pull/12910/head
Eli Schwartz 11 months ago
parent 46f3cff5b2
commit 4d1bfd0939
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 3
      mesonbuild/compilers/mixins/clike.py
  2. 4
      mesonbuild/linkers/linkers.py
  3. 6
      unittests/internaltests.py

@ -84,7 +84,8 @@ class CLikeCompilerArgs(arglist.CompilerArgs):
if group_start < 0:
# First occurrence of a library
group_start = i
if group_start >= 0:
# Only add groups if there are multiple libraries.
if group_end > group_start >= 0:
# Last occurrence of a library
new.insert(group_end + 1, '-Wl,--end-group')
new.insert(group_start, '-Wl,--start-group')

@ -978,7 +978,7 @@ class Xc16DynamicLinker(DynamicLinker):
version=version)
def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
if not args:
if len(args) < 2:
return args
return self._apply_prefix('--start-group') + args + self._apply_prefix('--end-group')
@ -1064,7 +1064,7 @@ class TIDynamicLinker(DynamicLinker):
version=version)
def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
if not args:
if len(args) < 2:
return args
return self._apply_prefix('--start-group') + args + self._apply_prefix('--end-group')

@ -241,7 +241,7 @@ class InternalTests(unittest.TestCase):
gcc.get_default_include_dirs = lambda: ['/usr/include', '/usr/share/include', '/usr/local/include']
## Test that 'direct' append and extend works
l = gcc.compiler_args(['-Lfoodir', '-lfoo'])
self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-Wl,--start-group', '-lfoo', '-Wl,--end-group'])
self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-lfoo'])
# Direct-adding a library and a libpath appends both correctly
l.extend_direct(['-Lbardir', '-lbar'])
self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-Wl,--start-group', '-lfoo', '-Lbardir', '-lbar', '-Wl,--end-group'])
@ -269,10 +269,10 @@ class InternalTests(unittest.TestCase):
gcc.get_default_include_dirs = lambda: ['/usr/include', '/usr/share/include', '/usr/local/include']
## Test that 'direct' append and extend works
l = gcc.compiler_args(['-Lfoodir', '-lfoo'])
self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-Wl,--start-group', '-lfoo', '-Wl,--end-group'])
self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-lfoo'])
## Test that to_native removes all system includes
l += ['-isystem/usr/include', '-isystem=/usr/share/include', '-DSOMETHING_IMPORTANT=1', '-isystem', '/usr/local/include']
self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-Wl,--start-group', '-lfoo', '-Wl,--end-group', '-DSOMETHING_IMPORTANT=1'])
self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-lfoo', '-DSOMETHING_IMPORTANT=1'])
def test_string_templates_substitution(self):
dictfunc = mesonbuild.mesonlib.get_filenames_templates_dict

Loading…
Cancel
Save