From dd4254a3d9d26cd436f984515570ec8cd211ee33 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Wed, 8 Oct 2014 15:50:21 -0700 Subject: Add linked modules to a separate global list Fixes #2. --- test.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'test.c') diff --git a/test.c b/test.c index d6280e4..878694e 100644 --- a/test.c +++ b/test.c @@ -31,7 +31,8 @@ #define CLOSE_LIB dlclose( library ) #define CLOSE_GLOBAL dlclose( global ) -#define RETURN_ERROR return 1 +#define RETURN_ERROR printf("From line %d\n", __LINE__); return 1 + #define RUNFUNC do { \ ret = function (); \ if( ret != 0) { \ @@ -73,6 +74,7 @@ int main() void *library; char *error; int (*function)( void ); + int (*printf_local)( const char * ); int (*nonexistentfunction)( void ); int ret; @@ -106,6 +108,20 @@ int main() else printf( "SUCCESS\tGot global handle: %p\n", global ); + printf_local = dlsym(global, "printf"); + if (!printf_local) + { + error = dlerror(); + printf("ERROR\tCould not get symbol from global handle: %s\n", + error ? error : ""); + CLOSE_LIB; + CLOSE_GLOBAL; + RETURN_ERROR; + } + else + printf("SUCCESS\tGot symbol from global handle: %p\n", printf_local); + printf_local("Hello world from local printf!\n"); + function = dlsym( library, "function" ); if( !function ) { @@ -288,6 +304,19 @@ int main() error ? error : "" ); } + function = dlsym(global, "printf"); + if (!function) + { + error = dlerror(); + printf("ERROR\tCould not get symbol from global handle: %s\n", + error ? error : ""); + CLOSE_LIB; + CLOSE_GLOBAL; + RETURN_ERROR; + } + else + printf("SUCCESS\tGot symbol from global handle: %p\n", function); + ret = dlclose( library ); if( ret ) { -- cgit v1.2.3-55-g6feb