Use a custom dynamic linker with gdb

Viewed 204

I have built a custom version of glibc. It introduces some new symbols that I use with a custom shared library. For this I add a new version: SHIM

I use gcc -g -o my_test my_test.c -l my_so.so -Wl,-dynamic-linker=/local/home/me/glibc-build/ld-linux-x86-64.so.2 to build a test executable. It needs to use the runtime linker of my custom glibc build so it can link the custom glibc symbols used in my_so.so. This actually works.

But when I use gdb to debug the executable, I find that the default runtime linker is used. I get the following error:

/bin/bash: /lib64/ld-linux-x86-64.so.2: version `SHIM' not found (required by /local/home/me/glibc-build/libc.so.6)

How can I have gdb use my custom runtime linker? I tried to use gdb --args /local/home/me/glibc-build/ld-linux-x86-64.so.2 ./my_test, but I end up with the same error

1 Answers

I use gcc -g -o my_test my_test.c -l my_so.so -Wl,-dynamic-linker=/local/home/me/glibc-build/ld-linux-x86-64.so.2 to build a test executable.

Using above command to link the executable is incomplete. I am guessing that you must also set LD_LIBRARY_PATH=/local/home/me/glibc-build:/local/home/me/glibc-build/elf:... in order to make my_test work, and it that setting of LD_LIBRARY_PATH that is preventing /bin/bash from working.

You can confirm this by running (in your current environment):

bash -c ./my_test

which is exactly what GDB is doing, and which should fail with the same error.

If my guess is correct, the best way to fix this is to unset LD_LIBRARY_PATH and relink your executable with -Wl,-rpath=/local/home/me/glibc-build:/local/home/me/glibc-build/elf:... so that my_test doesn't require setting LD_LIBRARY_PATH at all.

Related