dlsym

POSIX restrictions on pointer types in C

自闭症网瘾萝莉.ら 提交于 2019-12-03 23:57:12
问题 Background The POSIX standard adds a lot of library functions and other identifiers to the C language. In the description of the dlsym() function, it says (with my emphasis): SYNOPSIS #include <dlfcn.h> void *dlsym(void *restrict handle, const char *restrict name); DESCRIPTION The dlsym () function shall obtain the address of a symbol (a function identifier or a data object identifier) ... The C standard doesn't guarantee that a function pointer can be converted to a void * , or even that the

How to detect at runtime whether symbols are stripped?

回眸只為那壹抹淺笑 提交于 2019-12-03 12:35:22
In my C++ program, how can I detect programmatically at runtime whether symbols have been stripped via the 'strip' gnu development tool on Linux? I'd like a function definition which returns true if stripped, otherwise false. Would using dlsym() on "main()" work to detect this reliably? I know the file command can tell the difference, so you could possibly look at its source to see what mechanism it uses. jschmier From a comment left for another answer : A stripped ELF will lack a .symtab entry. The file command traverses through all the ELF section headers until a symbol table section is

How to access (dynamically allocated) Fortran arrays in C

倖福魔咒の 提交于 2019-12-03 04:00:49
My main question is why arrays do such weird things and whether there is any way at all to do the following in a "clean" way. I currently have a C program foo.c interfacing a Fortran program bar.f90 via dlopen/dlsym , roughly like in the code below: foo.c: #include <dlfcn.h> #include <stdio.h> int main() { int i, k = 4; double arr[k]; char * e; void * bar = dlopen("Code/Test/bar.so", RTLD_NOW | RTLD_LOCAL); void (*allocArray)(int*); *(void **)(&allocArray) = dlsym(bar, "__bar_MOD_allocarray"); void (*fillArray)(double*); *(void **)(&fillArray) = dlsym(bar, "__bar_MOD_fillarray"); void (

Setting my lib for LD_PRELOAD makes some processes produce loader errors

被刻印的时光 ゝ 提交于 2019-12-03 02:30:41
I get the following error when I try to run a script I have only execution access for: uname: symbol lookup error: /home/dumindara/random/sotest/a.out: undefined symbol: dlsym This is after I have set LD_PRELOAD environment variable to /home/dumindara/random/sotest/a.out . a.out has a test malloc function, and calls dlsym internally. I don't get this problem when running ls . Most processes do give this error. Why does this happen and what can I do to make it work? I assume that your a.out file is a shared object and not a executable and move on... dlsym() is a function from the libdl library,

Reference a variable by name in C++ by using Symbol Table

时光总嘲笑我的痴心妄想 提交于 2019-12-02 04:07:29
问题 Basically what the title asks. Being a bit unfamiliar with C++ , and the more advanced concepts such as symbol tables, I've looked into it online but am struggling to find any direction towards what my end goal is. Most of the tutorials I've seen cater to C, and the closest question I've found (here) puts me at a brick wall, as I've tried compiling it but I'm not getting the desired results, and I'm not too solid on how extern "C" works yet. By the end of this, I want to be able to access a

Reference a variable by name in C++ by using Symbol Table

不想你离开。 提交于 2019-12-01 23:51:20
Basically what the title asks. Being a bit unfamiliar with C++ , and the more advanced concepts such as symbol tables, I've looked into it online but am struggling to find any direction towards what my end goal is. Most of the tutorials I've seen cater to C, and the closest question I've found ( here ) puts me at a brick wall, as I've tried compiling it but I'm not getting the desired results, and I'm not too solid on how extern "C" works yet. By the end of this, I want to be able to access a variable from the symbol table, and change the variable. I have played around with nm and objdump (and

how can I get the `__NSAutoreleaseNoPool` address?

最后都变了- 提交于 2019-12-01 13:35:28
I tried with extern void __NSAutoreleaseNoPool(void* obj); but that results in an unresolved symbol when linking (not sure what Framework it needs, though). I also tried dlsym(RTLD_DEFAULT, "__NSAutoreleaseNoPool") but that just gives be NULL . And I tried with _dyld_lookup_and_bind and NSLookupSymbolInImage but they also don't work. dsymutil and nm both find the symbol, though: $ dsymutil -s --arch=x86_64 ---------------------------------------------------------------------- /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation -----------------------------------------

how can I get the `__NSAutoreleaseNoPool` address?

最后都变了- 提交于 2019-12-01 11:40:30
问题 I tried with extern void __NSAutoreleaseNoPool(void* obj); but that results in an unresolved symbol when linking (not sure what Framework it needs, though). I also tried dlsym(RTLD_DEFAULT, "__NSAutoreleaseNoPool") but that just gives be NULL . And I tried with _dyld_lookup_and_bind and NSLookupSymbolInImage but they also don't work. dsymutil and nm both find the symbol, though: $ dsymutil -s --arch=x86_64 ---------------------------------------------------------------------- /System/Library

How to correctly assign a pointer returned by dlsym into a variable of function pointer type?

你。 提交于 2019-11-30 08:12:46
I am trying to use dlopen() and dlsym() in my code and compile it with gcc . Here is the first file. /* main.c */ #include <dlfcn.h> int main() { void *handle = dlopen("./foo.so", RTLD_NOW); if (handle) { void (*func)() = dlsym(handle, "func"); func(); } return 0; } Here is the second file. /* foo.c */ #include <stdio.h> void func() { printf("hello, world\n"); } Here is how I compile and run the code. $ gcc -std=c99 -pedantic -Wall -Wextra -shared -fPIC -o foo.so foo.c $ gcc -std=c99 -pedantic -Wall -Wextra -ldl -o main main.c main.c: In function ‘main’: main.c:10:26: warning: ISO C forbids

Ubuntu13.10下Cppunit1.12.1安装记录

╄→гoц情女王★ 提交于 2019-11-29 12:35:13
环境介绍 ubuntu version: 13.10 gcc, g++ version: 4.8.1 cppunit version: 1.12.1 cppunit 可以在该处下载 cppunit传送门 安装过程 解压以后, 安装仍然是传统的三步骤: ./configure make sudo make install configure 的过程能够很容易的通过, 当进行make的时候, 则出现了如下的错误: g++ -g -O2 -o .libs/DllPlugInTester DllPlugInTester.o CommandLineParser.o -ldl ../../src/cppunit/.libs/libcppunit.so -lm ../../src/cppunit/.libs/libcppunit.so: undefined reference to `dlsym' ../../src/cppunit/.libs/libcppunit.so: undefined reference to `dlopen' ../../src/cppunit/.libs/libcppunit.so: undefined reference to `dlclose' collect2: error: ld returned 1 exit status make[2]: ***