Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When will LD_PRELOAD be ignored

Tags:

c

linux

I'm trying to use LD_PRELOAD to wrap some functions in a system, I first exported the environment variable LD_PRELOAD to point to my .so file, then I run the system, I always get ERROR: ld.so: object '/full/path/to/wrap.so' from LD_PRELOAD cannot be preloaded: ignored. So I tried to understand LD_PRELOAD on the man page:

A list of additional, user-specified, ELF shared libraries to be loaded before all others. The items of the list can be separated by spaces or colons. This can be used to selectively override functions in other shared libraries. The libraries are searched for using the rules given under DESCRIPTION. For set-user-ID/set-group-ID ELF binaries, preload pathnames containing slashes are ignored, and libraries in the standard search directories are loaded only if the set-user-ID permission bit is enabled on the library file.

I don't 100% understand the above text, first, it says

For set-user-ID/set-group-ID ELF binaries, preload pathnames containing slashes are ignored

If I can't use slashes, how can I set the full path of LA_PRELOAD?

second, it says

and libraries in the standard search directories are loaded only if...

what is the standard search directories?

My final question is understanding when will LD_PRELOAD be ignored? Thank you for your help.

Edit:

When I exported the LD_PRELOAD to a shared library in /usr/lib/ like this: export LD_PRELOAD=shared-lib.so, I got rid of the above error, but I have no root privileges, so I'm not able to put any files under /usr/lib/, any suggestions about this? I think if I can manage to export the LD_PRELOAD without any slashes, it should work, but unless the shared library file is in /usr/lib/, LD_PRELOAD requires the full path.

like image 457
user4016367 Avatar asked Sep 01 '25 06:09

user4016367


2 Answers

You may want to export LD_DEBUG=files to get a bit of insight of what's going on, although the output will be quite verbose and it may take you a while to find relevant lines.

EDIT: since that didn't help, you may want to try other LD_DEBUG options:

libs        display library search paths
reloc       display relocation processing
files       display progress for input file
symbols     display symbol table processing
bindings    display information about symbol binding
versions    display version dependencies
all         all previous options combined
statistics  display relocation statistics
unused      determined unused DSOs
help        display this help message and exit

all looks like an overkill, but maybe libs or symbols will show something useful.

like image 95
Dmitry Grigoryev Avatar answered Sep 02 '25 19:09

Dmitry Grigoryev


This means two things:

  1. Either '/full/path/to/wrap.so' is not a shared library (check with file '/full/path/to/wrap.so'),
  2. Or '/full/path/to/wrap.so' is missing (itself) a shared library (check that with ldd '/full/path/to/wrap.so')

If the above is not usefull, then try a very low level tool:

$ strace /path/to/your/exe/which/load/wrap.so 2>&1 | grep '/full/path/to/wrap.so'

If you want to get some context, try using -3 in grep (or any larger number):

$ strace /path/to/your/exe/which/load/wrap.so 2>&1 | grep -3 '/full/path/to/wrap.so'
like image 25
malat Avatar answered Sep 02 '25 20:09

malat