简体   繁体   中英

Why is LD_PRELOAD usage discouraged?

I came across this piece of advice on the Google's tcmalloc documentation page.

You can use TCMalloc in applications you didn't compile yourself, by using LD_PRELOAD:

 $ LD_PRELOAD="/usr/lib/libtcmalloc.so" 

LD_PRELOAD is tricky, and we don't necessarily recommend this mode of usage.

Why do they discourage LD_PRELOAD? Is something inherently wrong with it? Is normal linking more robust? How?

使用LD_PRELOADtcmalloc实现也将用于任何子进程,而这可能不是您想要的。

In addition to ysdx ' answer, the value of LD_PRELOAD will also be ignored (for good reasons) for setuid() ed programs.

Depending on the use-case, this might be undesirable. For example, you cannot write a shell script wrapper that exports LD_PRELOAD and then executes the actual program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM