diff --git a/src/coreclr/hosts/corerun/CMakeLists.txt b/src/coreclr/hosts/corerun/CMakeLists.txt index b3baaaa70fc287..2cb404a14c951b 100644 --- a/src/coreclr/hosts/corerun/CMakeLists.txt +++ b/src/coreclr/hosts/corerun/CMakeLists.txt @@ -11,6 +11,14 @@ endif(CLR_CMAKE_HOST_WIN32) #Required to expose symbols for global symbol discovery. set(CLR_CMAKE_KEEP_NATIVE_SYMBOLS TRUE) +if (CLR_CMAKE_HOST_APPLE) + # Prevent exporting symbols except for GetCurrentClrDetails from corerun. This is necessary + # to avoid a problem with local typeinfo for standard C++ EH types like std::bad_alloc, + # std::out_of_range etc. being exposed for binding for external shared libraries and causing + # mismatch in catch type matching. + add_link_options(LINKER:-exported_symbol,_GetCurrentClrDetails) +endif() + add_executable_clr(corerun corerun.cpp dotenv.cpp diff --git a/src/native/corehost/apphost/CMakeLists.txt b/src/native/corehost/apphost/CMakeLists.txt index 61ff7bc8bd9754..b74a6eb30d8f5c 100644 --- a/src/native/corehost/apphost/CMakeLists.txt +++ b/src/native/corehost/apphost/CMakeLists.txt @@ -1,4 +1,12 @@ # Licensed to the .NET Foundation under one or more agreements. # The .NET Foundation licenses this file to you under the MIT license. +if (CLR_CMAKE_HOST_APPLE) + # Prevent exporting symbols from apphost. This is necessary to avoid a problem with + # local typeinfo for standard C++ EH types like std::bad_alloc, std::out_of_range etc. + # being exposed for binding for external shared libraries and causing mismatch in + # catch type matching. + add_link_options(LINKER:-no_exported_symbols) +endif() + add_subdirectory(standalone) diff --git a/src/native/corehost/dotnet/CMakeLists.txt b/src/native/corehost/dotnet/CMakeLists.txt index 5704c911ac9568..5ff8385ff1af94 100644 --- a/src/native/corehost/dotnet/CMakeLists.txt +++ b/src/native/corehost/dotnet/CMakeLists.txt @@ -1,6 +1,14 @@ # Licensed to the .NET Foundation under one or more agreements. # The .NET Foundation licenses this file to you under the MIT license. +if (CLR_CMAKE_HOST_APPLE) + # Prevent exporting symbols from dotnet. This is necessary to avoid a problem with + # local typeinfo for standard C++ EH types like std::bad_alloc, std::out_of_range etc. + # being exposed for binding for external shared libraries and causing mismatch in + # catch type matching. + add_link_options(LINKER:-no_exported_symbols) +endif() + if(CLR_CMAKE_TARGET_WIN32) list(APPEND SOURCES dotnet.manifest