Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame^] | 1 | From dbc9e971bd320f3df15c1ee74f54858e6792b183 Mon Sep 17 00:00:00 2001 |
| 2 | From: Xavier Claessens <xavier.claessens@collabora.com> |
| 3 | Date: Fri, 11 Oct 2019 11:01:22 -0400 |
| 4 | Subject: [PATCH] Remove duplicated object files in static libraries |
| 5 | |
| 6 | When a static library link_whole to a bunch of other static libraries, |
| 7 | we have to extract all their objects recursively. But that could |
| 8 | introduce duplicated objects. ar is dumb enough to allow this without |
| 9 | error, but once the resulting static library is linked into an |
| 10 | executable or shared library, the linker will complain about duplicated |
| 11 | symbols. |
| 12 | |
| 13 | Upstream-Status: Backport |
| 14 | Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> |
| 15 | |
| 16 | --- |
| 17 | mesonbuild/backend/backends.py | 3 ++- |
| 18 | test cases/unit/69 static link/lib/func17.c | 4 ++++ |
| 19 | test cases/unit/69 static link/lib/func18.c | 6 ++++++ |
| 20 | test cases/unit/69 static link/lib/func19.c | 7 +++++++ |
| 21 | test cases/unit/69 static link/lib/meson.build | 12 ++++++++++++ |
| 22 | 5 files changed, 31 insertions(+), 1 deletion(-) |
| 23 | create mode 100644 test cases/unit/69 static link/lib/func17.c |
| 24 | create mode 100644 test cases/unit/69 static link/lib/func18.c |
| 25 | create mode 100644 test cases/unit/69 static link/lib/func19.c |
| 26 | |
| 27 | diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py |
| 28 | index 947be1cbef..e54809657f 100644 |
| 29 | --- a/mesonbuild/backend/backends.py |
| 30 | +++ b/mesonbuild/backend/backends.py |
| 31 | @@ -281,7 +281,8 @@ def relpath(self, todir, fromdir): |
| 32 | os.path.join('dummyprefixdir', fromdir)) |
| 33 | |
| 34 | def flatten_object_list(self, target, proj_dir_to_build_root=''): |
| 35 | - return self._flatten_object_list(target, target.get_objects(), proj_dir_to_build_root) |
| 36 | + obj_list = self._flatten_object_list(target, target.get_objects(), proj_dir_to_build_root) |
| 37 | + return list(dict.fromkeys(obj_list)) |
| 38 | |
| 39 | def _flatten_object_list(self, target, objects, proj_dir_to_build_root): |
| 40 | obj_list = [] |
| 41 | diff --git a/test cases/unit/69 static link/lib/func17.c b/test cases/unit/69 static link/lib/func17.c |
| 42 | new file mode 100644 |
| 43 | index 0000000000..d1d8ec498c |
| 44 | --- /dev/null |
| 45 | +++ b/test cases/unit/69 static link/lib/func17.c |
| 46 | @@ -0,0 +1,4 @@ |
| 47 | +int func17() |
| 48 | +{ |
| 49 | + return 1; |
| 50 | +} |
| 51 | diff --git a/test cases/unit/69 static link/lib/func18.c b/test cases/unit/69 static link/lib/func18.c |
| 52 | new file mode 100644 |
| 53 | index 0000000000..c149085ba4 |
| 54 | --- /dev/null |
| 55 | +++ b/test cases/unit/69 static link/lib/func18.c |
| 56 | @@ -0,0 +1,6 @@ |
| 57 | +int func17(); |
| 58 | + |
| 59 | +int func18() |
| 60 | +{ |
| 61 | + return func17() + 1; |
| 62 | +} |
| 63 | diff --git a/test cases/unit/69 static link/lib/func19.c b/test cases/unit/69 static link/lib/func19.c |
| 64 | new file mode 100644 |
| 65 | index 0000000000..69120e4bf8 |
| 66 | --- /dev/null |
| 67 | +++ b/test cases/unit/69 static link/lib/func19.c |
| 68 | @@ -0,0 +1,7 @@ |
| 69 | +int func17(); |
| 70 | +int func18(); |
| 71 | + |
| 72 | +int func19() |
| 73 | +{ |
| 74 | + return func17() + func18(); |
| 75 | +} |
| 76 | diff --git a/test cases/unit/69 static link/lib/meson.build b/test cases/unit/69 static link/lib/meson.build |
| 77 | index 5f04aab6a1..8f95fc4546 100644 |
| 78 | --- a/test cases/unit/69 static link/lib/meson.build |
| 79 | +++ b/test cases/unit/69 static link/lib/meson.build |
| 80 | @@ -66,3 +66,15 @@ libfunc15 = static_library('func15', 'func15.c', |
| 81 | libfunc16 = static_library('func16', 'func16.c', |
| 82 | link_with : libfunc15, |
| 83 | install : true) |
| 84 | + |
| 85 | +# Verify func17.c.o gets included only once into libfunc19, otherwise |
| 86 | +# func19-shared would failed with duplicated symbol. |
| 87 | +libfunc17 = static_library('func17', 'func17.c', |
| 88 | + install : false) |
| 89 | +libfunc18 = static_library('func18', 'func18.c', |
| 90 | + link_with : libfunc17, |
| 91 | + install : false) |
| 92 | +libfunc19 = static_library('func19', 'func19.c', |
| 93 | + link_whole : [libfunc17, libfunc18], |
| 94 | + install : false) |
| 95 | +shared_library('func19-shared', link_whole : [libfunc19]) |