xiaogw
xiaogw

Reputation: 745

How does LD_PRELOAD update the library function

I know we can use the LD_PRELOAD trick to replace a libc function, e.g., malloc(). So how exactly LD_PRELOAD works? Does it replace the GOT/PLT entry?

Upvotes: 0

Views: 211

Answers (1)

Florian Weimer
Florian Weimer

Reputation: 33719

It puts the preloaded library at the start of the symbol search path. This way, all references to malloc are bound to its implementation, and not the implementation in libc.

In glibc, you can see the code in elf/rtld.c (the call to _dl_map_object_deps) and the implementation of the _dl_map_object_deps function in elf/dl-deps.c.

Upvotes: 1

Related Questions