[Tizen] Fix build error for Clang-16+ (#399) accepted/tizen/unified/20240215.175757 accepted/tizen/unified/dev/20240620.010646
author이형주/MDE Lab(SR)/삼성전자 <leee.lee@samsung.com>
Thu, 15 Feb 2024 10:34:24 +0000 (19:34 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 15 Feb 2024 10:34:24 +0000 (19:34 +0900)
This commit is a mix of upstream commits specific to tizen unified.

* [release/7.0] Suppress clang-16 warnings (backport #81573) (#84444)

Fix DBI loading problem on Linux (#82461)

* Use logical and for boolean operation in bstr (#67858)

This seems like a mistake and recent versions of clang even complain
about it:

    /runtime/src/coreclr/palrt/bstr.cpp:50:13: error: use of bitwise '&' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
            if (SUCCEEDED(ULongMult(cchSize, sizeof(WCHAR), &temp)) &
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                                    &&
    /runtime/src/coreclr/pal/inc/pal.h:5144:27: note: expanded from macro 'SUCCEEDED'
    #define SUCCEEDED(Status) ((HRESULT)(Status) >= 0)
                              ^
    /runtime/src/coreclr/palrt/bstr.cpp:50:13: note: cast one or both operands to int to silence this warning
    /runtime/src/coreclr/pal/inc/pal.h:5144:27: note: expanded from macro 'SUCCEEDED'
    #define SUCCEEDED(Status) ((HRESULT)(Status) >= 0)
                              ^
    1 error generated.

* Fix Wunqualified-std-cast-call in singlefilehost (#72305)

Modified by hand due to mingling w/ other commits

---------

Co-authored-by: Antoine Martin <dev@ayakael.net>
Co-authored-by: Omair Majid <omajid@redhat.com>
eng/native/configurecompiler.cmake
src/coreclr/dlls/mscordbi/CMakeLists.txt
src/coreclr/palrt/bstr.cpp
src/libraries/Native/Unix/CMakeLists.txt
src/native/corehost/apphost/static/CMakeLists.txt
src/native/corehost/apphost/static/singlefilehost_freebsdexports.src [moved from src/native/corehost/apphost/static/singlefilehost_OSXexports.src with 81% similarity]
src/native/corehost/apphost/static/singlefilehost_unixexports.src
src/native/corehost/fxr/sdk_resolver.cpp

index 974d944..c1fbbe2 100644 (file)
@@ -378,6 +378,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)
index c7a23c9..b7618b3 100644 (file)
@@ -99,6 +99,17 @@ elseif(CLR_CMAKE_HOST_UNIX)
         mscordaccore
     )
 
+    # 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.
index 2f5ccd9..93c1da7 100644 (file)
@@ -47,7 +47,7 @@ inline HRESULT CbSysStringSize(ULONG cchSize, BOOL isByteLen, ULONG *result)
     else
     {
         ULONG temp = 0; // should not use in-place addition in ULongAdd
-        if (SUCCEEDED(ULongMult(cchSize, sizeof(WCHAR), &temp)) &
+        if (SUCCEEDED(ULongMult(cchSize, sizeof(WCHAR), &temp)) &&
             SUCCEEDED(ULongAdd(temp, constant, result)))
         {
             *result = *result & ~WIN32_ALLOC_ALIGN;
index 6931f62..d59ec3b 100644 (file)
@@ -28,6 +28,15 @@ set(VERSION_FILE_PATH "${CMAKE_BINARY_DIR}/version.c")
 # We mark the function which needs exporting with PALEXPORT
 add_compile_options(-fvisibility=hidden)
 
+# 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)
+
 add_compile_options(-Wno-format-nonliteral)
 add_compile_options(-Wno-disabled-macro-expansion)
 add_compile_options(-Wno-padded)
index a00c791..6d491c0 100644 (file)
@@ -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()
index a004e7f..e8006f7 100644 (file)
@@ -34,7 +34,7 @@ sdk_resolver::sdk_resolver(bool allow_prerelease) :
 }
 
 sdk_resolver::sdk_resolver(fx_ver_t version, sdk_roll_forward_policy roll_forward, bool allow_prerelease) :
-    version(move(version)),
+    version(std::move(version)),
     roll_forward(roll_forward),
     allow_prerelease(allow_prerelease)
 {
@@ -357,7 +357,7 @@ bool sdk_resolver::parse_global_file(pal::string_t global_file_path)
         }
     }
 
-    global_file = move(global_file_path);
+    global_file = std::move(global_file_path);
     return true;
 }
 
@@ -471,7 +471,7 @@ bool sdk_resolver::resolve_sdk_path_and_version(const pal::string_t& dir, pal::s
         if (pal::directory_exists(probe_path))
         {
             trace::verbose(_X("Found requested SDK directory [%s]"), probe_path.c_str());
-            sdk_path = move(probe_path);
+            sdk_path = std::move(probe_path);
             resolved_version = version;
 
             // The SDK path has been resolved
@@ -523,7 +523,7 @@ bool sdk_resolver::resolve_sdk_path_and_version(const pal::string_t& dir, pal::s
 
         changed = true;
         resolved_version = ver;
-        resolved_version_str = move(version);
+        resolved_version_str = std::move(version);
     }
 
     if (changed)