From 49e0676ba932c3b4b9f7de290afc6d7b0d2d6b4c Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 3 Dec 2016 01:11:07 +0200 Subject: [PATCH] Add a test that tests the module and symbol resolution with dlopen. --- .../common/125 shared module/meson.build | 6 ++- test cases/common/125 shared module/module.c | 6 +-- test cases/common/125 shared module/prog.c | 38 +++++++++++++++++++ test cases/common/125 shared module/runtime.c | 19 ++++++++++ 4 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 test cases/common/125 shared module/prog.c create mode 100644 test cases/common/125 shared module/runtime.c diff --git a/test cases/common/125 shared module/meson.build b/test cases/common/125 shared module/meson.build index 70e954bd8..5ca50c5e2 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 be0720d29..ed2712c2a 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 000000000..839703401 --- /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 +#include +#include + +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 000000000..f701171fd --- /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; +}