For some reasons, I need to add a function to glibc. I tried to add a sample function to pthread.so:
glibc/nptl/my_add.c
, which return a sum of two numbers.glibc/nptl/Makefile
, Add the my_add
to "libpthread-routines"$ readelf build/nptl/pthread.so.0 -s | grep "my_add"
326: 0000000000000000 0 FILE LOCAL DEFAULT ABS my_add.c
458: 0000000000013550 4 FUNC LOCAL DEFAULT 14 __my_add
510: 0000000000013550 4 FUNC LOCAL DEFAULT 14 my_add@@GLIBC_2.2.5
I think that maybe I am ought to modify the gcc flags in Makefile, but I don't know how to do it. The glibc is complicated for me, but I hava to slove it.
please help me, thanks!
my_add.c
#include "pthreadP.h"
#include <shlib-compat.h>
int __my_add (int a, int b)
{
return a+b;
}
versioned_symbol (libpthread, __my_add, my_add, GLIBC_2_1);
but the func's bind value is LOCAL.
This is because GLIBC build process tightly controls the set of external symbols (so no undesirable or internal-only symbols are exported).
You must add my_add
function to nptl/Versions
file.