static linking of gdb

Bernd Edlinger
2020-04-05T10:13:44Z

Hi,

I noticed that gdb is currently not
linking libstdc++ statically, as it did
in the past if I remember correclty.

$ ldd `which gdb`
linux-vdso.so.1 => (0x00007ffe59eb4000)
libncurses.so.5 => /lib/x86_64-linux-gnu/libncurses.so.5 (0x00007f43f4448000)
libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f43f4218000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f43f4010000)
libpython2.7.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 (0x00007f43f3aa8000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f43f3888000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f43f3680000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f43f3378000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f43f3148000)
libstdc++.so.6 => /home/ed/gnu/install/lib64/libstdc++.so.6 (0x00007f43f4698000)
libgcc_s.so.1 => /home/ed/gnu/install/lib64/libgcc_s.so.1 (0x00007f43f3128000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f43f2d58000)
/lib64/ld-linux-x86-64.so.2 (0x00007f43f4670000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f43f2b38000)

this means, this gdb that I build here will not run with the libstdc++ version
that is on my system, by default, only with the gcc version that I used to build.

We should use static libraries as much as possible, especially libstdc++ and libgcc
are not always downward compatible and are easy to make the binary unusable.

$ ldd `which gdbserver`
linux-vdso.so.1 => (0x00007ffea4384000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fac78c08000)
libstdc++.so.6 => /home/ed/gnu/install/lib64/libstdc++.so.6 (0x00007fac78e38000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fac78900000)
libgcc_s.so.1 => /home/ed/gnu/install/lib64/libgcc_s.so.1 (0x00007fac788e0000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fac786c0000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fac782f0000)
/lib64/ld-linux-x86-64.so.2 (0x00007fac78e10000)

even gdbserver is not selfcontained.

compare that to gcc:

$ ldd `which gcc`
linux-vdso.so.1 => (0x00007ffee448c000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ffa7da50000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffa7d680000)
/lib64/ld-linux-x86-64.so.2 (0x00007ffa7dd58000)

which is selfcontained.

All we should do, is at least do add -static-libstdc++ -static-libgcc
to the build rules (when using gcc at least), who knows how to do that,
please do it.

Thanks
Bernd.