Skip to content

Commit c94c492

Browse files
dcbakereli-schwartz
authored andcommitted
build: don't add targets to link_whole_targets if we took their objects
What happens is this: - liba is a convenience static library - libb is an installed static library - libb links in liba with --link-whole - libc links to libb - we generate a link line with libb *and* liba, even though libb is a strict superset of liba This is a bug that has existed since the we stopped using link-whole to combine convenience libraries, and to instead propagate their dependencies up. For most linkers this is harmless, if inefficient. However, for apple's ld64 with the addition calling `ranlib -c`, this ends up causing multiple copies of symbols to clash (I think that other linkers recognize that these symbols are the same and combine them), and linking to fail. The fix is to stop adding libraries to a target's `link_whole_targets` when we take its objects instead. This is an all around win since it fixes this bug, shortens linker command lines, and avoids opening archives that no new symbols will be found in anyway.
1 parent c02d7fe commit c94c492

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

mesonbuild/build.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,11 +1466,13 @@ def link_whole(self, target):
14661466
raise InvalidArguments(msg + ' This is not possible in a cross build.')
14671467
else:
14681468
mlog.warning(msg + ' This will fail in cross build.')
1469+
# When we're a static library and we link_whole: to another static
1470+
# library, we need to add that target's objects to ourselves.
1471+
# Otherwise add it to the link_whole_targets, but not both.
14691472
if isinstance(self, StaticLibrary):
1470-
# When we're a static library and we link_whole: to another static
1471-
# library, we need to add that target's objects to ourselves.
14721473
self.objects += t.extract_all_objects_recurse()
1473-
self.link_whole_targets.append(t)
1474+
else:
1475+
self.link_whole_targets.append(t)
14741476

14751477
def extract_all_objects_recurse(self) -> T.List[T.Union[str, 'ExtractedObjects']]:
14761478
objs = [self.extract_all_objects()]

0 commit comments

Comments
 (0)