aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2019-10-11 11:01:22 -0400
committerJussi Pakkanen <jpakkane@gmail.com>2019-10-21 01:08:05 +0300
commit212a05b87ed34f921dfd07142305389dbfa9bb7d (patch)
treeeb6cea91360c05c4eaf0e9b591f271e8c94288a3
parentaece7ecded6f9113535c5b1c3e2f41056d3d041d (diff)
downloadmeson-212a05b87ed34f921dfd07142305389dbfa9bb7d.zip
meson-212a05b87ed34f921dfd07142305389dbfa9bb7d.tar.gz
meson-212a05b87ed34f921dfd07142305389dbfa9bb7d.tar.bz2
Remove duplicated object files in static libraries
When a static library link_whole to a bunch of other static libraries, we have to extract all their objects recursively. But that could introduce duplicated objects. ar is dumb enough to allow this without error, but once the resulting static library is linked into an executable or shared library, the linker will complain about duplicated symbols.
-rw-r--r--mesonbuild/backend/backends.py3
-rw-r--r--test cases/unit/69 static link/lib/func17.c4
-rw-r--r--test cases/unit/69 static link/lib/func18.c6
-rw-r--r--test cases/unit/69 static link/lib/func19.c7
-rw-r--r--test cases/unit/69 static link/lib/meson.build12
5 files changed, 31 insertions, 1 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index 947be1c..e548096 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -281,7 +281,8 @@ class Backend:
os.path.join('dummyprefixdir', fromdir))
def flatten_object_list(self, target, proj_dir_to_build_root=''):
- return self._flatten_object_list(target, target.get_objects(), proj_dir_to_build_root)
+ obj_list = self._flatten_object_list(target, target.get_objects(), proj_dir_to_build_root)
+ return list(dict.fromkeys(obj_list))
def _flatten_object_list(self, target, objects, proj_dir_to_build_root):
obj_list = []
diff --git a/test cases/unit/69 static link/lib/func17.c b/test cases/unit/69 static link/lib/func17.c
new file mode 100644
index 0000000..d1d8ec4
--- /dev/null
+++ b/test cases/unit/69 static link/lib/func17.c
@@ -0,0 +1,4 @@
+int func17()
+{
+ return 1;
+}
diff --git a/test cases/unit/69 static link/lib/func18.c b/test cases/unit/69 static link/lib/func18.c
new file mode 100644
index 0000000..c149085
--- /dev/null
+++ b/test cases/unit/69 static link/lib/func18.c
@@ -0,0 +1,6 @@
+int func17();
+
+int func18()
+{
+ return func17() + 1;
+}
diff --git a/test cases/unit/69 static link/lib/func19.c b/test cases/unit/69 static link/lib/func19.c
new file mode 100644
index 0000000..69120e4
--- /dev/null
+++ b/test cases/unit/69 static link/lib/func19.c
@@ -0,0 +1,7 @@
+int func17();
+int func18();
+
+int func19()
+{
+ return func17() + func18();
+}
diff --git a/test cases/unit/69 static link/lib/meson.build b/test cases/unit/69 static link/lib/meson.build
index 5f04aab..8f95fc4 100644
--- a/test cases/unit/69 static link/lib/meson.build
+++ b/test cases/unit/69 static link/lib/meson.build
@@ -66,3 +66,15 @@ libfunc15 = static_library('func15', 'func15.c',
libfunc16 = static_library('func16', 'func16.c',
link_with : libfunc15,
install : true)
+
+# Verify func17.c.o gets included only once into libfunc19, otherwise
+# func19-shared would failed with duplicated symbol.
+libfunc17 = static_library('func17', 'func17.c',
+ install : false)
+libfunc18 = static_library('func18', 'func18.c',
+ link_with : libfunc17,
+ install : false)
+libfunc19 = static_library('func19', 'func19.c',
+ link_whole : [libfunc17, libfunc18],
+ install : false)
+shared_library('func19-shared', link_whole : [libfunc19])