Skip to content
Snippets Groups Projects
Commit 1d4557de authored by Vivek Das Mohapatra's avatar Vivek Das Mohapatra
Browse files

capsule-init.c: move the dlopen and dlsym real-implmentation cache

This used to reside in the capsule handle, it's now global shared
state used by all active capsules.
parent 9a82b9c3
Branches
Tags
1 merge request!311Build capsule-capture-libs from a bundled copy of libcapsule
......@@ -3,6 +3,16 @@
#include "utils/utils.h"
#include <stdlib.h>
#include <dlfcn.h>
dlsymfunc capsule_dl_symbol = NULL;
dlopnfunc capsule_dl_open = NULL;
static void __attribute__ ((constructor)) _init_capsule (void)
{
capsule_dl_symbol = dlsym( RTLD_DEFAULT, "dlsym" );
capsule_dl_open = dlsym( RTLD_DEFAULT, "dlopen" );
}
capsule
capsule_init (Lmid_t namespace,
......@@ -18,8 +28,6 @@ capsule_init (Lmid_t namespace,
handle->prefix = prefix;
handle->exclude = exclude;
handle->exported = exported;
handle->get_symbol = dlsym( RTLD_DEFAULT, "dlsym" );
handle->load_dso = dlsym( RTLD_DEFAULT, "dlopen" );
// in principle we should be able to make both reloc calls
// efficient in the same do-not-redo-your-work way, but for
......
......@@ -15,6 +15,8 @@ struct _capsule
const char **exported; // list of DSOs from which to export
capsule_item *relocations;
struct { ptr_list *all; ptr_list *some; } seen;
dlsymfunc get_symbol;
dlopnfunc load_dso;
};
extern ptr_list *capsule_manifest;
extern dlsymfunc capsule_dl_symbol;
extern dlopnfunc capsule_dl_open;
......@@ -204,15 +204,15 @@ static int relocate (const capsule cap,
// no source dl handle means we must have a pre-populated
// map of shim-to-real function pointers in `relocations',
// otherwise populate the map using dlsym():
// otherwise populate the map using [the real] dlsym():
if( cap->dl_handle )
for( map = cap->relocations; map->name; map++ )
{
if( !map->shim )
map->shim = (ElfW(Addr)) dlsym( RTLD_DEFAULT, map->name );
map->shim = (ElfW(Addr)) capsule_dl_symbol( RTLD_DEFAULT, map->name );
if( !map->real )
map->real = (ElfW(Addr)) dlsym( cap->dl_handle, map->name );
map->real = (ElfW(Addr)) capsule_dl_symbol( cap->dl_handle, map->name );
}
// time to enter some sort of ... dangerous... zone:
......
......@@ -23,7 +23,7 @@ void *
capsule_external_dlsym (capsule cap, void *handle, const char *symbol)
{
DEBUG( DEBUG_DLFUNC|DEBUG_WRAPPERS, "dlsym(%s)", symbol );
void *addr = cap->get_symbol( cap->dl_handle, symbol );
void *addr = NULL;
if( addr )
{
......@@ -39,9 +39,8 @@ capsule_external_dlsym (capsule cap, void *handle, const char *symbol)
if( addr == NULL )
{
DEBUG( DEBUG_DLFUNC|DEBUG_WRAPPERS,
"symbol %s not found or not exportable, fall back to default",
symbol );
addr = cap->get_symbol( handle, symbol );
"symbol %s not found: fall back to default", symbol );
addr = capsule_dl_symbol ( handle, symbol );
}
return addr;
......@@ -53,10 +52,9 @@ capsule_external_dlopen(const capsule cap, const char *file, int flag)
void *handle = NULL;
char *error = NULL;
if( cap->load_dso )
if( capsule_dl_open )
{
fprintf( stderr, "dlopen<%p>( %s, %d )\n", cap->load_dso, file, flag );
handle = cap->load_dso( file, flag );
handle = capsule_dl_open ( file, flag | RTLD_NODELETE );
}
else
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment