aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/build.py10
-rwxr-xr-xrun_unittests.py10
-rw-r--r--test cases/unit/26 shared_mod linking/libfile.c14
-rw-r--r--test cases/unit/26 shared_mod linking/main.c11
-rw-r--r--test cases/unit/26 shared_mod linking/meson.build5
5 files changed, 50 insertions, 0 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 3ff68ed..aca592e 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -380,6 +380,7 @@ class BuildTarget(Target):
self.process_compilers_late()
self.validate_sources()
self.validate_cross_install(environment)
+ self.check_module_linking()
def __lt__(self, other):
return self.get_id() < other.get_id()
@@ -1027,6 +1028,15 @@ You probably should put it in link_with instead.''')
def is_linkable_target(self):
return False
+ def check_module_linking(self):
+ '''
+ Warn if shared modules are linked with target: (link_with) #2865
+ '''
+ for link_target in self.link_targets:
+ if isinstance(link_target, SharedModule):
+ mlog.warning('''target links against shared modules. This is not
+recommended as it can lead to undefined behaviour on some platforms''')
+ return
class Generator:
def __init__(self, args, kwargs):
diff --git a/run_unittests.py b/run_unittests.py
index 96a98eb..9f0ae3f 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -1899,6 +1899,16 @@ int main(int argc, char **argv) {
exception_raised = True
self.assertTrue(exception_raised, 'Double locking did not raise exception.')
+ def test_check_module_linking(self):
+ """
+ Test that shared modules are not linked with targets(link_with:) #2865
+ """
+ tdir = os.path.join(self.unit_test_dir, '26 shared_mod linking')
+ out = self.init(tdir)
+ msg = ('''WARNING: target links against shared modules. This is not
+recommended as it can lead to undefined behaviour on some platforms''')
+ self.assertIn(msg, out)
+
def test_ndebug_if_release_disabled(self):
testdir = os.path.join(self.unit_test_dir, '25 ndebug if-release')
self.init(testdir, extra_args=['--buildtype=release', '-Db_ndebug=if-release'])
diff --git a/test cases/unit/26 shared_mod linking/libfile.c b/test cases/unit/26 shared_mod linking/libfile.c
new file mode 100644
index 0000000..44f7667
--- /dev/null
+++ b/test cases/unit/26 shared_mod linking/libfile.c
@@ -0,0 +1,14 @@
+#if defined _WIN32 || defined __CYGWIN__
+ #define DLL_PUBLIC __declspec(dllexport)
+#else
+ #if defined __GNUC__
+ #define DLL_PUBLIC __attribute__ ((visibility("default")))
+ #else
+ #pragma message ("Compiler does not support symbol visibility.")
+ #define DLL_PUBLIC
+ #endif
+#endif
+
+int DLL_PUBLIC func() {
+ return 0;
+}
diff --git a/test cases/unit/26 shared_mod linking/main.c b/test cases/unit/26 shared_mod linking/main.c
new file mode 100644
index 0000000..12f9c98
--- /dev/null
+++ b/test cases/unit/26 shared_mod linking/main.c
@@ -0,0 +1,11 @@
+#if defined _WIN32 || defined __CYGWIN__
+ #define DLL_IMPORT __declspec(dllimport)
+#else
+ #define DLL_IMPORT
+#endif
+
+int DLL_IMPORT func();
+
+int main(int argc, char **arg) {
+ return func();
+}
diff --git a/test cases/unit/26 shared_mod linking/meson.build b/test cases/unit/26 shared_mod linking/meson.build
new file mode 100644
index 0000000..994a5d3
--- /dev/null
+++ b/test cases/unit/26 shared_mod linking/meson.build
@@ -0,0 +1,5 @@
+project('shared library linking test', 'c', 'cpp')
+
+mod = shared_module('mymod', 'libfile.c')
+
+exe = executable('prog', 'main.c', link_with : mod, install : true) \ No newline at end of file