Skip to content

Restore exclusion of "gcc_eh" from implicit link libraries

Christian Pfeiffer requested to merge ChrisTX/cmake:implicit-lib-gcceh into master

Since !800 (merged) we no longer filter out all gcc* implicit link libraries. This allows mixing of gcc and non-gcc compilers across languages. However, this caused a subtle problem with how GCC makes exception handling symbols available to linked binaries.

GCC (at least on MinGW) provides two different libraries with exception handling symbols:

  • gcc_s: A shared library with -fvisibility=default, used by -shared-libgcc.
  • gcc_eh: A static library with -fvisibility=hidden, used by -static-libgcc.

The C compiler (on MinGW) defaults to -static-libgcc and uses gcc_eh. The C++ compiler defaults to -shared-libgcc and uses gcc_s when linking shared libraries and executables so that exceptions can propagate across shared libraries. When linking a mixed-language binary, the C++ compiler should be used along with its choice of gcc_s. In this case gcc_eh should not be added even though the C compiler implies it because gcc_s supersedes it.

Since the above-mentioned change, CMake is adding gcc_eh to C++ link lines that also contain C code on MinGW. This causes both gcc_s and gcc_eh to be used, which is incorrect. We can fix this simply by excluding gcc_eh from the C compiler's implicit link libraries.

Fixes: #17436 (closed)

Edited by Brad King

Merge request reports

Loading