4

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?

Community
  • 1
  • 1
Sam
  • 19,708
  • 4
  • 59
  • 82
  • Well the documentation is suggesting one way of doing something, but they don't want people to go using "LD_PRELOAD" for . –  Dec 05 '14 at 08:38
  • Those bad reasons are what I want to understand. They only say it's tricky – Sam Dec 05 '14 at 08:57

2 Answers2

5

When using LD_PRELOAD, the tcmalloc implementation will be used for any child process as well which may not be what you want.

ysdx
  • 8,889
  • 1
  • 38
  • 51
4

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.

Community
  • 1
  • 1
5gon12eder
  • 24,280
  • 5
  • 45
  • 92