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

265 questions
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
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
1 answer

How to use perf with ld_preload?

I tried to use perf stat with LD_PRELOAD as prefix for executable such as: perf stat LD_PRELOAD=$PWD/../user/preload.so ./write 1 It seems not work for perf, are there any way to achieve it?
Steven
  • 811
  • 4
  • 23
6
votes
3 answers

How to wrap variadic functions using LD_PRELOAD?

I have to perform dynamic linking on a variadic function of following format: int foo(char *args, const char *f, ...) Here the number of arguments are variable. What I want to achieve is that I want to pass the obtained arguments to the original…
ankit jain
  • 350
  • 2
  • 12
6
votes
2 answers

Using LD_PRELOAD mixed 64bit/32bit environment in Linux

I would like to set LD_PRELOAD to point to a shared library where I might run either a 64bit or 32bit application. It is obvious that the shared library and the executable have to match in bit-ness. $ LD_PRELOAD=/lib64/lib_init.so…
Robert McLay
  • 63
  • 1
  • 3
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
  • 10,999
  • 13
  • 68
  • 158
6
votes
1 answer

LD_PRELOAD causing segmentation fault in dynamic library loader

I have written a library which is intended to be loaded via LD_PRELOAD. On some Linux systems, this is causing the dynamic library loader to segfault during initialisation. I have a simple test case that exhibits this behaviour, but only if I link…
jprice
  • 9,755
  • 1
  • 28
  • 32
6
votes
2 answers

Replacing the close() function in Linux with my own close() function

I'm trying to provide my own implementation of the close() function in Linux. Why? Because I just found out you could do that and it sounds fun. Here's myclose.c: #include int close(int fd) { printf("Closing fd: %d\n", fd); return…
gsgx
  • 12,020
  • 25
  • 98
  • 149
6
votes
1 answer

What are the differences between LD_PRELOAD and strace?

Both methods are used to gather system calls also parameters and return values of them. When we prefer LD_PRELOAD and why? Maybe we can say that we can only gather syscalls via strace but we can gather library calls with LD_PRELOAD trick. However,…
Ricardo Cristian Ramirez
  • 1,194
  • 3
  • 20
  • 42
5
votes
2 answers

How to debug functions in a dynamic library loaded with LD_PRELOAD with gdb?

I'm trying to debug some functions in a dynamic shared library libexecHook.so. This library is preloaded setting LD_PRELOAD in order to intercept and rewrite some calls to execve() and friends. For debugging purposes I have built gmake with symbols.…
Marko
  • 128
  • 1
  • 9
5
votes
1 answer

Why doesn't LD_PRELOAD take effect with scripts having no shebang?

If, when I run a script, I use LD_PRELOAD to designate a library to preload, I find that the library is in fact preloaded only if the script has a shebang line. For example, given this script: # Not a shebang echo Hello and this…
John Bollinger
  • 160,171
  • 8
  • 81
  • 157
5
votes
2 answers

why doesn't LD_PRELOAD trick catch open() when called by fopen()?

I use the LD_PRELOAD trick to catch open64() calls and I think I know how to do it correctly: with the program foobar compiled from #include #include #include int main() { open64("foobar.txt", 0); return…
Mark Galeck
  • 6,155
  • 1
  • 28
  • 55
5
votes
5 answers

How to override assert macro in C?

I want to create my own version of assert in which it does some log prints in case assert was called in NDEBUG mode. I tried to do the LD_PRELOAD trick and redefine the assert macro but it seems to ignore the macro definition completely and…
itayb
  • 139
  • 3
  • 10
5
votes
1 answer

Presenting a virtual filesystem to a Linux process without root access

I'm looking for a way to present a userspace filesystem to a specific Linux process but I don't have root access. The obvious answer is FUSE but without root access I cannot load the kernel module and so FUSE seems to be out of the question (unless…
tommyvn
  • 713
  • 5
  • 12
5
votes
3 answers

LD_PRELOADed libraries and child process

everyone! Image that i have a program(usemalloc) like this: #include #include #define USER_BYTES_SIZE 100 int main(void){ char* userbytes = (char*)malloc(USER_BYTES_SIZE*sizeof(char)); if(!userbytes) return…
振 禹
  • 51
  • 3
1
2
3
17 18