Closed GoogleCodeExporter closed 9 years ago
Another data point: dladdr() fails when it tries to load the math functions for
double precision numbers.
If I print out functions getting registered in Math.cc, I get e.g.
Added function sin64(angle)=0x7faa5f74ec50
and then in LLVMBuilder::createExternFunc:
Looking up function sin64: 0x7faa5f74ec50
Unable to locate symbol for extern function: sin64
Original comment by Conrad.S...@gmail.com
on 9 Mar 2012 at 9:10
[deleted comment]
[deleted comment]
A simple demonstration looks like this:
module.cc:
#include <math.h>
#include <stdio.h>
typedef double (OneFuncDouble)(double);
OneFuncDouble *one_funcs_double[]= { sin, cos, tan, NULL };
extern "C" {
void **module_init(){
static void* func_array[4];
for (int i=0; i<4; i++){
func_array[i] = (void*)one_funcs_double[i];
if (one_funcs_double[i])
printf("Registering symbol %p\n", (void*)one_funcs_double[i]);
}
return func_array;
}
}
main.cc:
#include <dlfcn.h>
#include <stdio.h>
typedef void **(init_func)();
void **test_init(){
static void *retval[] = {NULL};
return retval;
}
int main(int argc, char **argv){
void *module = dlopen("module.so", RTLD_NOW);
init_func *myfunc;
myfunc = &test_init;
if (module){
init_func *module_init = (init_func *)dlsym(module, "module_init");
void **func_array = module_init();
Dl_info symInfo;
for (int i=0; func_array[i]; i++){
if (dladdr(func_array[i], &symInfo)){
if (symInfo.dli_sname)
printf("Found symbol %s\n", symInfo.dli_fname, symInfo.dli_sname);
else
printf("ERROR: symbol for %p not found\n", func_array[i]);
}
}
}
else printf("Failed to load module\n");
return 0;
}
Makefile:
all: module.so test_module
test_module: main.o
g++ -fPIC $< -o $@ -ldl
module.o: module.cc
g++ -fPIC -c $< -o $@
module.so: module.o
g++ -fPIC -shared -Wl,-soname,module.so -o $@ $<
Original comment by Conrad.S...@gmail.com
on 16 Mar 2012 at 4:58
Original comment by Conrad.S...@gmail.com
on 23 May 2012 at 6:28
Original issue reported on code.google.com by
Conrad.S...@gmail.com
on 20 Feb 2012 at 5:47Attachments: