# LD\_PRELOAD: The Hero We Need and Deserve

DevFeed: [LD\_PRELOAD: The Hero We Need and Deserve](<https://devfeed.tech/articles/ld-preload-the-hero-we-need-and-deserve-35176.md>)

Original publisher: [Read original article](<https://blog.jessfraz.com/post/ld_preload/>)

Published: 2019-02-17T15:09:26Z

Content type: opinion

Language: en

Sources: [Jessie Frazelle](<https://devfeed.tech/sources/jessie-frazelle.md>)

Topics: [Library](<https://devfeed.tech/topics/library.md>), [function](<https://devfeed.tech/topics/function.md>)

## AI overview

A personal, enthusiastic explanation of LD_PRELOAD, an environment variable that lets users override library symbols with custom functions from a shared object. The article also highlights community examples of using it for process behavior, SSH key generation, compatibility hacks, readline interception, and software interfaces.

## Source excerpt

I'm a huge, HUGE, fan of LD_PRELOAD let me tell you... oh wait it's my blog so I'm going to. Where do I begin... About three years ago, I wrote a blog post about the 10 LDFLAGS I love. After writing the post, I realized I should have made the number odd because I think that is part of BuzzFeed's "click algorithm." But more seriously, I realized just how many people on the internet you can upset when you don't include LD_PRELOAD in your favorite LDFLAGS post. I am going to take the time right now to make one thing very clear, VERY CLEAR, listen closely: LD_PRELOAD IS NOT A FLAG. It is an environment variable. Wake up sheeple! Phew! Now that's out of the way, we can continue... I love LD_PRELOAD. I love it so much I am devoting this entire blog post to professing my undying love for it. So here we go... Background For those who don't know what LD_PRELOAD is: TODAY IS YOUR LUCKY DAY! LD_PRELOAD allows you to override symbols in any library by specifying your new function in a shared object. When you run LD_PRELOAD=/path/to/my/free.so /bin/mybinary, /path/to/my/free.so is loaded before any other library, including libc. When mybinary is executed, it uses your custom function for free. PRETTY FREAKING AWESOME RIGHT! FEEL THE POWER! Okay, so moving on... Fun Times on the Internet One night, I'm just hanging around in my apartment, laying on my couch, and I think "oh I'm going to ask the Internet what they've done with LD_PRELOAD." This is how most of my tweets start for what it's worth. So I asked... yo internet nerds, tell me all the ways you've done dirty things with LD_PRELOAD.... I need them.... for... science... -- jessie frazelle 👩🏼🚀 (@jessfraz) January 21, 2019 This tweet blew up in THE BEST WAY! I got some really cool responses I will highlight below. Not mine but my favorite: https://t.co/zljcn70pmh -- ダデイさま (@leifwalsh) January 21, 2019 $ FORCE_PID=42 LD_PRELOAD=./getpid.so bash -c 'echo $$' 42 For forcing specific bad ssh key generation when the RNG was busted... -- 𝙺𝚎𝚎𝚜 𝙲𝚘𝚘𝚔 (@kees_c