From 58b620fa04ebcfe70a46e9c97ee60bbc8a4f6146 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Thu, 6 Apr 2023 15:46:31 -0400 Subject: [PATCH 1/2] Suppress clang-16 warnings (#81573) --- eng/native/configurecompiler.cmake | 9 +++++++++ eng/native/init-compiler.sh | 4 ++-- src/coreclr/dlls/mscordbi/CMakeLists.txt | 5 +---- src/coreclr/dlls/mscordbi/mscordbi.cpp | 15 +++++++++++++++ src/libraries/Native/Unix/CMakeLists.txt | 9 +++++++++ src/native/corehost/apphost/static/CMakeLists.txt | 4 ++-- ...orts.src => singlefilehost_freebsdexports.src} | 4 ++++ .../apphost/static/singlefilehost_unixexports.src | 4 ---- 8 files changed, 42 insertions(+), 12 deletions(-) rename src/native/corehost/apphost/static/{singlefilehost_OSXexports.src => singlefilehost_freebsdexports.src} (81%) diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index f3526deb19fa0..1a43b710c618b 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -367,6 +367,15 @@ if (CLR_CMAKE_HOST_UNIX) add_compile_options(-Wno-incompatible-ms-struct) add_compile_options(-Wno-reserved-identifier) + + # clang 16.0 introduced buffer hardening https://discourse.llvm.org/t/rfc-c-buffer-hardening/65734 + # which we are not conforming to yet. + add_compile_options(-Wno-unsafe-buffer-usage) + + # other clang 16.0 suppressions + add_compile_options(-Wno-single-bit-bitfield-constant-conversion) + add_compile_options(-Wno-cast-function-type-strict) + add_compile_options(-Wno-incompatible-function-pointer-types-strict) else() add_compile_options(-Wno-unknown-pragmas) add_compile_options(-Wno-uninitialized) diff --git a/eng/native/init-compiler.sh b/eng/native/init-compiler.sh index 567d18da4747a..e215bd75ff158 100755 --- a/eng/native/init-compiler.sh +++ b/eng/native/init-compiler.sh @@ -46,8 +46,8 @@ if [[ -z "$CLR_CC" ]]; then # Set default versions if [[ -z "$majorVersion" ]]; then # note: gcc (all versions) and clang versions higher than 6 do not have minor version in file name, if it is zero. - if [[ "$compiler" == "clang" ]]; then versions=( 11 10 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5 ) - elif [[ "$compiler" == "gcc" ]]; then versions=( 11 10 9 8 7 6 5 4.9 ); fi + if [[ "$compiler" == "clang" ]]; then versions=( 16 15 14 13 12 11 10 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5 ) + elif [[ "$compiler" == "gcc" ]]; then versions=( 12 11 10 9 8 7 6 5 4.9 ); fi for version in "${versions[@]}"; do parts=(${version//./ }) diff --git a/src/coreclr/dlls/mscordbi/CMakeLists.txt b/src/coreclr/dlls/mscordbi/CMakeLists.txt index c7a23c9923fe1..4a03a788a71a5 100644 --- a/src/coreclr/dlls/mscordbi/CMakeLists.txt +++ b/src/coreclr/dlls/mscordbi/CMakeLists.txt @@ -99,10 +99,7 @@ elseif(CLR_CMAKE_HOST_UNIX) mscordaccore ) - # COREDBI_LIBRARIES is mentioned twice because ld is one pass linker and will not find symbols - # if they are defined after they are used. Having all libs twice makes sure that ld will actually - # find all symbols. - target_link_libraries(mscordbi ${COREDBI_LIBRARIES} ${COREDBI_LIBRARIES}) + target_link_libraries(mscordbi ${COREDBI_LIBRARIES}) add_dependencies(mscordbi mscordaccore) diff --git a/src/coreclr/dlls/mscordbi/mscordbi.cpp b/src/coreclr/dlls/mscordbi/mscordbi.cpp index afd2cfe800225..489c552a0bd3e 100644 --- a/src/coreclr/dlls/mscordbi/mscordbi.cpp +++ b/src/coreclr/dlls/mscordbi/mscordbi.cpp @@ -26,3 +26,18 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) // Defer to the main debugging code. return DbgDllMain(hInstance, dwReason, lpReserved); } + +#if defined(HOST_LINUX) && defined(TARGET_LINUX) +PALIMPORT HINSTANCE PALAPI DAC_PAL_RegisterModule(IN LPCSTR lpLibFileName); +PALIMPORT VOID PALAPI DAC_PAL_UnregisterModule(IN HINSTANCE hInstance); + +HINSTANCE PALAPI PAL_RegisterModule(IN LPCSTR lpLibFileName) +{ + return DAC_PAL_RegisterModule(lpLibFileName); +} + +VOID PALAPI PAL_UnregisterModule(IN HINSTANCE hInstance) +{ + DAC_PAL_UnregisterModule(hInstance); +} +#endif diff --git a/src/libraries/Native/Unix/CMakeLists.txt b/src/libraries/Native/Unix/CMakeLists.txt index 997849f9ecf92..89c2317d107a8 100644 --- a/src/libraries/Native/Unix/CMakeLists.txt +++ b/src/libraries/Native/Unix/CMakeLists.txt @@ -51,6 +51,15 @@ if(CMAKE_C_COMPILER_ID STREQUAL Clang) add_compile_options(-Wthread-safety) add_compile_options(-Wno-thread-safety-analysis) add_compile_options(-Wno-reserved-identifier) + + # clang 16.0 introduced buffer hardening https://discourse.llvm.org/t/rfc-c-buffer-hardening/65734 + # which we are not conforming to yet. + add_compile_options(-Wno-unsafe-buffer-usage) + + # other clang 16.0 suppressions + add_compile_options(-Wno-single-bit-bitfield-constant-conversion) + add_compile_options(-Wno-cast-function-type-strict) + add_compile_options(-Wno-incompatible-function-pointer-types-strict) elseif(CMAKE_C_COMPILER_ID STREQUAL GNU) add_compile_options(-Wno-stringop-truncation) endif() diff --git a/src/native/corehost/apphost/static/CMakeLists.txt b/src/native/corehost/apphost/static/CMakeLists.txt index a00c79139863f..6d491c086da98 100644 --- a/src/native/corehost/apphost/static/CMakeLists.txt +++ b/src/native/corehost/apphost/static/CMakeLists.txt @@ -73,8 +73,8 @@ if(CLR_CMAKE_TARGET_WIN32) add_linker_flag("/DEF:${CMAKE_CURRENT_SOURCE_DIR}/singlefilehost.def") else() - if(CLR_CMAKE_TARGET_OSX) - set(DEF_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/singlefilehost_OSXexports.src) + if(CLR_CMAKE_TARGET_FREEBSD) + set(DEF_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/singlefilehost_freebsdexports.src) else() set(DEF_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/singlefilehost_unixexports.src) endif() diff --git a/src/native/corehost/apphost/static/singlefilehost_OSXexports.src b/src/native/corehost/apphost/static/singlefilehost_freebsdexports.src similarity index 81% rename from src/native/corehost/apphost/static/singlefilehost_OSXexports.src rename to src/native/corehost/apphost/static/singlefilehost_freebsdexports.src index 18d5697e84580..767c9546a3b47 100644 --- a/src/native/corehost/apphost/static/singlefilehost_OSXexports.src +++ b/src/native/corehost/apphost/static/singlefilehost_freebsdexports.src @@ -9,3 +9,7 @@ g_dacTable ; Used by profilers MetaDataGetDispenser + +; FreeBSD needs to reexport these +__progname +environ diff --git a/src/native/corehost/apphost/static/singlefilehost_unixexports.src b/src/native/corehost/apphost/static/singlefilehost_unixexports.src index 1f9c517821855..18d5697e84580 100644 --- a/src/native/corehost/apphost/static/singlefilehost_unixexports.src +++ b/src/native/corehost/apphost/static/singlefilehost_unixexports.src @@ -9,7 +9,3 @@ g_dacTable ; Used by profilers MetaDataGetDispenser - -; FreeBSD needs to reexport these -__progname -environ From ac85caf0ed34d5a70bc1c337c75df2230ccc78de Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Thu, 6 Apr 2023 16:39:27 -0400 Subject: [PATCH 2/2] Fix DBI loading problem on Linux (#82461) --- src/coreclr/dlls/mscordbi/CMakeLists.txt | 16 +++++++++++++++- src/coreclr/dlls/mscordbi/mscordbi.cpp | 15 --------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/coreclr/dlls/mscordbi/CMakeLists.txt b/src/coreclr/dlls/mscordbi/CMakeLists.txt index 4a03a788a71a5..b7618b324c260 100644 --- a/src/coreclr/dlls/mscordbi/CMakeLists.txt +++ b/src/coreclr/dlls/mscordbi/CMakeLists.txt @@ -99,7 +99,21 @@ elseif(CLR_CMAKE_HOST_UNIX) mscordaccore ) - target_link_libraries(mscordbi ${COREDBI_LIBRARIES}) + # Before llvm 16, lld was setting `--undefined-version` by default. The default was + # flipped to `--no-undefined-version` in lld 16, so we will explicitly set it to + # `--undefined-version` for our use-case. + include(CheckLinkerFlag OPTIONAL) + if(COMMAND check_linker_flag) + check_linker_flag(CXX -Wl,--undefined-version LINKER_SUPPORTS_UNDEFINED_VERSION) + if (LINKER_SUPPORTS_UNDEFINED_VERSION) + add_linker_flag(-Wl,--undefined-version) + endif(LINKER_SUPPORTS_UNDEFINED_VERSION) + endif(COMMAND check_linker_flag) + + # COREDBI_LIBRARIES is mentioned twice because ld is one pass linker and will not find symbols + # if they are defined after they are used. Having all libs twice makes sure that ld will actually + # find all symbols. + target_link_libraries(mscordbi ${COREDBI_LIBRARIES} ${COREDBI_LIBRARIES}) add_dependencies(mscordbi mscordaccore) diff --git a/src/coreclr/dlls/mscordbi/mscordbi.cpp b/src/coreclr/dlls/mscordbi/mscordbi.cpp index 489c552a0bd3e..afd2cfe800225 100644 --- a/src/coreclr/dlls/mscordbi/mscordbi.cpp +++ b/src/coreclr/dlls/mscordbi/mscordbi.cpp @@ -26,18 +26,3 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) // Defer to the main debugging code. return DbgDllMain(hInstance, dwReason, lpReserved); } - -#if defined(HOST_LINUX) && defined(TARGET_LINUX) -PALIMPORT HINSTANCE PALAPI DAC_PAL_RegisterModule(IN LPCSTR lpLibFileName); -PALIMPORT VOID PALAPI DAC_PAL_UnregisterModule(IN HINSTANCE hInstance); - -HINSTANCE PALAPI PAL_RegisterModule(IN LPCSTR lpLibFileName) -{ - return DAC_PAL_RegisterModule(lpLibFileName); -} - -VOID PALAPI PAL_UnregisterModule(IN HINSTANCE hInstance) -{ - DAC_PAL_UnregisterModule(hInstance); -} -#endif