Fix tracing lib problems in multiple PALs. Issue #3164.
authorMike McLaughlin <mikem@microsoft.com>
Fri, 12 Feb 2016 22:47:12 +0000 (14:47 -0800)
committerMike McLaughlin <mikem@microsoft.com>
Sat, 13 Feb 2016 01:35:34 +0000 (17:35 -0800)
Moved the tracepointprovider loading in miscpalapi.cpp to separate library that
is only linked by libcoreclr.so.

src/dlls/mscoree/coreclr/CMakeLists.txt
src/pal/inc/pal.h
src/pal/src/CMakeLists.txt
src/pal/src/exception/signal.cpp
src/pal/src/include/pal/process.h
src/pal/src/init/pal.cpp
src/pal/src/misc/miscpalapi.cpp
src/pal/src/misc/tracepointprovider.cpp [new file with mode: 0644]
src/pal/src/thread/process.cpp
src/pal/src/thread/thread.cpp

index 0901404913033b88d6a84c0b120db0d2cff8dd31..9795d4126226bd0acdd37b84ed488441ec9d1197 100644 (file)
@@ -108,6 +108,7 @@ else()
     list(APPEND CORECLR_LIBRARIES
         ${START_WHOLE_ARCHIVE} # force all PAL objects to be included so all exports are available  
         coreclrpal
+        tracepointprovider
         ${END_WHOLE_ARCHIVE} 
         mscorrc_debug
         palrt
index cc4a695d043d0fac41174b00aae923b7937f399d..8ba8c9b2e3d336547c592d834d4d76b79dc7082a 100644 (file)
@@ -493,26 +493,6 @@ typedef long time_t;
 typedef DWORD (PALAPI *PTHREAD_START_ROUTINE)(LPVOID lpThreadParameter);
 typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE;
 
-
-/******************* Tracing Initialization *******************************/
-
-#if defined(__LINUX__)
-
-// Constructor priority is set to 200, which allows for constructors to
-// guarantee that they run before or after this constructor by setting
-// their priority appropriately.
-
-// Priority values must be greater than 100.  The lower the value,
-// the higher the priority.
-static
-void
-__attribute__((__unused__))
-__attribute__((constructor (200)))
-PAL_InitializeTracing(void);
-
-#endif
-
-
 /******************* PAL-Specific Entrypoints *****************************/
 
 PALIMPORT
index 9828d304333d45c0274519be3c1799074c1e8972..ff0d1c381d8b0d991f66397330e4a3df2f21ea08 100644 (file)
@@ -202,6 +202,11 @@ add_library(coreclrpal
   ${PLATFORM_SOURCES}
 )
 
+add_library(tracepointprovider
+  STATIC
+  misc/tracepointprovider.cpp
+)
+
 if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
   find_library(COREFOUNDATION CoreFoundation)
   find_library(CORESERVICES CoreServices)
index 35a3de35d321a0b28536bb53fe76f9750e92c369..25136a703b32e7b26c7d754e2c4f931c87cdf707 100644 (file)
@@ -227,7 +227,7 @@ static void sigill_handler(int code, siginfo_t *siginfo, void *context)
         restore_signal(code, &g_previous_sigill);
     }
 
-    PROCShutdownProcess();
+    PROCNotifyProcessShutdown();
 }
 
 /*++
@@ -274,7 +274,7 @@ static void sigfpe_handler(int code, siginfo_t *siginfo, void *context)
         restore_signal(code, &g_previous_sigfpe);
     }
 
-    PROCShutdownProcess();
+    PROCNotifyProcessShutdown();
 }
 
 /*++
@@ -344,7 +344,7 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context)
         restore_signal(code, &g_previous_sigsegv);
     }
 
-    PROCShutdownProcess();
+    PROCNotifyProcessShutdown();
 }
 
 /*++
@@ -392,7 +392,7 @@ static void sigtrap_handler(int code, siginfo_t *siginfo, void *context)
         PROCAbort();
     }
 
-    PROCShutdownProcess();
+    PROCNotifyProcessShutdown();
 }
 
 /*++
@@ -447,7 +447,7 @@ static void sigbus_handler(int code, siginfo_t *siginfo, void *context)
         restore_signal(code, &g_previous_sigbus);
     }
 
-    PROCShutdownProcess();
+    PROCNotifyProcessShutdown();
 }
 
 /*++
@@ -465,7 +465,7 @@ static void sigint_handler(int code, siginfo_t *siginfo, void *context)
 {
     TRACE("SIGINT signal; chaining to previous sigaction\n");
 
-    PROCShutdownProcess();
+    PROCNotifyProcessShutdown();
 
     // Restore the original or default handler and resend signal
     restore_signal(code, &g_previous_sigint);
@@ -487,7 +487,7 @@ static void sigquit_handler(int code, siginfo_t *siginfo, void *context)
 {
     TRACE("SIGQUIT signal; chaining to previous sigaction\n");
 
-    PROCShutdownProcess();
+    PROCNotifyProcessShutdown();
 
     // Restore the original or default handler and resend signal
     restore_signal(code, &g_previous_sigquit);
@@ -554,7 +554,7 @@ PAL_ERROR InjectActivationInternal(CorUnix::CPalThread* pThread)
     int status = pthread_kill(pThread->GetPThreadSelf(), INJECT_ACTIVATION_SIGNAL);
     if (status != 0)
     {
-        PROCShutdownProcess();
+        PROCNotifyProcessShutdown();
 
         // Failure to send the signal is fatal. There are only two cases when sending
         // the signal can fail. First, if the signal ID is invalid and second, 
index 724214ca5d3b4b9ec7c547149a96c01f7a94f904..bd78f9bc1208548ad3f2a469e3e7ebcdbd5fa862 100644 (file)
@@ -132,14 +132,14 @@ void PROCAbort();
 
 /*++
 Function:
-  PROCShutdownProcess
+  PROCNotifyProcessShutdown
   
   Calls the abort handler to do any shutdown cleanup. Call be
   called from the unhandled native exception handler.
 
 (no return value)
 --*/
-void PROCShutdownProcess();
+void PROCNotifyProcessShutdown();
 
 /*++
 Function:
index ab9614f5fb3d10cd02b5f242ccd7474857e2e570..b2efdf2779bbbf96e2e5b9c61ca906b532804de4 100644 (file)
@@ -242,7 +242,7 @@ Initialize(
         // Initialize the environment.
         if (FALSE == MiscInitialize())
         {
-            goto done;
+            goto CLEANUP0;
         }
 
         // Initialize debug channel settings before anything else.
@@ -250,7 +250,7 @@ Initialize(
         // MiscInitialize.
         if (FALSE == DBG_init_channels())
         {
-            goto done;
+            goto CLEANUP0;
         }
 
 #if _DEBUG
@@ -271,6 +271,7 @@ Initialize(
             // we use large numbers of threads or have many open files.
         }
 
+
         /* initialize the shared memory infrastructure */
         if (!SHMInitialize())
         {
@@ -572,6 +573,7 @@ CLEANUP1a:
 CLEANUP1:
     SHMCleanup();
 CLEANUP0:
+    TLSCleanup();
     ERROR("PAL_Initialize failed\n");
     SetLastError(palError);
 done:
index 10a71e3907d764666dee9229969b91e4d6931e5f..44ba18b9071b92f0ec3a89903d5044aa4ea096b8 100644 (file)
@@ -50,80 +50,6 @@ SET_DEFAULT_DEBUG_CHANNEL(MISC);
 static const char RANDOM_DEVICE_NAME[] ="/dev/random";
 static const char URANDOM_DEVICE_NAME[]="/dev/urandom";
 
-
-/*++
-
-Initialization logic for LTTng tracepoint providers.
-
---*/
-#if defined(__LINUX__)
-
-static const char tpLibName[] = "libcoreclrtraceptprovider.so";
-
-
-/*++
-
-NOTE: PAL_InitializeTracing MUST NOT depend on anything in the PAL itself
-as it is called prior to PAL initialization.
-
---*/
-static
-void
-PAL_InitializeTracing(void)
-{
-    // Get the path to the currently executing shared object (libcoreclr.so).
-    Dl_info info;
-    int succeeded = dladdr((void *)PAL_InitializeTracing, &info);
-    if(!succeeded)
-    {
-        return;
-    }
-
-    // Copy the path and modify the shared object name to be the tracepoint provider.
-    char tpProvPath[MAX_LONGPATH];
-    int pathLen = strlen(info.dli_fname);
-    int tpLibNameLen = strlen(tpLibName);
-
-    // Find the length of the full path without the shared object name, including the trailing slash.
-    int lastTrailingSlashLen = -1;
-    for(int i=pathLen-1; i>=0; i--)
-    {
-        if(info.dli_fname[i] == '/')
-        {
-            lastTrailingSlashLen = i+1;
-            break;
-        }
-    }
-
-    // Make sure we found the last trailing slash.
-    if(lastTrailingSlashLen == -1)
-    {
-        return;
-    }
-
-    // Make sure that the final path is shorter than MAX_PATH.
-    // +1 ensures that the string can be NULL-terminated.
-    if((lastTrailingSlashLen + tpLibNameLen + 1) > MAX_LONGPATH)
-    {
-        return;
-    }
-
-    // Copy the path without the shared object name.
-    memcpy(&tpProvPath, info.dli_fname, lastTrailingSlashLen);
-
-    // Append the shared object name for the tracepoint provider.
-    memcpy(&tpProvPath[lastTrailingSlashLen], &tpLibName, tpLibNameLen);
-
-    // NULL-terminate the string.
-    tpProvPath[lastTrailingSlashLen + tpLibNameLen] = '\0';
-
-    // Load the tracepoint provider.
-    // It's OK if this fails - that just means that tracing dependencies aren't available.
-    dlopen(tpProvPath, RTLD_NOW | RTLD_GLOBAL);
-}
-
-#endif
-
 /*++
 
 Function :
diff --git a/src/pal/src/misc/tracepointprovider.cpp b/src/pal/src/misc/tracepointprovider.cpp
new file mode 100644 (file)
index 0000000..68f898d
--- /dev/null
@@ -0,0 +1,112 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*++
+
+Module Name:
+
+    tracepointprovider.cpp
+
+Abstract:
+
+    Trace point provider support
+
+Revision History:
+
+--*/
+
+#include "pal/palinternal.h"
+#include "pal/dbgmsg.h"
+#include "pal/file.h"
+#include "pal/process.h"
+#include "pal/module.h"
+#include "pal/malloc.hpp"
+
+#include <errno.h>
+#include <unistd.h> 
+#include <pthread.h>
+#include <dlfcn.h>
+
+SET_DEFAULT_DEBUG_CHANNEL(MISC);
+
+/*++
+
+Initialization logic for LTTng tracepoint providers.
+
+--*/
+#if defined(__LINUX__)
+
+static const char tpLibName[] = "libcoreclrtraceptprovider.so";
+
+
+/*++
+
+NOTE: PAL_InitializeTracing MUST NOT depend on anything in the PAL itself
+as it is called prior to PAL initialization.
+
+Constructor priority is set to 200, which allows for constructors to
+guarantee that they run before or after this constructor by setting
+their priority appropriately.
+
+Priority values must be greater than 100.  The lower the value,
+the higher the priority.
+
+--*/
+__attribute__((__unused__))
+__attribute__((constructor (200)))
+static void
+PAL_InitializeTracing(void)
+{
+    // Get the path to the currently executing shared object (libcoreclr.so).
+    Dl_info info;
+    int succeeded = dladdr((void *)PAL_InitializeTracing, &info);
+    if(!succeeded)
+    {
+        return;
+    }
+
+    // Copy the path and modify the shared object name to be the tracepoint provider.
+    char tpProvPath[MAX_LONGPATH];
+    int pathLen = strlen(info.dli_fname);
+    int tpLibNameLen = strlen(tpLibName);
+
+    // Find the length of the full path without the shared object name, including the trailing slash.
+    int lastTrailingSlashLen = -1;
+    for(int i=pathLen-1; i>=0; i--)
+    {
+        if(info.dli_fname[i] == '/')
+        {
+            lastTrailingSlashLen = i+1;
+            break;
+        }
+    }
+
+    // Make sure we found the last trailing slash.
+    if(lastTrailingSlashLen == -1)
+    {
+        return;
+    }
+
+    // Make sure that the final path is shorter than MAX_PATH.
+    // +1 ensures that the string can be NULL-terminated.
+    if((lastTrailingSlashLen + tpLibNameLen + 1) > MAX_LONGPATH)
+    {
+        return;
+    }
+
+    // Copy the path without the shared object name.
+    memcpy(&tpProvPath, info.dli_fname, lastTrailingSlashLen);
+
+    // Append the shared object name for the tracepoint provider.
+    memcpy(&tpProvPath[lastTrailingSlashLen], &tpLibName, tpLibNameLen);
+
+    // NULL-terminate the string.
+    tpProvPath[lastTrailingSlashLen + tpLibNameLen] = '\0';
+
+    // Load the tracepoint provider.
+    // It's OK if this fails - that just means that tracing dependencies aren't available.
+    dlopen(tpProvPath, RTLD_NOW | RTLD_GLOBAL);
+}
+
+#endif
\ No newline at end of file
index eb2e8d5b29371a047ee4b7af55ac664cbe757653..c5f79f553244be1866f7ce24a993693d52d03f28 100644 (file)
@@ -2537,7 +2537,7 @@ DestroyProcessModules(IN ProcessModules *listHead)
 
 /*++
 Function:
-  PROCShutdownProcess
+  PROCNotifyProcessShutdown
   
   Calls the abort handler to do any shutdown cleanup. Call be called 
   from the unhandled native exception handler.
@@ -2545,9 +2545,9 @@ Function:
 (no return value)
 --*/
 __attribute__((destructor)) 
-void PROCShutdownProcess()
+void PROCNotifyProcessShutdown()
 {
-    TRACE("PROCShutdownProcess %p\n", g_shutdownCallback.RawValue());
+    TRACE("PROCNotifyProcessShutdown %p\n", g_shutdownCallback.RawValue());
 
     PSHUTDOWN_CALLBACK callback = InterlockedExchangePointer(&g_shutdownCallback, NULL);
     if (callback != NULL)
@@ -2569,7 +2569,7 @@ PAL_NORETURN
 void
 PROCAbort()
 {
-    PROCShutdownProcess();
+    PROCNotifyProcessShutdown();
     abort();
 }
 
@@ -3214,7 +3214,7 @@ CorUnix::TerminateCurrentProcessNoExit(BOOL bTerminateUnconditionally)
     locked = PALInitLock();
     if(locked && PALIsInitialized())
     {
-        PROCShutdownProcess();
+        PROCNotifyProcessShutdown();
         PALCommonCleanup();
     }
 }
index f3a93a9b79e645d9d8215cce1c95b21aa24792f7..57462166c88dfe2f2c3e1a8af4dade2cfdcc8256 100644 (file)
@@ -206,6 +206,8 @@ Function:
 VOID TLSCleanup()
 {
     SPINLOCKDestroy(&free_threads_spinlock);
+
+    pthread_key_delete(thObjKey);
 }
 
 /*++