Add prefix to DAC's PAL exports for alpine (dotnet/coreclr#18873)
authorMike McLaughlin <mikem@microsoft.com>
Fri, 13 Jul 2018 06:45:39 +0000 (23:45 -0700)
committerGitHub <noreply@github.com>
Fri, 13 Jul 2018 06:45:39 +0000 (23:45 -0700)
Added some cmake logic to create assembly include mapping files. One that maps the
prefixed name (DAC_foo) to the actual name (foo) which is included in the DAC module
and another that maps the actual name to the prefixed name that is included in the SOS,
DBI and createdump modules.

The data exports like IID_IUnknown are not prefixed and don't need to be (immutable static data).

There were some C++ exports functions exported with their decorated names in
the CatchHardwareExceptionHolder and NativeExceptionHolderBase classes. Created
PAL_* style export functions that implements the code.

Fix lldb plugin cmake file to use LLDB_H/LLDB_LIB env vars to build it.

Commit migrated from https://github.com/dotnet/coreclr/commit/b89e2305a2c953272c997242d01b66b1bb1e661e

18 files changed:
src/coreclr/CMakeLists.txt
src/coreclr/functions.cmake
src/coreclr/generateexportedsymbols.awk
src/coreclr/generateredefinesfile.awk [new file with mode: 0644]
src/coreclr/generateversionscript.awk
src/coreclr/src/ToolBox/SOS/Strike/CMakeLists.txt
src/coreclr/src/ToolBox/SOS/lldbplugin/CMakeLists.txt
src/coreclr/src/debug/createdump/CMakeLists.txt
src/coreclr/src/dlls/mscordac/CMakeLists.txt
src/coreclr/src/dlls/mscordac/libredefines.S [new file with mode: 0644]
src/coreclr/src/dlls/mscordac/mscordac_unixexports.src
src/coreclr/src/dlls/mscordac/palredefines.S [new file with mode: 0644]
src/coreclr/src/dlls/mscordbi/CMakeLists.txt
src/coreclr/src/pal/inc/pal.h
src/coreclr/src/pal/src/exception/seh.cpp
src/coreclr/src/pal/src/include/pal/thread.hpp
src/coreclr/src/palrt/guid.cpp
src/coreclr/src/palrt/guiddef.h [deleted file]

index 0e408a4..64a65e3 100644 (file)
@@ -25,6 +25,7 @@ set(VM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/vm)
 set(GENERATED_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/src/inc)
 set(GENERATED_EVENTING_DIR ${CMAKE_CURRENT_BINARY_DIR}/eventing)
 set(VERSION_FILE_PATH "${CMAKE_BINARY_DIR}/version.cpp")
+set(PAL_REDEFINES_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/dlls/mscordac/palredefines.S)
 
 set(CORECLR_SET_RPATH ON)
 if(CORECLR_SET_RPATH)
index c228683..d868445 100644 (file)
@@ -107,6 +107,27 @@ function(generate_exports_file)
                               PROPERTIES GENERATED TRUE)
 endfunction()
 
+function(generate_exports_file_prefix inputFilename outputFilename prefix)
+
+  if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
+    set(AWK_SCRIPT generateexportedsymbols.awk)
+  else()
+    set(AWK_SCRIPT generateversionscript.awk)
+    if (NOT ${prefix} STREQUAL "")
+        set(AWK_VARS ${AWK_VARS} -v prefix=${prefix})
+    endif()
+  endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
+
+  add_custom_command(
+    OUTPUT ${outputFilename}
+    COMMAND ${AWK} -f ${CMAKE_SOURCE_DIR}/${AWK_SCRIPT} ${AWK_VARS} ${inputFilename} >${outputFilename}
+    DEPENDS ${inputFilename} ${CMAKE_SOURCE_DIR}/${AWK_SCRIPT}
+    COMMENT "Generating exports file ${outputFilename}"
+  )
+  set_source_files_properties(${outputFilename}
+                              PROPERTIES GENERATED TRUE)
+endfunction()
+
 function(add_precompiled_header header cppFile targetSources)
   if(MSVC)
     set(precompiledBinary "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/stdafx.pch")
index 1d9b200..120897f 100644 (file)
@@ -1,11 +1,12 @@
 { 
-       # Remove the CR character in case the sources are mapped from
-       # a Windows share and contain CRLF line endings
-       gsub(/\r/,"", $0);
+    # Remove the CR character in case the sources are mapped from
+    # a Windows share and contain CRLF line endings
+    gsub(/\r/,"", $0);
 
-       # Skip empty lines and comment lines starting with semicolon
-       if (NF && !match($0, /^[:space:]*;/))
-       {
-               print "_"  $0;
-       }
+    # Skip empty lines and comment lines starting with semicolon
+    if (NF && !match($0, /^[:space:]*;/))
+    {
+        gsub(/^#/,"", $0);
+        print "_"  $0;
+    }
 } 
diff --git a/src/coreclr/generateredefinesfile.awk b/src/coreclr/generateredefinesfile.awk
new file mode 100644 (file)
index 0000000..592c19a
--- /dev/null
@@ -0,0 +1,22 @@
+# "jump" is the jump instruction for the platform
+# "prefix1" is the prefix of what is being mapped from
+# "prefix2" is the prefix of what is being mapped to
+{ 
+    # Remove the CR character in case the sources are mapped from
+    # a Windows share and contain CRLF line endings
+    gsub(/\r/,"", $0);
+    
+    # Skip empty lines and comment lines starting with semicolon
+    if (NF && !match($0, /^[:space:]*;/))
+    {
+        # Only process the entries that begin with "#"
+        if (match($0, /^#.*/))
+        {
+            gsub(/^#/,"", $0);
+            print "LEAF_ENTRY " prefix1 $0 ", _TEXT"
+            print "    " jump " EXTERNAL_C_FUNC(" prefix2 $0 ")"
+            print "LEAF_END " prefix1 $0 ", _TEXT"
+            print ""
+        }
+    }
+} 
index 226c6a5..7efc537 100644 (file)
@@ -1,19 +1,28 @@
 BEGIN {
-       print "V1.0 {";
-       print "    global:";
+    print "V1.0 {";
+    print "    global:";
 } 
 { 
-       # Remove the CR character in case the sources are mapped from
-       # a Windows share and contain CRLF line endings
-       gsub(/\r/,"", $0);
+    # Remove the CR character in case the sources are mapped from
+    # a Windows share and contain CRLF line endings
+    gsub(/\r/,"", $0);
        
-       # Skip empty lines and comment lines starting with semicolon
-       if (NF && !match($0, /^[ \t]*;/))
+    # Skip empty lines and comment lines starting with semicolon
+    if (NF && !match($0, /^[ \t]*;/))
+    {
+        # Only prefix the entries that start with "#"
+       if (match($0, /^#.*/))
        {
-               print "        "  $0 ";";
+           gsub(/^#/,"", $0);
+           print "        "prefix $0 ";";
        }
+        else
+        {
+           print "        "$0 ";";
+       }
+    }
 } 
 END {
-       print "    local: *;"
-       print "};";
+    print "    local: *;"
+    print "};";
 }
index 65c3f95..a9bd176 100644 (file)
@@ -38,6 +38,7 @@ elseif(CLR_CMAKE_PLATFORM_ARCH_ARM64)
   add_definitions(-DDBG_TARGET_64BIT)
   add_definitions(-DDBG_TARGET_WIN64=1)
 endif()
+
 add_definitions(-DSTRIKE)  
 
 remove_definitions(-DUNICODE)
@@ -183,6 +184,11 @@ endif()
 
 list(APPEND SOS_SOURCES ${SOS_SOURCES_ARCH})
 
+# Add the DAC PAL export mapping file
+if(CLR_CMAKE_PLATFORM_LINUX)
+    list(APPEND SOS_SOURCES ${PAL_REDEFINES_FILE})
+endif(CLR_CMAKE_PLATFORM_LINUX)
+
 if(CLR_CMAKE_PLATFORM_LINUX OR CLR_CMAKE_PLATFORM_FREEBSD OR CLR_CMAKE_PLATFORM_NETBSD)
     # Add linker exports file option
     set(EXPORTS_LINKER_OPTION -Wl,--version-script=${EXPORTS_FILE})
@@ -195,6 +201,10 @@ endif(CLR_CMAKE_PLATFORM_DARWIN)
 
 add_library_clr(sos SHARED ${SOS_SOURCES})
 
+if(CLR_CMAKE_PLATFORM_LINUX)
+    add_dependencies(sos pal_redefines_file)
+endif(CLR_CMAKE_PLATFORM_LINUX)
+
 if(CLR_CMAKE_PLATFORM_UNIX)
     add_custom_target(sos_exports DEPENDS ${EXPORTS_FILE})
     add_dependencies(sos sos_exports)
index e87ac8b..96aec30 100644 (file)
@@ -45,57 +45,72 @@ elseif(CLR_CMAKE_PLATFORM_ARCH_ARM64)
     SET(REQUIRE_LLDBPLUGIN false)
 endif()
 
-set(LLVM_HOST_DIR "$ENV{LLVM_HOME}")
-set(WITH_LLDB_LIBS "${LLVM_HOST_DIR}/lib" CACHE PATH "Path to LLDB libraries")
-set(WITH_LLDB_INCLUDES "${LLVM_HOST_DIR}/include" CACHE PATH "Path to LLDB headers")
+if(NOT $ENV{LLVM_HOME} STREQUAL "")
+    set(LLDB_INCLUDE_DIR "$ENV{LLVM_HOME}/include")
+    set(LLDB_LIB_DIR "$ENV{LLVM_HOME}/lib")
+else()
+    if(NOT $ENV{LLDB_INCLUDE_DIR} STREQUAL "")
+       set(LLDB_INCLUDE_DIR "$ENV{LLDB_INCLUDE_DIR}")
+    endif()
+    if(NOT $ENV{LLDB_LIB_DIR} STREQUAL "")
+       set(LLDB_LIB_DIR "$ENV{LLDB_LIB_DIR}")
+    endif()
+endif()
 
 if(NOT ENABLE_LLDBPLUGIN)
     return()
 endif()
 
-if (CLR_CMAKE_PLATFORM_DARWIN)
+if(NOT $ENV{LLDB_LIB} STREQUAL "")
+    set(LLDB_LIB "$ENV{LLDB_LIB}")
+else()
     # Check for LLDB library
-    find_library(LLDB NAMES LLDB lldb lldb-6.0 lldb-5.0 lldb-4.0 lldb-3.9 lldb-3.8 lldb-3.7 lldb-3.6 lldb-3.5 PATHS "${WITH_LLDB_LIBS}" PATH_SUFFIXES llvm NO_DEFAULT_PATH)
-    find_library(LLDB NAMES LLDB lldb lldb-6.0 lldb-5.0 lldb-4.0 lldb-3.9 lldb-3.8 lldb-3.7 lldb-3.6 lldb-3.5 PATH_SUFFIXES llvm)
-    if(LLDB STREQUAL LLDB-NOTFOUND)
+    if(CLR_CMAKE_PLATFORM_DARWIN)
+        find_library(LLDB_LIB NAMES LLDB lldb lldb-6.0 lldb-5.0 lldb-4.0 lldb-3.9 lldb-3.8 lldb-3.7 lldb-3.6 lldb-3.5 PATHS "${WITH_LLDB_LIBS}" PATH_SUFFIXES llvm NO_DEFAULT_PATH)
+        find_library(LLDB_LIB NAMES LLDB lldb lldb-6.0 lldb-5.0 lldb-4.0 lldb-3.9 lldb-3.8 lldb-3.7 lldb-3.6 lldb-3.5 PATH_SUFFIXES llvm)
+        if(LLDB_LIB STREQUAL LLDB_LIB-NOTFOUND)
+            if(REQUIRE_LLDBPLUGIN)
+                set(MESSAGE_MODE FATAL_ERROR)
+            else()
+                set(MESSAGE_MODE WARNING)
+            endif()
+            message(${MESSAGE_MODE} "Cannot find lldb library. Try installing Xcode. You may need to set LLVM_HOME, LLDB_LIB_DIR or LLDB_LIB if the build still can't find it.")
+            return()
+        endif()
+    endif()
+endif()
+
+message(STATUS "LLDB_LIB: ${LLDB_LIB}")
+
+if(NOT $ENV{LLDB_H} STREQUAL "")
+    set(LLDB_H "$ENV{LLDB_H}")
+else()
+    # Check for LLDB headers
+    # Multiple versions of LLDB can install side-by-side, so we need to check for lldb in various locations.
+    # If the file in a directory is found the result is stored in the variable and the search will not be repeated unless the variable is cleared.
+    find_path(LLDB_H "lldb/API/LLDB.h" PATHS "${WITH_LLDB_INCLUDES}" NO_DEFAULT_PATH)
+    find_path(LLDB_H "lldb/API/LLDB.h")
+    find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/lib/llvm-6.0/include")
+    find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/lib/llvm-5.0/include")
+    find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/lib/llvm-4.0/include")
+    find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/lib/llvm-3.9/include")
+    find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/lib/llvm-3.8/include")
+    find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/lib/llvm-3.7/include")
+    find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/lib/llvm-3.6/include")
+    find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/lib/llvm-3.5/include")
+    #FreeBSD
+    find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/local/llvm39/include")
+    find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/local/llvm38/include")
+
+    if(LLDB_H STREQUAL LLDB_H-NOTFOUND)
         if(REQUIRE_LLDBPLUGIN)
             set(MESSAGE_MODE FATAL_ERROR)
         else()
             set(MESSAGE_MODE WARNING)
         endif()
-        message(${MESSAGE_MODE} "Cannot find lldb-3.5, lldb-3.6, lldb-3.8, lldb-3.9, lldb-4.0, lldb-5.0 or lldb-6.0. Try installing liblldb-3.9-dev (or the appropriate package for your platform). You may need to set LLVM_HOME if the build still can't find it.")
-
+        message(${MESSAGE_MODE} "Cannot find LLDB.h Try installing lldb-3.9-dev (or the appropriate package for your platform). You may need to set LLVM_HOME or LLDB_INCLUDE_DIR if the build still can't find it.")
         return()
     endif()
-
-    message(STATUS "LLDB: ${LLDB}")
-endif()
-
-# Check for LLDB headers
-# Multiple versions of LLDB can install side-by-side, so we need to check for lldb in various locations.
-# If the file in a directory is found the result is stored in the variable and the search will not be repeated unless the variable is cleared.
-find_path(LLDB_H "lldb/API/LLDB.h" PATHS "${WITH_LLDB_INCLUDES}" NO_DEFAULT_PATH)
-find_path(LLDB_H "lldb/API/LLDB.h")
-find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/lib/llvm-6.0/include")
-find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/lib/llvm-5.0/include")
-find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/lib/llvm-4.0/include")
-find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/lib/llvm-3.9/include")
-find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/lib/llvm-3.8/include")
-find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/lib/llvm-3.7/include")
-find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/lib/llvm-3.6/include")
-find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/lib/llvm-3.5/include")
-#FreeBSD
-find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/local/llvm39/include")
-find_path(LLDB_H "lldb/API/LLDB.h" PATHS "/usr/local/llvm38/include")
-
-if(LLDB_H STREQUAL LLDB_H-NOTFOUND)
-    if(REQUIRE_LLDBPLUGIN)
-        set(MESSAGE_MODE FATAL_ERROR)
-    else()
-        set(MESSAGE_MODE WARNING)
-    endif()
-    message(${MESSAGE_MODE} "Cannot find LLDB.h Try installing lldb-3.9-dev (or the appropriate package for your platform). You may need to set LLVM_HOME if the build still can't find it.")
-    return()
 endif()
 
 message(STATUS "LLDB_H: ${LLDB_H}")
@@ -121,7 +136,7 @@ _add_library(sosplugin SHARED ${SOURCES})
 add_dependencies(sosplugin sos)
 
 if (CLR_CMAKE_PLATFORM_DARWIN)
-   target_link_libraries(sosplugin ${LLDB})
+   target_link_libraries(sosplugin ${LLDB_LIB})
 endif()
 
 # add the install targets
index 4272cfc..4e5b7a1 100644 (file)
@@ -20,7 +20,7 @@ include_directories(BEFORE ${VM_DIR})
 
 add_definitions(-DPAL_STDCPP_COMPAT=1)
 
-add_compile_options(-fPIC)
+add_compile_options(-fPIE)
 
 set(CREATEDUMP_SOURCES 
     createdump.cpp 
@@ -36,11 +36,14 @@ _add_library(createdump_lib
 
 _add_executable(createdump
     main.cpp
+    ${PAL_REDEFINES_FILE}
 )
 
+add_dependencies(createdump pal_redefines_file)
+
 target_link_libraries(createdump
     createdump_lib
-    # share the PAL in the dac module
+    # share the PAL/corguids in the dac module
     mscordaccore
 )
 
index fba524a..ec52903 100644 (file)
@@ -20,10 +20,10 @@ if(WIN32)
 
     set(CURRENT_BINARY_DIR_FOR_CONFIG ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
 
-    #Preprocess exports definition file
+    # Preprocess exports definition file
     preprocess_def_file(${CMAKE_CURRENT_SOURCE_DIR}/${DEF_SOURCES} ${CURRENT_BINARY_DIR_FOR_CONFIG}/mscordac.def)
 
-    #create target to add file dependency on mscordac.def
+    # Create target to add file dependency on mscordac.def
     add_custom_target(mscordaccore_def DEPENDS ${CURRENT_BINARY_DIR_FOR_CONFIG}/mscordac.def)
 
     # No library groups for Win32
@@ -32,7 +32,50 @@ if(WIN32)
 else(WIN32)
     set(DEF_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/mscordac_unixexports.src)
     set(EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/mscordac.exports)
-    generate_exports_file(${DEF_SOURCES} ${EXPORTS_FILE})
+
+    # Add dependency on export file
+    add_custom_target(mscordaccore_exports DEPENDS ${EXPORTS_FILE})
+
+    if(CLR_CMAKE_PLATFORM_DARWIN)
+        generate_exports_file(${DEF_SOURCES} ${EXPORTS_FILE})
+    endif(CLR_CMAKE_PLATFORM_DARWIN)
+
+    if(CLR_CMAKE_PLATFORM_LINUX)
+
+        # Generate DAC export file with the DAC_ prefix
+        generate_exports_file_prefix(${DEF_SOURCES} ${EXPORTS_FILE} DAC_)
+
+        set(REDEFINES_FILE_AWK_SCRIPT ${CMAKE_SOURCE_DIR}/generateredefinesfile.awk)
+
+        if (CLR_CMAKE_PLATFORM_ARCH_ARM OR CLR_CMAKE_PLATFORM_ARCH_ARM64)
+            set(JUMP_INSTRUCTION b)
+        else()
+            set(JUMP_INSTRUCTION jmp)
+        endif()
+
+        # Generate the palredefines.inc file to map from the imported prefixed APIs (foo to DAC_foo)
+        set(PAL_REDEFINES_INC ${GENERATED_INCLUDE_DIR}/palredefines.inc)
+        add_custom_command(
+            OUTPUT ${PAL_REDEFINES_INC}
+            COMMAND ${AWK} -f ${REDEFINES_FILE_AWK_SCRIPT} -v jump=${JUMP_INSTRUCTION} -v prefix2=DAC_ ${DEF_SOURCES} > ${PAL_REDEFINES_INC}
+            DEPENDS ${DEF_SOURCES} ${REDEFINES_FILE_AWK_SCRIPT}
+            COMMENT "Generating PAL redefines file -> ${PAL_REDEFINES_INC}"
+        )
+        add_custom_target(pal_redefines_file DEPENDS ${PAL_REDEFINES_INC})
+
+        # Generate the libredefines.inc file for the DAC to export the prefixed APIs (DAC_foo to foo)
+        set(LIB_REDEFINES_INC ${GENERATED_INCLUDE_DIR}/libredefines.inc)
+        add_custom_command(
+            OUTPUT ${LIB_REDEFINES_INC}
+            COMMAND ${AWK} -f ${REDEFINES_FILE_AWK_SCRIPT} -v jump=${JUMP_INSTRUCTION} -v prefix1=DAC_ ${DEF_SOURCES} > ${LIB_REDEFINES_INC}
+            DEPENDS ${DEF_SOURCES} ${REDEFINES_FILE_AWK_SCRIPT}
+            COMMENT "Generating DAC export redefines file -> ${LIB_REDEFINES_INC}"
+        )
+        add_custom_target(lib_redefines_inc DEPENDS ${LIB_REDEFINES_INC})
+
+        # Add lib redefines file to DAC
+        list(APPEND CLR_DAC_SOURCES libredefines.S)
+    endif(CLR_CMAKE_PLATFORM_LINUX)
 endif(WIN32)
 
 if(CLR_CMAKE_PLATFORM_LINUX OR CLR_CMAKE_PLATFORM_FREEBSD OR CLR_CMAKE_PLATFORM_NETBSD)
@@ -64,10 +107,12 @@ _add_library(mscordacobj OBJECT mscordac.cpp)
 
 add_library_clr(mscordaccore SHARED ${CLR_DAC_SOURCES} $<TARGET_OBJECTS:mscordacobj>)
 
+if(CLR_CMAKE_PLATFORM_LINUX)
+    add_dependencies(mscordaccore lib_redefines_inc)
+endif(CLR_CMAKE_PLATFORM_LINUX)
+
 if(CLR_CMAKE_PLATFORM_UNIX)
-    add_custom_target(mscordaccore_exports DEPENDS ${EXPORTS_FILE})
     add_dependencies(mscordaccore mscordaccore_exports)
-
     set_property(TARGET mscordaccore APPEND_STRING PROPERTY LINK_FLAGS ${EXPORTS_LINKER_OPTION})
     set_property(TARGET mscordaccore APPEND_STRING PROPERTY LINK_DEPENDS ${EXPORTS_FILE})
 endif(CLR_CMAKE_PLATFORM_UNIX)
diff --git a/src/coreclr/src/dlls/mscordac/libredefines.S b/src/coreclr/src/dlls/mscordac/libredefines.S
new file mode 100644 (file)
index 0000000..2449b9e
--- /dev/null
@@ -0,0 +1,12 @@
+#if defined(_X86_) || defined(_AMD64_)
+.intel_syntax noprefix
+#endif
+
+#include "unixasmmacros.inc"
+
+#if defined(_ARM_)
+.syntax unified
+.thumb
+#endif
+
+#include "libredefines.inc"
index 77a53d7..60fae97 100644 (file)
@@ -10,179 +10,179 @@ DllMain
 PAL_RegisterModule
 PAL_UnregisterModule
 
-PAL_BindResources
-PAL_bsearch
-PAL_errno
-PAL_fflush
-PAL__flushall
-PAL_free
-PAL_fwprintf
-PAL_GetPALDirectoryW
-PAL_GetResourceString
-PAL_get_stdout
-PAL_get_stderr
-PAL_GetCurrentThread
-PAL_GetCpuLimit
-PAL_GetSymbolModuleBase
-PAL_GetTransportPipeName
-PAL_InitializeDLL
-PAL_TerminateEx
-PAL_IsDebuggerPresent
-PAL_ProbeMemory
-PAL_Random
-PAL_iswspace
-PAL_memcpy
-PAL_malloc
-PAL_realloc
-PAL_printf
-PAL_qsort
-PAL_Reenter
-PAL_fprintf
-PAL__wcstoui64
-PAL_wcstoul
-PAL_iswprint
-PAL_VirtualReserveFromExecutableMemoryAllocatorWithinRange
-PAL_VirtualUnwindOutOfProc
-PAL_wcslen
-PAL_wcsncmp
-PAL_wcsrchr
-PAL_wcscmp
-PAL_wcschr
-PAL_wcscspn
-PAL_wcscat
-PAL_wcsstr
-
-_wcsicmp
-_stricmp
-sprintf_s
-swprintf_s
-vsprintf_s
-_snprintf_s
-_snwprintf_s
-_vsnprintf_s
-_vsnwprintf_s
-_itow_s
-_i64tow_s
-memcpy_s
-sscanf_s
-
-CopyFileW
-CreateDirectoryW
-CreateFileMappingA
-CreateFileMappingW
-CreateFileA
-CreateFileW
-CreateMutexW
-CreateMutexExW
-CreateEventW
-CreateEventExW
-CreateProcessW
-CreateSemaphoreExW
-CreateStreamOnHGlobal
-CreateThread
-CloseHandle
-DebugBreak
-DeleteCriticalSection
-DeleteFileW
-DuplicateHandle
-EnterCriticalSection
-FindClose
-FindFirstFileW
-FindNextFileW
-FlushFileBuffers
-FlushInstructionCache
-FormatMessageW
-FreeLibrary
-FileTimeToSystemTime
-GetACP
-GetCPInfo
-GetCurrentDirectoryW
-GetCurrentProcess
-GetCurrentProcessId
-GetCurrentThreadId
-GetEnvironmentVariableA
-GetEnvironmentVariableW
-GetFileAttributesExW
-GetFileAttributesW
-GetFileSize
-GetFullPathNameW
-GetLastError
-GetLongPathNameW
-GetModuleFileNameW
-GetProcAddress
-GetProcessAffinityMask
-GetProcessHeap
-GetShortPathNameW
-GetStdHandle
-GetSystemInfo
-GetSystemTime
-GetSystemTimeAsFileTime
-GetTempFileNameW
-GetTempPathW
-HeapAlloc
-HeapFree
-HeapSetInformation
-IIDFromString
+; Data exports (not prefixed)
+IID_IUnknown
 IID_IClassFactory
 IID_ISequentialStream
 IID_IStream
-IID_IUnknown
 IID_ICLRDataTarget
 IID_ICorDebugDataTarget4
 IID_ICLRDataEnumMemoryRegionsCallback
-InitializeCriticalSection
-IsDBCSLeadByte
-LeaveCriticalSection
-LoadLibraryA
-LoadLibraryW
-LoadLibraryExW
-LocalAlloc
-LocalReAlloc
-LocalFree
-MapViewOfFile
-MoveFileExW
-MultiByteToWideChar
-OpenProcess
-OutputDebugStringW
-OpenEventW
-OutputDebugStringA
-QueryPerformanceCounter
-QueryPerformanceFrequency
-RaiseException
-ReadFile
-ReleaseMutex
-ReleaseSemaphore
-RemoveDirectoryW
-ResetEvent
-ResumeThread
-SearchPathW
-SetEvent
-SetFileAttributesW
-SetFilePointer
-SetLastError
-SetErrorMode
-Sleep
-SleepEx
-SwitchToThread
-TerminateProcess
-TlsAlloc
-TlsFree
-TlsGetValue
-TlsSetValue
-VirtualAlloc
-VirtualFree
-VirtualProtect
-VirtualQuery
-UnmapViewOfFile
-WaitForMultipleObjectsEx
-WaitForSingleObject
-WaitForSingleObjectEx
-WideCharToMultiByte
-WriteFile
-
 nativeStringResourceTable_mscorrc_debug
-_ZN25NativeExceptionHolderBase4PushEv
-_ZN25NativeExceptionHolderBaseC2Ev
-_ZN25NativeExceptionHolderBaseD2Ev
-_ZN28CatchHardwareExceptionHolderC1Ev
-_ZN28CatchHardwareExceptionHolderD1Ev
+
+; All the # exports are prefixed with DAC_
+#PAL_BindResources
+#PAL_CatchHardwareExceptionHolderEnter
+#PAL_CatchHardwareExceptionHolderExit
+#PAL_bsearch
+#PAL_errno
+#PAL_fflush
+#PAL__flushall
+#PAL_free
+#PAL_fwprintf
+#PAL_GetPALDirectoryW
+#PAL_GetResourceString
+#PAL_get_stdout
+#PAL_get_stderr
+#PAL_GetCurrentThread
+#PAL_GetCpuLimit
+#PAL_GetNativeExceptionHolderHead
+#PAL_GetSymbolModuleBase
+#PAL_GetTransportPipeName
+#PAL_InitializeDLL
+#PAL_TerminateEx
+#PAL_IsDebuggerPresent
+#PAL_ProbeMemory
+#PAL_Random
+#PAL_iswspace
+#PAL_memcpy
+#PAL_malloc
+#PAL_realloc
+#PAL_printf
+#PAL_qsort
+#PAL_Reenter
+#PAL_fprintf
+#PAL__wcstoui64
+#PAL_wcstoul
+#PAL_iswprint
+#PAL_VirtualReserveFromExecutableMemoryAllocatorWithinRange
+#PAL_VirtualUnwindOutOfProc
+#PAL_wcslen
+#PAL_wcsncmp
+#PAL_wcsrchr
+#PAL_wcscmp
+#PAL_wcschr
+#PAL_wcscspn
+#PAL_wcscat
+#PAL_wcsstr
+
+#_wcsicmp
+#_stricmp
+#sprintf_s
+#swprintf_s
+#vsprintf_s
+#_snprintf_s
+#_snwprintf_s
+#_vsnprintf_s
+#_vsnwprintf_s
+#_itow_s
+#_i64tow_s
+#memcpy_s
+#sscanf_s
+
+#CopyFileW
+#CreateDirectoryW
+#CreateFileMappingA
+#CreateFileMappingW
+#CreateFileA
+#CreateFileW
+#CreateMutexW
+#CreateMutexExW
+#CreateEventW
+#CreateEventExW
+#CreateProcessW
+#CreateSemaphoreExW
+#CreateThread
+#CloseHandle
+#DebugBreak
+#DeleteCriticalSection
+#DeleteFileW
+#DuplicateHandle
+#EnterCriticalSection
+#FindClose
+#FindFirstFileW
+#FindNextFileW
+#FlushFileBuffers
+#FlushInstructionCache
+#FormatMessageW
+#FreeLibrary
+#FileTimeToSystemTime
+#GetACP
+#GetCPInfo
+#GetCurrentDirectoryW
+#GetCurrentProcess
+#GetCurrentProcessId
+#GetCurrentThreadId
+#GetEnvironmentVariableA
+#GetEnvironmentVariableW
+#GetFileAttributesExW
+#GetFileAttributesW
+#GetFileSize
+#GetFullPathNameW
+#GetLastError
+#GetLongPathNameW
+#GetModuleFileNameW
+#GetProcAddress
+#GetProcessAffinityMask
+#GetProcessHeap
+#GetShortPathNameW
+#GetStdHandle
+#GetSystemInfo
+#GetSystemTime
+#GetSystemTimeAsFileTime
+#GetTempFileNameW
+#GetTempPathW
+#HeapAlloc
+#HeapFree
+#HeapSetInformation
+#InitializeCriticalSection
+#IsDBCSLeadByte
+#LeaveCriticalSection
+#LoadLibraryA
+#LoadLibraryW
+#LoadLibraryExW
+#LocalAlloc
+#LocalReAlloc
+#LocalFree
+#MapViewOfFile
+#MoveFileExW
+#MultiByteToWideChar
+#OpenProcess
+#OutputDebugStringW
+#OpenEventW
+#OutputDebugStringA
+#QueryPerformanceCounter
+#QueryPerformanceFrequency
+#RaiseException
+#ReadFile
+#ReleaseMutex
+#ReleaseSemaphore
+#RemoveDirectoryW
+#ResetEvent
+#ResumeThread
+#SearchPathW
+#SetEvent
+#SetFileAttributesW
+#SetFilePointer
+#SetLastError
+#SetErrorMode
+#Sleep
+#SleepEx
+#SwitchToThread
+#SysAllocStringLen
+#SysFreeString
+#TerminateProcess
+#TlsAlloc
+#TlsFree
+#TlsGetValue
+#TlsSetValue
+#VirtualAlloc
+#VirtualFree
+#VirtualProtect
+#VirtualQuery
+#UnmapViewOfFile
+#WaitForMultipleObjectsEx
+#WaitForSingleObject
+#WaitForSingleObjectEx
+#WideCharToMultiByte
+#WriteFile
diff --git a/src/coreclr/src/dlls/mscordac/palredefines.S b/src/coreclr/src/dlls/mscordac/palredefines.S
new file mode 100644 (file)
index 0000000..b0cd615
--- /dev/null
@@ -0,0 +1,12 @@
+#if defined(_X86_) || defined(_AMD64_)
+.intel_syntax noprefix
+#endif
+
+#include "unixasmmacros.inc"
+
+#if defined(_ARM_)
+.syntax unified
+.thumb
+#endif
+
+#include "palredefines.inc"
index 5f5ad51..e979960 100644 (file)
@@ -11,9 +11,14 @@ if(CORECLR_SET_RPATH)
 endif(CORECLR_SET_RPATH)
 
 set(MSCORDBI_SOURCES
-  mscordbi.cpp
+    mscordbi.cpp
 )  
 
+# Add the DAC PAL export mapping file
+if(CLR_CMAKE_PLATFORM_LINUX)
+    list(APPEND MSCORDBI_SOURCES ${PAL_REDEFINES_FILE})
+endif(CLR_CMAKE_PLATFORM_LINUX)
+
 if(WIN32)
     add_precompiled_header(stdafx.h stdafx.cpp MSCORDBI_SOURCES)
     
@@ -24,7 +29,7 @@ if(WIN32)
     )
 
     set(DEF_SOURCES
-      mscordbi.src
+        mscordbi.src
     )
 
     convert_to_absolute_path(DEF_SOURCES ${DEF_SOURCES})
@@ -63,15 +68,15 @@ if(CLR_CMAKE_PLATFORM_UNIX)
 endif(CLR_CMAKE_PLATFORM_UNIX)
 
 set(COREDBI_LIBRARIES
-  debug-pal
-  cordbdi
-  utilcodestaticnohost
-  ildbsymlib
-  mdcompiler-dbi
-  mdruntime-dbi
-  mdruntimerw-dbi
-  mddatasource_dbi
-  corguids
+    debug-pal
+    cordbdi
+    utilcodestaticnohost
+    ildbsymlib
+    mdcompiler-dbi
+    mdruntime-dbi
+    mdruntimerw-dbi
+    mddatasource_dbi
+    corguids
 ) 
 
 if(WIN32)
@@ -101,14 +106,18 @@ elseif(CLR_CMAKE_PLATFORM_UNIX)
         mscordaccore
     )
 
-    add_dependencies(mscordbi 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})
 
+    add_dependencies(mscordbi mscordaccore)
+
+    if(CLR_CMAKE_PLATFORM_LINUX)
+        add_dependencies(mscordbi pal_redefines_file)
+    endif(CLR_CMAKE_PLATFORM_LINUX)
+
 endif(WIN32)
 
 # add the install targets
-install_clr(mscordbi)
\ No newline at end of file
+install_clr(mscordbi)
index d5587b9..98d0ae2 100644 (file)
@@ -5030,6 +5030,16 @@ PALAPI
 PAL_SetTerminationRequestHandler(
     IN PTERMINATION_REQUEST_HANDLER terminationRequestHandler);
 
+PALIMPORT
+VOID
+PALAPI
+PAL_CatchHardwareExceptionHolderEnter();
+
+PALIMPORT
+VOID
+PALAPI
+PAL_CatchHardwareExceptionHolderExit();
+
 //
 // This holder is used to indicate that a hardware
 // exception should be raised as a C++ exception
@@ -5038,9 +5048,15 @@ PAL_SetTerminationRequestHandler(
 class CatchHardwareExceptionHolder
 {
 public:
-    CatchHardwareExceptionHolder();
+    CatchHardwareExceptionHolder()
+    {
+        PAL_CatchHardwareExceptionHolderEnter();
+    }
 
-    ~CatchHardwareExceptionHolder();
+    ~CatchHardwareExceptionHolder()
+    {
+        PAL_CatchHardwareExceptionHolderExit();
+    }
 
     static bool IsEnabled();
 };
@@ -5058,6 +5074,13 @@ public:
 
 #ifdef FEATURE_PAL_SXS
 
+class NativeExceptionHolderBase;
+
+PALIMPORT
+NativeExceptionHolderBase **
+PALAPI
+PAL_GetNativeExceptionHolderHead();
+
 extern "C++" {
 
 //
@@ -5076,9 +5099,22 @@ class NativeExceptionHolderBase
     NativeExceptionHolderBase *m_next;
 
 protected:
-    NativeExceptionHolderBase();
+    NativeExceptionHolderBase()
+    {
+        m_head = nullptr;
+        m_next = nullptr;
+    }
 
-    ~NativeExceptionHolderBase();
+    ~NativeExceptionHolderBase()
+    {
+        // Only destroy if Push was called
+        if (m_head != nullptr)
+        {
+            *m_head = m_next;
+            m_head = nullptr;
+            m_next = nullptr;
+        }
+    }
 
 public:
     // Calls the holder's filter handler.
@@ -5087,7 +5123,13 @@ public:
     // Adds the holder to the "stack" of holders. This is done explicitly instead
     // of in the constructor was to avoid the mess of move constructors combined
     // with return value optimization (in CreateHolder).
-    void Push();
+    void Push()
+    {
+        NativeExceptionHolderBase **head = PAL_GetNativeExceptionHolderHead();
+        m_head = head;
+        m_next = *head;
+        *head = this;
+    }
 
     // Given the currentHolder and locals stack range find the next holder starting with this one
     // To find the first holder, pass nullptr as the currentHolder.
index b057070..39779be 100644 (file)
@@ -364,16 +364,22 @@ PAL_ERROR SEHDisable(CPalThread *pthrCurrent)
 
 --*/
 
-CatchHardwareExceptionHolder::CatchHardwareExceptionHolder()
+extern "C" 
+void 
+PALAPI
+PAL_CatchHardwareExceptionHolderEnter()
 {
     CPalThread *pThread = InternalGetCurrentThread();
-    ++pThread->m_hardwareExceptionHolderCount;
+    pThread->IncrementHardwareExceptionHolderCount();
 }
 
-CatchHardwareExceptionHolder::~CatchHardwareExceptionHolder()
+extern "C"
+void
+PALAPI
+PAL_CatchHardwareExceptionHolderExit()
 {
     CPalThread *pThread = InternalGetCurrentThread();
-    --pThread->m_hardwareExceptionHolderCount;
+    pThread->DecrementHardwareExceptionHolderCount();
 }
 
 bool CatchHardwareExceptionHolder::IsEnabled()
@@ -395,30 +401,12 @@ __declspec(thread)
 #endif // !__llvm__
 static NativeExceptionHolderBase *t_nativeExceptionHolderHead = nullptr;
 
-NativeExceptionHolderBase::NativeExceptionHolderBase()
-{
-    m_head = nullptr;
-    m_next = nullptr;
-}
-
-NativeExceptionHolderBase::~NativeExceptionHolderBase()
-{
-    // Only destroy if Push was called
-    if (m_head != nullptr)
-    {
-        *m_head = m_next;
-        m_head = nullptr;
-        m_next = nullptr;
-    }
-}
-
-void 
-NativeExceptionHolderBase::Push()
+extern "C"
+NativeExceptionHolderBase **
+PALAPI
+PAL_GetNativeExceptionHolderHead()
 {
-    NativeExceptionHolderBase **head = &t_nativeExceptionHolderHead;
-    m_head = head;
-    m_next = *head;
-    *head = this;
+    return &t_nativeExceptionHolderHead;
 }
 
 NativeExceptionHolderBase *
index 2a03bcf..a1ad599 100644 (file)
@@ -207,7 +207,7 @@ namespace CorUnix
     {
         friend
             PAL_ERROR
-            CorUnix::InternalCreateThread(
+            InternalCreateThread(
                 CPalThread *,
                 LPSECURITY_ATTRIBUTES,
                 DWORD,
@@ -250,8 +250,6 @@ namespace CorUnix
                 HANDLE *phThread
                 );
 
-        friend CatchHardwareExceptionHolder;
-        
     private:
 
         CPalThread *m_pNext;
@@ -552,6 +550,18 @@ namespace CorUnix
             return m_hardwareExceptionHolderCount > 0;
         }
 
+        inline void
+        IncrementHardwareExceptionHolderCount()
+        {
+            ++m_hardwareExceptionHolderCount;
+        }
+
+        inline void
+        DecrementHardwareExceptionHolderCount()
+        {
+            --m_hardwareExceptionHolderCount;
+        }
+
         LPTHREAD_START_ROUTINE
         GetStartAddress(
             void
index 14cd3bb..4ec5c8c 100644 (file)
@@ -11,7 +11,7 @@
 // ===========================================================================
 
 #define INITGUID
-#include "guiddef.h"
+#include <guiddef.h>
 
 // These are GUIDs and IIDs that would normally be provided by the system via uuid.lib,
 // and that the PALRT exposes through headers.
diff --git a/src/coreclr/src/palrt/guiddef.h b/src/coreclr/src/palrt/guiddef.h
deleted file mode 100644 (file)
index a082619..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-// 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.
-//
-
-//
-// ===========================================================================
-// File: guiddef.h
-// 
-// ===========================================================================
-// simplified guiddef.h for PAL
-
-#include "common.h"
-
-#ifdef DEFINE_GUID
-#undef DEFINE_GUID
-#endif
-
-#ifdef INITGUID
-#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
-        EXTERN_C const GUID DECLSPEC_SELECTANY name \
-                = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }
-#else
-#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
-    EXTERN_C const GUID FAR name
-#endif // INITGUID