Skip to content

Commit 4d1bfd0

Browse files
committed
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.
1 parent 46f3cff commit 4d1bfd0

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

mesonbuild/compilers/mixins/clike.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def to_native(self, copy: bool = False) -> T.List[str]:
8484
if group_start < 0:
8585
# First occurrence of a library
8686
group_start = i
87-
if group_start >= 0:
87+
# Only add groups if there are multiple libraries.
88+
if group_end > group_start >= 0:
8889
# Last occurrence of a library
8990
new.insert(group_end + 1, '-Wl,--end-group')
9091
new.insert(group_start, '-Wl,--start-group')

mesonbuild/linkers/linkers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ def __init__(self, for_machine: mesonlib.MachineChoice,
978978
version=version)
979979

980980
def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
981-
if not args:
981+
if len(args) < 2:
982982
return args
983983
return self._apply_prefix('--start-group') + args + self._apply_prefix('--end-group')
984984

@@ -1064,7 +1064,7 @@ def __init__(self, exelist: T.List[str], for_machine: mesonlib.MachineChoice,
10641064
version=version)
10651065

10661066
def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
1067-
if not args:
1067+
if len(args) < 2:
10681068
return args
10691069
return self._apply_prefix('--start-group') + args + self._apply_prefix('--end-group')
10701070

unittests/internaltests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def test_compiler_args_class_gnuld(self):
241241
gcc.get_default_include_dirs = lambda: ['/usr/include', '/usr/share/include', '/usr/local/include']
242242
## Test that 'direct' append and extend works
243243
l = gcc.compiler_args(['-Lfoodir', '-lfoo'])
244-
self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-Wl,--start-group', '-lfoo', '-Wl,--end-group'])
244+
self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-lfoo'])
245245
# Direct-adding a library and a libpath appends both correctly
246246
l.extend_direct(['-Lbardir', '-lbar'])
247247
self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-Wl,--start-group', '-lfoo', '-Lbardir', '-lbar', '-Wl,--end-group'])
@@ -269,10 +269,10 @@ def test_compiler_args_remove_system(self):
269269
gcc.get_default_include_dirs = lambda: ['/usr/include', '/usr/share/include', '/usr/local/include']
270270
## Test that 'direct' append and extend works
271271
l = gcc.compiler_args(['-Lfoodir', '-lfoo'])
272-
self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-Wl,--start-group', '-lfoo', '-Wl,--end-group'])
272+
self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-lfoo'])
273273
## Test that to_native removes all system includes
274274
l += ['-isystem/usr/include', '-isystem=/usr/share/include', '-DSOMETHING_IMPORTANT=1', '-isystem', '/usr/local/include']
275-
self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-Wl,--start-group', '-lfoo', '-Wl,--end-group', '-DSOMETHING_IMPORTANT=1'])
275+
self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-lfoo', '-DSOMETHING_IMPORTANT=1'])
276276

277277
def test_string_templates_substitution(self):
278278
dictfunc = mesonbuild.mesonlib.get_filenames_templates_dict

0 commit comments

Comments
 (0)