Re: [PATCH] Link to -lssp when available (fixes mingw build)

Eli Zaretskii
2019-12-19T15:49:40Z

> Cc: gdb-patches <gdb-patches@sourceware.org>
> From: Pedro Alves <palves@redhat.com>
> Date: Thu, 19 Dec 2019 14:19:45 +0000
>
> >> libstdc++ and libgcc DLLs indeed have the same problem. Which is why
> >> I mentioned the fact that the binary of GDB 9.0.90 produced by the
> >> MinGW build had dependencies on these two. I solved that locally by
> >> linking with "CXX='g++ -static-libstdc++ -static-libgcc'", but I
> >> thought Pedro once said these dependencies shouldn't happen, and I
> >> still hope we could understand why they suddenly appeared.
> >
> > Hm, I wonder why Pedro said that. GDB uses good amounts of the C++
> > standard library, so I would totally expect libstdc++ to appear.
>
> There's some confusion going on here. We must certainly link with
> libstdc++ somehow. The only question is whether we link to the
> dynamic or static version.

Right. Sorry if I inadvertently caused this confusion.

> Linking with static versions of the runtime is problematic if we also link
> with some other library that is itself linked with a different libstdc++.
> Multiple versions of libstc++/libgcc in a program is a recipe for disaster,
> such as for example C++ exceptions not working properly. Discussions about
> this started a few years ago when we switched to C++. E.g.:
>
> https://sourceware.org/ml/gdb-patches/2017-02/msg00705.html
>
> That is why the top level configure was recently changed to avoid the
> -static-libstc++/-static-libgcc:
>
> https://gcc.gnu.org/ml/gcc-patches/2019-08/msg00287.html
>
> Note that the patch added a new --with-static-standard-libraries
> configure switch which you can use to get back the previous behavior
> of linking with the static versions of the standard libraries.

Ah, okay, so I need to use that configure option. (The original
problem with exceptions thrown across shared libraries doesn't exist
in my build, because no C++-compiled shared library is used, they all
are linked statically.)

> I think a NEWS entry for that switch would be helpful, though.

Right, that would be helpful.

> > I don't really know what libgcc is used for.
>
> libgcc is GCC's low-level runtime library. It's an essential part
> of any program compiled by GCC:
> https://gcc.gnu.org/onlinedocs/gccint/Libgcc.html

Not every GCC complied program needs it, IME, but whenever libstdc++
is linked in, so is libgcc.