Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying multiple files with LD_PRELOAD

Tags:

c

linux

dynamic

x86

I know how to override one library with LD_PRELOAD, for example, as follows.

LD_PRELOAD=./getpid.so ./testpid 

Now my question is how to override multiple files. Say I want to override both getpid and getid, how would I specify that?

like image 843
MetallicPriest Avatar asked Dec 12 '11 12:12

MetallicPriest


People also ask

What is the LD_PRELOAD trick?

The LD_PRELOAD trick exploits functionality provided by the dynamic linker on Unix systems that allows you to tell the linker to bind symbols provided by a certain shared library before other libraries.

Is LD_PRELOAD an environment variable?

LD_PRELOAD is an optional environmental variable containing one or more paths to shared libraries, or shared objects, that the loader will load before any other shared library including the C runtime library (libc.so) This is called preloading a library.

What is LD_PRELOAD and Ld_library_path?

LD_PRELOAD (not LD_PRELOAD_PATH ) is a list of specific libraries (files) to be loaded before any other libraries, whether the program wants it or not. LD_LIBRARY_PATH is a list of directories to search when loading libraries that would have been loaded anyway.

Where is LD_PRELOAD defined?

LD_PRELOAD is an environment variable (part of the "environment" defined by the C library and Unix conventions). That specific variable tells the dynamic linker how to behave. It is probably not set to anything by default.


2 Answers

According to the ld.so manpage, it is a space separated list. So:

 LD_PRELOAD="path1 path2" 

ought to work.

like image 90
William Pursell Avatar answered Sep 22 '22 12:09

William Pursell


One option is to have the overridden version of both getpid and getid in a single .so which you give to LD_PRELOAD.

like image 38
codaddict Avatar answered Sep 21 '22 12:09

codaddict