|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Aaron R Robinson <arobins@microsoft.com> |
| 3 | +Date: Fri, 14 Nov 2025 11:01:28 -0800 |
| 4 | +Subject: [PATCH] [release/9.0-staging] Add flags when the clang's major |
| 5 | + version is > 20.0 (#121151) |
| 6 | +Backport: https://github.com/dotnet/runtime/pull/121151 |
| 7 | + |
| 8 | +## Customer Impact |
| 9 | + |
| 10 | +- [x] Customer reported |
| 11 | +- [ ] Found internally |
| 12 | + |
| 13 | +These issues were reported in |
| 14 | +https://github.com/dotnet/runtime/issues/119706 as problems with |
| 15 | +clang-21 on Fedora 43. The investigation uncovered that clang introduced |
| 16 | +a potentially breaking change in clang-20 that we do not currently |
| 17 | +consume. These build changes impact VMR related builds when linux |
| 18 | +distrobutions performing source build adopt clang-21. |
| 19 | + |
| 20 | +clang-20 breaking change log - |
| 21 | +https://releases.llvm.org/20.1.0/tools/clang/docs/ReleaseNotes.html#potentially-breaking-changes. |
| 22 | + |
| 23 | +This PR contains the minimal changes needed to fix issues from the |
| 24 | +following PR https://github.com/dotnet/runtime/pull/120775. |
| 25 | + |
| 26 | +.NET 10: https://github.com/dotnet/runtime/pull/121124 |
| 27 | +.NET 8: https://github.com/dotnet/runtime/pull/121150 |
| 28 | + |
| 29 | +## Regression |
| 30 | + |
| 31 | +- [ ] Yes |
| 32 | +- [x] No |
| 33 | + |
| 34 | +Build with the new clang-21 compiler will cause the runtime to crash. |
| 35 | + |
| 36 | +## Testing |
| 37 | + |
| 38 | +This has been validated using various legs and examples to demonstrate |
| 39 | +the usage of undefined behavior these flags convert into "defined" |
| 40 | +behavior in C/C++. |
| 41 | + |
| 42 | +## Risk |
| 43 | + |
| 44 | +Low. This has zero impact on our production build since we specifically |
| 45 | +target clang-18. This is only valid for those partners that are using |
| 46 | +clang-20+. |
| 47 | +--- |
| 48 | + eng/native/configurecompiler.cmake | 18 +++++++++++++++--- |
| 49 | + src/coreclr/debug/di/rspriv.h | 4 ++-- |
| 50 | + src/coreclr/debug/di/rsthread.cpp | 12 ++++++------ |
| 51 | + 3 files changed, 23 insertions(+), 11 deletions(-) |
| 52 | + |
| 53 | +diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake |
| 54 | +index 109b947e4eb..c114c03a9a1 100644 |
| 55 | +--- a/eng/native/configurecompiler.cmake |
| 56 | ++++ b/eng/native/configurecompiler.cmake |
| 57 | +@@ -526,9 +526,21 @@ if (CLR_CMAKE_HOST_UNIX) |
| 58 | + # Disable frame pointer optimizations so profilers can get better call stacks |
| 59 | + add_compile_options(-fno-omit-frame-pointer) |
| 60 | + |
| 61 | +- # Make signed arithmetic overflow of addition, subtraction, and multiplication wrap around |
| 62 | +- # using twos-complement representation (this is normally undefined according to the C++ spec). |
| 63 | +- add_compile_options(-fwrapv) |
| 64 | ++ if((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 20.0) OR |
| 65 | ++ (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20.0)) |
| 66 | ++ # Make signed overflow well-defined. Implies the following flags in clang-20 and above. |
| 67 | ++ # -fwrapv - Make signed arithmetic overflow of addition, subtraction, and multiplication wrap around |
| 68 | ++ # using twos-complement representation (this is normally undefined according to the C++ spec). |
| 69 | ++ # -fwrapv-pointer - The same as -fwrapv but for pointers. |
| 70 | ++ add_compile_options(-fno-strict-overflow) |
| 71 | ++ |
| 72 | ++ # Suppress C++ strict aliasing rules. This matches our use of MSVC. |
| 73 | ++ add_compile_options(-fno-strict-aliasing) |
| 74 | ++ else() |
| 75 | ++ # Make signed arithmetic overflow of addition, subtraction, and multiplication wrap around |
| 76 | ++ # using twos-complement representation (this is normally undefined according to the C++ spec). |
| 77 | ++ add_compile_options(-fwrapv) |
| 78 | ++ endif() |
| 79 | + |
| 80 | + if(CLR_CMAKE_HOST_APPLE) |
| 81 | + # Clang will by default emit objc_msgSend stubs in Xcode 14, which ld from earlier Xcodes doesn't understand. |
| 82 | +diff --git a/src/coreclr/debug/di/rspriv.h b/src/coreclr/debug/di/rspriv.h |
| 83 | +index 7e2b49b3170..119ca6f7c08 100644 |
| 84 | +--- a/src/coreclr/debug/di/rspriv.h |
| 85 | ++++ b/src/coreclr/debug/di/rspriv.h |
| 86 | +@@ -6404,8 +6404,8 @@ private: |
| 87 | + // Lazily initialized. |
| 88 | + EXCEPTION_RECORD * m_pExceptionRecord; |
| 89 | + |
| 90 | +- static const CorDebugUserState kInvalidUserState = CorDebugUserState(-1); |
| 91 | +- CorDebugUserState m_userState; // This is the current state of the |
| 92 | ++ static const int kInvalidUserState = -1; |
| 93 | ++ int m_userState; // This is the current state of the |
| 94 | + // thread, at the time that the |
| 95 | + // left side synchronized |
| 96 | + |
| 97 | +diff --git a/src/coreclr/debug/di/rsthread.cpp b/src/coreclr/debug/di/rsthread.cpp |
| 98 | +index cd7f79867a5..8c4f3317eff 100644 |
| 99 | +--- a/src/coreclr/debug/di/rsthread.cpp |
| 100 | ++++ b/src/coreclr/debug/di/rsthread.cpp |
| 101 | +@@ -783,7 +783,7 @@ CorDebugUserState CordbThread::GetUserState() |
| 102 | + m_userState = pDAC->GetUserState(m_vmThreadToken); |
| 103 | + } |
| 104 | + |
| 105 | +- return m_userState; |
| 106 | ++ return (CorDebugUserState)m_userState; |
| 107 | + } |
| 108 | + |
| 109 | + |
| 110 | +@@ -887,7 +887,7 @@ HRESULT CordbThread::CreateStepper(ICorDebugStepper ** ppStepper) |
| 111 | + //Returns true if current user state of a thread is USER_WAIT_SLEEP_JOIN |
| 112 | + bool CordbThread::IsThreadWaitingOrSleeping() |
| 113 | + { |
| 114 | +- CorDebugUserState userState = m_userState; |
| 115 | ++ int userState = m_userState; |
| 116 | + if (userState == kInvalidUserState) |
| 117 | + { |
| 118 | + //If m_userState is not ready, we'll read from DAC only part of it which |
| 119 | +@@ -3721,14 +3721,14 @@ HRESULT CordbUnmanagedThread::SetupFirstChanceHijackForSync() |
| 120 | + LOG((LF_CORDB, LL_INFO10000, "CUT::SFCHFS: hijackCtx started as:\n")); |
| 121 | + LogContext(GetHijackCtx()); |
| 122 | + |
| 123 | +- // Save the thread's full context for all platforms except for x86 because we need the |
| 124 | ++ // Save the thread's full context for all platforms except for x86 because we need the |
| 125 | + // DT_CONTEXT_EXTENDED_REGISTERS to avoid getting incomplete information and corrupt the thread context |
| 126 | + DT_CONTEXT context; |
| 127 | +-#ifdef TARGET_X86 |
| 128 | ++#ifdef TARGET_X86 |
| 129 | + context.ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_EXTENDED_REGISTERS; |
| 130 | + #else |
| 131 | + context.ContextFlags = DT_CONTEXT_FULL; |
| 132 | +-#endif |
| 133 | ++#endif |
| 134 | + |
| 135 | + BOOL succ = DbiGetThreadContext(m_handle, &context); |
| 136 | + _ASSERTE(succ); |
| 137 | +@@ -3739,7 +3739,7 @@ HRESULT CordbUnmanagedThread::SetupFirstChanceHijackForSync() |
| 138 | + LOG((LF_CORDB, LL_ERROR, "CUT::SFCHFS: DbiGetThreadContext error=0x%x\n", error)); |
| 139 | + } |
| 140 | + |
| 141 | +-#ifdef TARGET_X86 |
| 142 | ++#ifdef TARGET_X86 |
| 143 | + GetHijackCtx()->ContextFlags = DT_CONTEXT_FULL | DT_CONTEXT_EXTENDED_REGISTERS; |
| 144 | + #else |
| 145 | + GetHijackCtx()->ContextFlags = DT_CONTEXT_FULL; |
0 commit comments