Add a test that tests the module and symbol resolution with dlopen.

pull/1126/head
Jussi Pakkanen 8 years ago
parent 2dd7f3cb47
commit 49e0676ba9
  1. 6
      test cases/common/125 shared module/meson.build
  2. 6
      test cases/common/125 shared module/module.c
  3. 38
      test cases/common/125 shared module/prog.c
  4. 19
      test cases/common/125 shared module/runtime.c

@ -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()])

@ -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();
}

@ -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

@ -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;
}
Loading…
Cancel
Save