C / C ++ Dynamic Link Library Overload

In my application, I need to change some functions of the glibc source code. I only need to change the pthread part. For example, I changed multi-threaded related functions like pthread_create.c or pthread_mutex_lock.c in the source code. Then, when my specific program is running, I want to specify it to use the modified functions, when it is necessary to use these functions, and this will not affect other functions. In addition, I do not want to specify the whole version of glibc when the program is running. I need to ask about your help, is there a good solution to this problem? Thank you !! Dean

+4
source share
1 answer

This task is for a shared library interpolator. Here is a great article.

If the function is in the shared library, the runtime linker can be assigned to invoke another function “inserted”. Interposer can completely replace functionality or can increase it. A great example is the malloc family of functions, a memory leak detector and a heap creation tool can be based on a set of intermediate elements between a user program and system calls.

Interpolators work only for shared (.so) libraries. Static (.a) libraries directly reference the executable, and calls cannot be easily intercepted.

All major Linux support benefits come with LD_PRELOAD functions.

pthread_create.

+1

Source: https://habr.com/ru/post/1653592/


All Articles