aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2017-07-21 06:07:51 +0530
committerJussi Pakkanen <jpakkane@gmail.com>2017-07-23 02:07:04 +0300
commitb3d048e93a55feaedadb1efae72de0b8871eefab (patch)
tree71fad319fa4d9516c5737f0b15e1f5ee2f823bcc
parent5f6add79e0759692dba272e60913c6401f2318ce (diff)
downloadmeson-b3d048e93a55feaedadb1efae72de0b8871eefab.zip
meson-b3d048e93a55feaedadb1efae72de0b8871eefab.tar.gz
meson-b3d048e93a55feaedadb1efae72de0b8871eefab.tar.bz2
CompilerArgs: Put start/end-group around shared libs too
Closes https://github.com/mesonbuild/meson/issues/2096
-rw-r--r--mesonbuild/compilers/compilers.py23
-rw-r--r--test cases/common/153 recursive linking/edge-cases/libsto.c8
-rw-r--r--test cases/common/153 recursive linking/edge-cases/meson.build9
-rw-r--r--test cases/common/153 recursive linking/edge-cases/shstmain.c16
-rw-r--r--test cases/common/153 recursive linking/edge-cases/stobuilt.c7
-rw-r--r--test cases/common/153 recursive linking/edge-cases/stomain.c16
-rw-r--r--test cases/common/153 recursive linking/meson.build3
-rw-r--r--test cases/common/153 recursive linking/shnodep/meson.build2
8 files changed, 75 insertions, 9 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 72e1ed3..77b3cb9 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -54,6 +54,9 @@ for _l in clike_langs:
clike_suffixes += lang_suffixes[_l]
clike_suffixes += ('h', 'll', 's')
+# XXX: Use this in is_library()?
+soregex = re.compile(r'.*\.so(\.[0-9]+)?(\.[0-9]+)?(\.[0-9]+)?$')
+
# All these are only for C-like languages; see `clike_langs` above.
def sort_clike(lang):
@@ -495,20 +498,24 @@ class CompilerArgs(list):
def to_native(self):
# Check if we need to add --start/end-group for circular dependencies
- # between static libraries.
+ # between static libraries, and for recursively searching for symbols
+ # needed by static libraries that are provided by object files or
+ # shared libraries.
if get_compiler_uses_gnuld(self.compiler):
- group_started = False
+ global soregex
+ group_start = -1
for each in self:
- if not each.startswith('-l') and not each.endswith('.a'):
+ if not each.startswith('-l') and not each.endswith('.a') and \
+ not soregex.match(each):
continue
i = self.index(each)
- if not group_started:
+ if group_start < 0:
# First occurance of a library
- self.insert(i, '-Wl,--start-group')
- group_started = True
- # Last occurance of a library
- if group_started:
+ group_start = i
+ if group_start >= 0:
+ # Last occurance of a library
self.insert(i + 1, '-Wl,--end-group')
+ self.insert(group_start, '-Wl,--start-group')
return self.compiler.unix_args_to_native(self)
def append_direct(self, arg):
diff --git a/test cases/common/153 recursive linking/edge-cases/libsto.c b/test cases/common/153 recursive linking/edge-cases/libsto.c
new file mode 100644
index 0000000..93f46a8
--- /dev/null
+++ b/test cases/common/153 recursive linking/edge-cases/libsto.c
@@ -0,0 +1,8 @@
+#include "../lib.h"
+
+int get_builto_value (void);
+
+SYMBOL_EXPORT
+int get_stodep_value (void) {
+ return get_builto_value ();
+}
diff --git a/test cases/common/153 recursive linking/edge-cases/meson.build b/test cases/common/153 recursive linking/edge-cases/meson.build
new file mode 100644
index 0000000..6a46266
--- /dev/null
+++ b/test cases/common/153 recursive linking/edge-cases/meson.build
@@ -0,0 +1,9 @@
+# Test https://github.com/mesonbuild/meson/issues/2096
+# Note that removing 'shnodep' from link_with: makes the error go away because
+# then it is added after the static library is added to the link command.
+test('shared-static', executable('shstexe', 'shstmain.c', link_with : [shnodep, stshdep]))
+
+# Static library that needs a symbol defined in an object file. This already
+# works, but good to add a test case early.
+stodep = static_library('stodep', 'libsto.c')
+test('stodep', executable('stodep', 'stomain.c', 'stobuilt.c', link_with : stodep))
diff --git a/test cases/common/153 recursive linking/edge-cases/shstmain.c b/test cases/common/153 recursive linking/edge-cases/shstmain.c
new file mode 100644
index 0000000..b44c55f
--- /dev/null
+++ b/test cases/common/153 recursive linking/edge-cases/shstmain.c
@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+#include "../lib.h"
+
+int get_stshdep_value (void);
+
+int main(int argc, char *argv[]) {
+ int val;
+
+ val = get_stshdep_value ();
+ if (val != 1) {
+ printf("st1 value was %i instead of 1\n", val);
+ return -1;
+ }
+ return 0;
+}
diff --git a/test cases/common/153 recursive linking/edge-cases/stobuilt.c b/test cases/common/153 recursive linking/edge-cases/stobuilt.c
new file mode 100644
index 0000000..9cc15bc
--- /dev/null
+++ b/test cases/common/153 recursive linking/edge-cases/stobuilt.c
@@ -0,0 +1,7 @@
+#include "../lib.h"
+
+
+SYMBOL_EXPORT
+int get_builto_value (void) {
+ return 1;
+}
diff --git a/test cases/common/153 recursive linking/edge-cases/stomain.c b/test cases/common/153 recursive linking/edge-cases/stomain.c
new file mode 100644
index 0000000..90208a7
--- /dev/null
+++ b/test cases/common/153 recursive linking/edge-cases/stomain.c
@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+#include "../lib.h"
+
+int get_stodep_value (void);
+
+int main(int argc, char *argv[]) {
+ int val;
+
+ val = get_stodep_value ();
+ if (val != 1) {
+ printf("st1 value was %i instead of 1\n", val);
+ return -1;
+ }
+ return 0;
+}
diff --git a/test cases/common/153 recursive linking/meson.build b/test cases/common/153 recursive linking/meson.build
index 4cecd57..2ca7151 100644
--- a/test cases/common/153 recursive linking/meson.build
+++ b/test cases/common/153 recursive linking/meson.build
@@ -24,3 +24,6 @@ subdir('3rdorderdeps')
# Circular dependencies between static libraries
# This requires the use of --start/end-group with GNU ld
subdir('circular')
+
+# Various edge cases that have been reported
+subdir('edge-cases')
diff --git a/test cases/common/153 recursive linking/shnodep/meson.build b/test cases/common/153 recursive linking/shnodep/meson.build
index 796f0dd..66cfd9b 100644
--- a/test cases/common/153 recursive linking/shnodep/meson.build
+++ b/test cases/common/153 recursive linking/shnodep/meson.build
@@ -1 +1 @@
-shnodep = shared_library('shnodep', 'lib.c')
+shnodep = shared_library('shnodep', 'lib.c', version: '0.0.0')