dlopen, dlsym & how to call a function of the libc library inside a function defined in your custom library with the same name.

(If you like articles title longer that the article itself, you’re on the right place.)

As the subject of the article, here’s a brief piece of code to define a library with a function whose name is also in libc. In the example we want to call the libc time() function inside our time() function.

  • adsense



  • You can note the use of dlsym() function with the use of the flag RTDL_NEXT, that (from the man page) will find the next occurrence of a function in the search order after the current library. This allows one to provide a wrapper around a function in another shared library.

    The code on my github.com.

    Please note that you can find the gcc commands inside the branch, file compile.sh.

    Leave a Comment

    Your email address will not be published.