Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 619649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:40:42+00:00 2026-05-13T18:40:42+00:00

I need to write a little library, to be loaded by setting LD_PRELOAD, and

  • 0

I need to write a little library, to be loaded by setting LD_PRELOAD, and which will override some functions in the standard C library but also call those functions in the standard library. Specifically, I want my shiny new library to let users provide their own resolv.conf so they can, eg, specify their default domain, or set aliases in it for long hostnames. I’m going to need a good understanding of how the linker works if I’m to do this, so can anyone point me at some good documentation, that doesn’t assume that I know it all already and just need a reference, but also doesn’t assume that I’m a complete idiot?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:40:42+00:00Added an answer on May 13, 2026 at 6:40 pm

    If you are using the GNU linker, one thing you need to know about is RTLD_NEXT. This allows you to “find the next occurrence of a function in the search order after the current library”.

    This way, you can override a standard function and still be able to call the original version.

    I used this function in a version of malloc that tracks allocation stats. I needed to override malloc to collect the stats but I still wanted the original version of malloc to do the allocation:

    static void *(*next_malloc)(size_t) = NULL;
    
    __attribute__ ((constructor))
    static void
    bootstrap() 
    {
        next_malloc = dlsym(RTLD_NEXT, "malloc");
    }
    
    void *
    malloc(size_t size)
    {
        void *ptr = next_malloc(size);
    
        // collect some stats
    
        return ptr;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a script in Matlab, which will read some data from
I need to write a little wizard application into which a user inputs some
I need to write custom ord and chr functions. I'm writing a little program
Please forgive my attempts at necromancy, but I actually need to write some code
We are creating a javascript library from scratch and we need some utilities functions,
I need to write a little ruby function that does word wrapping. I have
I need to write a little program in C that parses a string. I
I need to write some input data files for a python program, and I
Let's say I'm writing a little library in C -- some data structure, say.
I need to write a procedure that will allow me to select x amount

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.