From 129623416cc01c193203958a59cfa936b5bc693a Mon Sep 17 00:00:00 2001 From: Ahmed Arif Date: Thu, 14 May 2026 10:57:13 +0200 Subject: [PATCH] [SDK][CMAKE] Link libgcc_eh into C++ targets when available The build uses -nostdlib which prevents GCC from auto-linking libgcc_eh.a. This library provides the SEH unwind symbols (_Unwind_Resume, __emutls_get_address, etc.) needed by C++ exception handling. Without it, any C++ target compiled with -fexceptions fails to link with undefined references to these symbols. Add a libgcc_eh INTERFACE target that conditionally pulls in libgcc_eh.a when the toolchain provides it (as on SEH-enabled x86_64), falling back to a no-op otherwise (SJLJ/DWARF toolchains). --- sdk/cmake/gcc.cmake | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sdk/cmake/gcc.cmake b/sdk/cmake/gcc.cmake index 83feb26c0da..1be6aa6c7db 100644 --- a/sdk/cmake/gcc.cmake +++ b/sdk/cmake/gcc.cmake @@ -657,12 +657,19 @@ set_target_properties(libgcc PROPERTIES IMPORTED_LOCATION ${LIBGCC_LOCATION}) # libgcc needs kernel32 and winpthread (an appropriate CRT must be linked manually) target_link_libraries(libgcc INTERFACE libwinpthread libkernel32) +add_library(libgcc_eh INTERFACE) +target_link_libraries(libgcc_eh INTERFACE libgcc) +# only add libgcc_eh.a if it exists (SEH toolchains have it, SJLJ/DWARF do not) +execute_process(COMMAND ${GXX_EXECUTABLE} -print-file-name=libgcc_eh.a OUTPUT_VARIABLE _LIBGCC_EH_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) +if(EXISTS "${_LIBGCC_EH_PATH}") + target_link_libraries(libgcc_eh INTERFACE "${_LIBGCC_EH_PATH}") +endif() + add_library(libsupc++ STATIC IMPORTED GLOBAL) execute_process(COMMAND ${GXX_EXECUTABLE} -print-file-name=libsupc++.a OUTPUT_VARIABLE LIBSUPCXX_LOCATION) string(STRIP ${LIBSUPCXX_LOCATION} LIBSUPCXX_LOCATION) set_target_properties(libsupc++ PROPERTIES IMPORTED_LOCATION ${LIBSUPCXX_LOCATION}) -# libsupc++ requires libgcc and stdc++compat -target_link_libraries(libsupc++ INTERFACE libgcc stdc++compat) +target_link_libraries(libsupc++ INTERFACE libgcc_eh libgcc stdc++compat) add_library(libmingwex STATIC IMPORTED) execute_process(COMMAND ${GXX_EXECUTABLE} -print-file-name=libmingwex.a OUTPUT_VARIABLE LIBMINGWEX_LOCATION)