Questions tagged [dlsym]

POSIX function for accessing code or data in a dynamically-loaded library using the code's name.

187 questions
55
votes
5 answers

What is Linux utility to mangle a C++ symbol name?

I have c++filt command to demangle a symbol, what is the tool to do the opposite and mangle a symbol name? This would be useful if I were to want to call dlsym() on a mangled C++ function name. I'd rather not hard code the name mangling in the code…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
27
votes
7 answers

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

I am trying to use dlopen() and dlsym() in my code and compile it with gcc. Here is the first file. /* main.c */ #include int main() { void *handle = dlopen("./foo.so", RTLD_NOW); if (handle) { void (*func)() =…
Lone Learner
  • 18,088
  • 20
  • 102
  • 200
19
votes
5 answers

Alternatives to dlsym() and dlopen() in C++

I have an application a part of which uses shared libraries. These libraries are linked at compile time. At Runtime the loader expects the shared object to be in the LD_LIBRARY_PATH , if not found the entire application crashes with error "unable…
sud03r
  • 19,109
  • 16
  • 77
  • 96
17
votes
2 answers

Setting my lib for LD_PRELOAD makes some processes produce loader errors

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…
nakiya
  • 14,063
  • 21
  • 79
  • 118
14
votes
2 answers

Casting when using dlsym()

I'm using dlsym() in C and I have a question whether the return value of dlsym() should be explicitly cast or if it is implicitly cast correctly. Here is the function: double (*(compile)(void))(double x, double y) { if (system("scan-build clang…
lord.garbage
  • 5,884
  • 5
  • 36
  • 55
13
votes
1 answer

POSIX restrictions on pointer types in C

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 void *dlsym(void *restrict handle, const…
Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
13
votes
4 answers

dynamic_cast fails when used with dlopen/dlsym

Intro Let me apologise upfront for the long question. It is as short as I could make it, which is, unfortunately, not very short. Setup I have defined two interfaces, A and B: class A // An interface { public: virtual ~A() {} virtual void…
Kees-Jan
  • 518
  • 4
  • 16
10
votes
3 answers

std::shared_ptr and dlopen(), avoiding undefined behavior

dlopen() is a C function used for dynamically loading shared libraries at runtime. The pattern, in case you're not familiar, is thus: Call dlopen("libpath", flag) to get a void *handle to the library Call dlsym(handle, "object_name") to get a void…
9
votes
5 answers

How to detect at runtime whether symbols are stripped?

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…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
9
votes
2 answers

dlsym returns NULL, even though the symbol exists

I am using dlsym to look up symbols in my program, but it always returns NULL, which I am not expecting. According to the manpage, dlsym may return NULL if there was an error somehow, or if the symbol indeed is NULL. In my case, I am getting an…
Lorraine
  • 1,189
  • 14
  • 30
8
votes
4 answers

Function interposition in Linux without dlsym

I'm currently working on a project where I need to track the usage of several system calls and low-level functions like mmap, brk, sbrk. So far, I've been doing this using function interposition: I write a wrapper function with the same name as the…
Jay Conrod
  • 28,943
  • 19
  • 98
  • 110
7
votes
1 answer

Why does this dynamic library loading code work with gcc?

Background: I've found myself with the unenviable task of porting a C++ GNU/Linux application over to Windows. One of the things this application does is search for shared libraries on specific paths and then loads classes out of them dynamically…
bckohan
  • 203
  • 1
  • 6
7
votes
1 answer

How does the dlsym work?

it's very easy to find how to use dlsym() and other functions from this family, but how does it work internally? Is it possible to write own, easy implementation of dlsym()? I'm wondering if it is possible to achieve similar behavior but without…
kashpersky
  • 165
  • 2
  • 8
7
votes
1 answer

How to programmatically list ELF shared library symbols

In my C shared library, I want to dlopen() another shared library and retrieve a list of the exported symbols this library has. Is there a way I can do that programmatically, without running nm/objdump? As a secondary question: How can I retrieve…
linker
  • 71
  • 3
7
votes
2 answers

How can I intercept dlsym calls using LD_PRELOAD?

I want to intercept application's calls to dlsym. I have tried declaring inside the .so that I am preloading dlsym , and using dlsym itself to get it's real address, but that for quite obvious reasons didn't work. Is there a way easier than taking…
user1588911
  • 71
  • 1
  • 3
1
2 3
12 13