diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2022-08-15 14:48:32 -0700 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2022-09-02 13:40:05 +0530 |
commit | 5e1ab20a89b7864c3a950278e379e51a17294d4e (patch) | |
tree | 63d1709a244e5b078b374bde6c16f2e45ef53fe8 | |
parent | c6656793cc4d0af0557492d825ed1e257577a464 (diff) | |
download | meson-5e1ab20a89b7864c3a950278e379e51a17294d4e.zip meson-5e1ab20a89b7864c3a950278e379e51a17294d4e.tar.gz meson-5e1ab20a89b7864c3a950278e379e51a17294d4e.tar.bz2 |
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.
-rw-r--r-- | mesonbuild/build.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 5dab210..5e7e933 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1460,11 +1460,13 @@ You probably should put it in link_with instead.''') raise InvalidArguments(msg + ' This is not possible in a cross build.') else: mlog.warning(msg + ' This will fail in cross build.') + # When we're a static library and we link_whole: to another static + # library, we need to add that target's objects to ourselves. + # Otherwise add it to the link_whole_targets, but not both. if isinstance(self, StaticLibrary): - # When we're a static library and we link_whole: to another static - # library, we need to add that target's objects to ourselves. self.objects += t.extract_all_objects_recurse() - self.link_whole_targets.append(t) + else: + self.link_whole_targets.append(t) def extract_all_objects_recurse(self) -> T.List[T.Union[str, 'ExtractedObjects']]: objs = [self.extract_all_objects()] |