Fix build with CorecLR 6.0.
authorMikhail Kurinnoi <m.kurinnoi@samsung.com>
Thu, 9 Sep 2021 16:06:34 +0000 (09:06 -0700)
committerAlexander Soldatov/Platform Lab /SRR/Staff Engineer/Samsung Electronics <soldatov.a@samsung.com>
Fri, 10 Sep 2021 16:35:32 +0000 (19:35 +0300)
clr.cmake
src/CMakeLists.txt
src/trace/commontrace.cpp
src/trace/commontrace.h

index 0294627ae908dfdb447397501bdd8d7386514539..9d19cc04e69094631bc72012ce9213b56ac6c7ff 100644 (file)
--- a/clr.cmake
+++ b/clr.cmake
@@ -119,19 +119,25 @@ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--build-id=sha1")
 #-----------------------------------
 if (CLR_CMAKE_PLATFORM_ARCH_AMD64)
   add_definitions(-D_AMD64_)
+  add_definitions(-DHOST_AMD64) # https://github.com/dotnet/runtime/commit/fcd862e06413a000f9cafa9d2f359226c60b9b42
   add_definitions(-D_WIN64)
   add_definitions(-DAMD64)
   add_definitions(-DBIT64=1)
+  add_definitions(-DHOST_64BIT=1) # https://github.com/dotnet/runtime/commit/fcd862e06413a000f9cafa9d2f359226c60b9b42
 elseif (CLR_CMAKE_PLATFORM_ARCH_I386)
   add_definitions(-D_X86_)
+  add_definitions(-DHOST_X86) # https://github.com/dotnet/runtime/commit/fcd862e06413a000f9cafa9d2f359226c60b9b42
 elseif (CLR_CMAKE_PLATFORM_ARCH_ARM)
   add_definitions(-D_ARM_)
   add_definitions(-DARM)
+  add_definitions(-DHOST_ARM) # https://github.com/dotnet/runtime/commit/fcd862e06413a000f9cafa9d2f359226c60b9b42
 elseif (CLR_CMAKE_PLATFORM_ARCH_ARM64)
   add_definitions(-D_ARM64_)
   add_definitions(-DARM64)
+  add_definitions(-DHOST_ARM64) # https://github.com/dotnet/runtime/commit/fcd862e06413a000f9cafa9d2f359226c60b9b42
   add_definitions(-D_WIN64)
   add_definitions(-DBIT64=1)
+  add_definitions(-DHOST_64BIT=1) # https://github.com/dotnet/runtime/commit/fcd862e06413a000f9cafa9d2f359226c60b9b42
 else ()
   clr_unknown_arch()
 endif ()
index 8d7e65ea0f1f76ef6df25a634808e9bed7c56014..e74b9b17b1c0e3a6d7162743fd150d70f400efba 100644 (file)
@@ -49,7 +49,7 @@ set_property(
 )
 
 target_link_libraries(coreprof
-  libcorguids
+  libcorguids
   # utilcodestaticnohost
   # gcinfo
   # mscorrc_debug
index 66e4e07c3ea9ffde2d7823a1657ef5605a50da1c..dee5a93d98ec95b3de9a5d5053fa41aa7bf47178 100644 (file)
@@ -46,6 +46,7 @@
 // NOTE: currently only one instance of the CommonTrace can exist at each
 // moment, so global variable can be used.
 static CommonTrace *g_pCommonTraceObject = nullptr;
+static thread_local ThreadInfo *tlsThreadInfo = nullptr;
 
 static void SampleHandlerStub(
     int code, siginfo_t *siginfo, void *context)
@@ -98,7 +99,6 @@ static struct timespec MsToTS(unsigned long ms)
 
 CommonTrace::CommonTrace(Profiler &profiler)
     : BaseTrace(profiler)
-    , m_tlsThreadInfoIndex(TLS_OUT_OF_INDEXES)
     , m_threadStorage()
     , m_classStorage()
     , m_pauseAction()
@@ -117,17 +117,6 @@ CommonTrace::~CommonTrace()
     // NOTE: we are dealing with a partially destroyed m_profiler!
     this->Shutdown();
 
-    if (m_tlsThreadInfoIndex != TLS_OUT_OF_INDEXES)
-    {
-        if (!TlsFree(m_tlsThreadInfoIndex))
-        {
-            m_profiler.HandleHresult(
-                "CommonTrace::~CommonTrace(): TlsFree()",
-                HRESULT_FROM_WIN32(GetLastError())
-            );
-        }
-    }
-
     _ASSERTE(g_pCommonTraceObject == this);
     g_pCommonTraceObject = nullptr;
 }
@@ -170,19 +159,6 @@ void CommonTrace::ProcessConfig(ProfilerConfig &config)
     }
 #endif
 
-    //
-    // Initializing thread local storage.
-    //
-
-    m_tlsThreadInfoIndex = TlsAlloc();
-    if (m_tlsThreadInfoIndex == TLS_OUT_OF_INDEXES)
-    {
-        throw HresultException(
-            "CommonTrace::ProcessConfig(): TlsAlloc()",
-            HRESULT_FROM_WIN32(GetLastError())
-        );
-    }
-
     //
     // Setup signal handlers.
     //
@@ -684,20 +660,7 @@ ThreadInfo *CommonTrace::GetThreadInfo() noexcept
         // Try to get thread info from the local storage.
         //
 
-        ThreadInfo *threadInfo = reinterpret_cast<ThreadInfo*>(
-            TlsGetValue(m_tlsThreadInfoIndex));
-
-        if (threadInfo == nullptr)
-        {
-            DWORD lastError = GetLastError();
-            if (lastError != ERROR_SUCCESS)
-            {
-                m_profiler.HandleHresult(
-                    "CommonTrace::GetThreadInfo(): TlsGetValue()",
-                    HRESULT_FROM_WIN32(lastError)
-                );
-            }
-        }
+        ThreadInfo *threadInfo = tlsThreadInfo;
 
         HRESULT hr;
 
@@ -748,13 +711,7 @@ ThreadInfo *CommonTrace::GetThreadInfo() noexcept
             // Save new thead info to the local storage.
             //
 
-            if (!TlsSetValue(m_tlsThreadInfoIndex, threadInfo))
-            {
-                m_profiler.HandleHresult(
-                    "CommonTrace::GetThreadInfo(): TlsSetValue()",
-                    HRESULT_FROM_WIN32(GetLastError())
-                );
-            }
+            tlsThreadInfo = threadInfo;
         }
 
         return threadInfo;
@@ -772,8 +729,7 @@ ThreadInfo *CommonTrace::GetThreadInfoR() const noexcept
     // Try to get thread info from the local storage.
     //
 
-    ThreadInfo *threadInfo = reinterpret_cast<ThreadInfo*>(
-        TlsGetValue(m_tlsThreadInfoIndex));
+    ThreadInfo *threadInfo = tlsThreadInfo;
 
 #ifdef _TARGET_AMD64_
     if (threadInfo == nullptr)
index 2bcb0c1dabb31dd5187ccf8e1b72b7848147ac41..e66caa5576bf2c02b9ea5c6a8f1fc07646f1c3b0 100644 (file)
@@ -149,8 +149,6 @@ public:
     HRESULT GarbageCollectionFinished() noexcept;
 
 private:
-    int m_tlsThreadInfoIndex;
-
     SharedResource<ThreadStorage> m_threadStorage;
     SharedResource<ClassStorage>  m_classStorage;