aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test cases/common/125 shared module/meson.build6
-rw-r--r--test cases/common/125 shared module/module.c6
-rw-r--r--test cases/common/125 shared module/prog.c38
-rw-r--r--test cases/common/125 shared module/runtime.c19
4 files changed, 65 insertions, 4 deletions
diff --git a/test cases/common/125 shared module/meson.build b/test cases/common/125 shared module/meson.build
index 70e954b..5ca50c5 100644
--- a/test cases/common/125 shared module/meson.build
+++ b/test cases/common/125 shared module/meson.build
@@ -1,4 +1,8 @@
project('shared module', 'c')
-shared_module('mymodule', 'module.c')
+dl = meson.get_compiler('c').find_library('dl', required : false)
+l = shared_library('runtime', 'runtime.c')
+m = shared_module('mymodule', 'module.c')
+e = executable('prog', 'prog.c', link_with : l, dependencies : dl)
+test('import test', e, args : [m.full_path()])
diff --git a/test cases/common/125 shared module/module.c b/test cases/common/125 shared module/module.c
index be0720d..ed2712c 100644
--- a/test cases/common/125 shared module/module.c
+++ b/test cases/common/125 shared module/module.c
@@ -11,12 +11,12 @@
/*
* Shared modules often have references to symbols that are not defined
- * at link time, but which will be provided by the executable that
+ * at link time, but which will be provided from deps of the executable that
* dlopens it. We need to make sure that this works, i.e. that we do
* not pass -Wl,--no-undefined when linking modules.
*/
-int nonexisting_function();
+int func_from_language_runtime();
int DLL_PUBLIC func() {
- return nonexisting_function();
+ return func_from_language_runtime();
}
diff --git a/test cases/common/125 shared module/prog.c b/test cases/common/125 shared module/prog.c
new file mode 100644
index 0000000..8397034
--- /dev/null
+++ b/test cases/common/125 shared module/prog.c
@@ -0,0 +1,38 @@
+#ifdef _WIN32
+// FIXME: add implementation using Winapi functions for dlopen.
+
+int main(int argc, char **argv) {
+ return 0;
+}
+
+#else
+
+#include<dlfcn.h>
+#include<assert.h>
+#include<stdio.h>
+
+int func();
+int func_from_language_runtime();
+
+int main(int argc, char **argv) {
+ void *dl;
+ int (*importedfunc)();
+ int success;
+ char *error;
+
+ dlerror();
+ dl = dlopen(argv[1], RTLD_LAZY);
+ error = dlerror();
+ if(error) {
+ printf("Could not open %s: %s\n", argv[1], error);
+ return 1;
+ }
+ importedfunc = (int (*)()) dlsym(dl, "func");
+ assert(importedfunc);
+ assert(importedfunc != func_from_language_runtime);
+ success = (*importedfunc)() == func_from_language_runtime();
+ dlclose(dl);
+ return !success;
+}
+
+#endif
diff --git a/test cases/common/125 shared module/runtime.c b/test cases/common/125 shared module/runtime.c
new file mode 100644
index 0000000..f701171
--- /dev/null
+++ b/test cases/common/125 shared module/runtime.c
@@ -0,0 +1,19 @@
+#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
+
+/*
+ * This file pretends to be a language runtime that supports extension
+ * modules.
+ */
+
+int func_from_language_runtime() {
+ return 86;
+}