Questions tagged [dlsym]

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

187 questions
4
votes
1 answer

dlsym-like functionality for non-dynamically-loaded code?

I know how to use dlsym() to find symbols keyed by a string - when these symbols are exported by a shared library which I've dlopen()ed. But - what about other code? Just object code I've linked statically. Is it possible to somehow lookup…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
4
votes
0 answers

Is there a way to detect at runtime if a library was statically linked?

I have a situation where I distribute a library that uses symbol interposition to deal with some stdlib.h functions, e.g., malloc. I would normally just use the standard psymbol = dlsym(RTDL_NEXT,"symbol") technique as described here. I have some…
Luke
  • 124
  • 6
4
votes
5 answers

C/C++ Dynamic loading of functions with unknown prototype

I'm in the process of writing a kind of runtime system/interpreter, and one of things that I need to be able to do is call c/c++ functions located in external libraries. On linux I'm using the dlfcn.h functions to open a library, and call a function…
R Campbell
  • 160
  • 1
  • 8
4
votes
1 answer

having object file symbols become dynamic symbols in executable

I have several object files (from C++) that are spat out of a build system. They have several extern "C"-linkage symbols I want to use in a program and have accessible via dlopen/dlsym from elsewhere. When compiled into an executable with gcc, these…
user
  • 4,920
  • 3
  • 25
  • 38
4
votes
1 answer

Should I cache dlsym's return value?

I'm using the POSIX dlopen/dlsym API's to load dynamic libraries at runtime and then call functions from those libraries by name. Is it a good idea, performance-wise, to store the result of dlsym somewhere? Or does dlsym do its own caching already…
Wander Nauta
  • 18,832
  • 1
  • 45
  • 62
3
votes
1 answer

How to handle different behaviour for dlsym() in OSX and Linux (generic)

I recently added some dynamic plugin behavior in an OSX program which works as designed. However, trying the same on Linux (generic) fails as dlsym() library call fails to resolve symbol in the same way that works fine in OSX. From reading man dlsym…
Johan
  • 383
  • 1
  • 2
  • 11
3
votes
0 answers

Is it possible to define a symbol dynamically such that it will be found by dlsym?

I want to simulate loading symbols from a shared library for testing purposes. Is there a way to define a symbol at runtime programmatically such that dlsym will find it? For example: dl_define_symbol("foobar") .... void* f =…
Bruce Adams
  • 4,953
  • 4
  • 48
  • 111
3
votes
2 answers

dlsym() + RTLD_NEXT doesn't work as expected on Ubuntu 20.04

I'm faced a strange runtime behavior on Ubuntu 20.04 (gcc v 9.3.0) when using dlsym() call. Please, see below a simple example: file test.cpp: #include #include #include #include #include…
drus
  • 495
  • 2
  • 6
  • 13
3
votes
2 answers

How can dlsym successfully import function from stripped binary library?

It's weird that dlsym can import functions from stripped binaries. Can anyone tell me why/how? === FILE: a.c === int a1() { return 1; } int a2() { return 2; } === end of a.c === === FILE: b.c === #include #include #include…
felix021
  • 1,936
  • 3
  • 16
  • 20
3
votes
3 answers

Ansi C patch using dlsym compiles OK under linux but fails on Mac Os X

I have build a little patch to append to a certain application and trace the invocations of some functions. Among them, malloc() and open(). I am using dlsym to store the pointer to the original symbol and replace the function name with my own. It…
flaab
  • 543
  • 9
  • 19
3
votes
2 answers

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

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…
MrMattL92
  • 33
  • 7
3
votes
1 answer

C typedef for function prototype dlsym

I am writing a shared library to LD_PRELOAD and intercept some calls from an existing library (in linux). I have about 50+ different function prototypes and attribute declaration to write and I want to keep the code as short as possible because the…
doctor killer
  • 392
  • 1
  • 14
3
votes
1 answer

dlsym and parameter checking

I'm writing a plug-in application in C and I'm using dlopen/dlsym to load dynamically the "implementation" of some functions. For example I have the following pointer to a function struct cti_t* (*create)() = 0; And I load the implementation using…
IWill80
  • 87
  • 7
3
votes
3 answers

undefined reference to `dlsym' Learn C The Hard Way

When I try to compile my unit test files i get 'undefined reference to `dlsym' error. I read that on Unix system (I'm on Ubuntu 12.04) adding -ldl to compiler works, but I tried to work with Zed's Shaw Makefile and still nothing happened. This is…
Michał Bil
  • 3,179
  • 5
  • 20
  • 24
3
votes
2 answers

How to access (dynamically allocated) Fortran arrays in C

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…
Sty
  • 760
  • 1
  • 9
  • 30
1 2
3
12 13