Questions tagged [ld-preload]

LD_PRELOAD is a list of additional ELF shared objects that should be loaded first.

LD_PRELOAD is a list of additional ELF shared objects that should be loaded first.

For more information, visit this website

http://man7.org/linux/man-pages/man8/ld.so.8.html

234 questions
26
votes
3 answers

LD_PRELOAD does not work as expected

Consider the following library which can be preloaded before any program execution: // g++ -std=c++11 -shared -fPIC preload.cpp -o preload.so // LD_PRELOAD=./preload.so #include struct Goodbye { Goodbye() {std::cout <<…
Martin
  • 8,269
  • 8
  • 43
  • 75
18
votes
1 answer

What is the exact equivalent to LD_PRELOAD on OSX?

I am using LD_PRELOAD to hook a library function, and in Linux it works perfectly. But I cannot figure out how to do the equivalent in OSX. The setup I have on Linux is as follows: The code is: #include #include #include…
horseyguy
  • 27,966
  • 18
  • 97
  • 133
16
votes
1 answer

link a static library to a shared library and hide exported symbols

I am having an annoying problem with the linker. I want to link some symbols from a shared library to a static library, but not export its symbols (ie, I cannot simply merge the libraries or link with --whole-archive). What I want is link (as in,…
Thibaut
  • 2,280
  • 1
  • 14
  • 26
12
votes
1 answer

Binding failure with objcopy --redefine-syms

Preconditions A third-party has provided a C++ executable fooapp that uses a shared object libfoo.so. The library also comes with a header foo.hpp so developers can build other applications: /* foo.hpp */ namespace foo { void bar(int a, int b); …
BrianTheLion
  • 2,440
  • 2
  • 22
  • 43
11
votes
5 answers

LD_PRELOAD with setuid binary

I am trying to use LD_PRELOAD to preload a library with an application that has setuid permissions. Tried LD_PRELOAD at first, and it seemed like it was being ignored with the setuid binary, though it was working when I tried it with others like ls,…
Mark Lobo
  • 311
  • 2
  • 3
  • 8
8
votes
1 answer

LD_PRELOAD does not loaded on systemd

I am trying to inject a SO into a process that starts using systemd init system (using LD_PRELOAD), but it does not loaded into the new process. I complied a basic SO (unrandom.c): int rand(){ return 42; //the most random number in the…
Or Smolnik
  • 81
  • 1
  • 5
8
votes
2 answers

hiding functions in C

I have application that has a function f1 void f1 () In addition, I have a library that I load using LD_PRELOAD. The library has several code files and several header file, and it compiled to .so file. On of the header files also uses a function…
dk7
  • 303
  • 1
  • 13
7
votes
1 answer

why is library loaded via LD_PRELOAD operating before initialization?

In the following minimal example, a library loaded via LD_PRELOAD with functions to intercept fopen and openat is apparently operating before its initialization. (Linux is CentOS 7.3). Why?? library file comm.c: #define _GNU_SOURCE #include…
Mark Galeck
  • 5,261
  • 1
  • 22
  • 43
7
votes
1 answer

How to check if a linux shared library has been preloaded using LD_PRELOAD

I'm familiar with using dlopen() to check if a shared library has been loaded into a process using a prior call to dlopen() without triggering a load if it isn't present, like so: void* lib = dlopen(lib_name, RTLD_NOLOAD); if (lib != NULL) { …
Timo Geusch
  • 23,267
  • 4
  • 48
  • 70
7
votes
1 answer

Dynamically modify symbol table at runtime (in C)

Is it possible to dynamically modify symbol table at runtime in C (in elf format on Linux)? My eventual goal is the following: Inside certain function say foo, I want to override malloc function to my custom handler my_malloc. But outside foo, any…
Richard
  • 12,738
  • 17
  • 48
  • 75
6
votes
1 answer

intercepting the openat() system call for GNU tar

I'm trying to intercept the openat() system call on Linux using a custom shared library that I can load via LD_PRELOAD. An example intercept-openat.c has this content: #define _GNU_SOURCE #include #include #include…
Julius Plenz
  • 63
  • 1
  • 3
6
votes
5 answers

Problems with LD_PRELOAD and calloc() interposition for certain executables

Relating to a previous question of mine I've successfully interposed malloc, but calloc seems to be more problematic. That is with certain hosts, calloc gets stuck in an infinite loop with a possible internal calloc call inside dlsym. However, a…
Justicle
  • 13,619
  • 13
  • 66
  • 91
6
votes
1 answer

LD_PRELOAD only working for malloc, not free

I'm trying to interpose malloc/free/calloc/realloc etc with some interposers via LD_PRELOAD. In my small test, only malloc seems to be interposed, even though free is detected (see output). I'd expect the output to contain a line "NANO: free(x)" -…
Justicle
  • 13,619
  • 13
  • 66
  • 91
6
votes
3 answers

LD_PRELOAD doesn't affect dlopen() with RTLD_NOW

If I use a function from a shared library directly, i.e. by declaring it in my code and linking during compile time, LD_PRELOAD works fine. But if I use dlopen()/dlsym() instead LD_PRELOAD has no effect! The problem is that I want to debug a program…
sashoalm
  • 63,456
  • 96
  • 348
  • 677
6
votes
2 answers

How to wrap ioctl(int d, unsigned long request, ...) using LD_PRELOAD?

Here's the template I use for wrapping a function using LD_PRELOAD: int gettimeofday(struct timeval *tv, struct timezone *tz) { static int (*gettimeofday_real)(struct timeval *tv, struct timezone *tz)=NULL; if (!gettimeofday_real)…
d33tah
  • 8,728
  • 10
  • 51
  • 128
1
2 3
15 16