From c1052b40b9d94e49d5221f57b65a2feed6a64f71 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid Date: Thu, 21 May 2020 11:41:31 +0300 Subject: [PATCH] Fix missing symbol issues in SunOS build (#36455) * Fix missing symbol issues in SunOS build * Fix SIGSEGV due to invalid free() --- src/coreclr/src/dlls/dbgshim/CMakeLists.txt | 15 +++++++-------- src/coreclr/src/dlls/mscordac/CMakeLists.txt | 15 +++++++-------- src/coreclr/src/dlls/mscordbi/CMakeLists.txt | 15 +++++++-------- .../src/dlls/mscoree/coreclr/CMakeLists.txt | 19 +++++++++++-------- .../hosts/unixcoreruncommon/coreruncommon.cpp | 19 +++++-------------- src/coreclr/src/jit/CMakeLists.txt | 11 ++++++----- src/installer/corehost/cli/common.cmake | 2 +- .../CMakeLists.txt | 2 ++ .../Native/Unix/System.Native/CMakeLists.txt | 6 +++--- 9 files changed, 49 insertions(+), 55 deletions(-) diff --git a/src/coreclr/src/dlls/dbgshim/CMakeLists.txt b/src/coreclr/src/dlls/dbgshim/CMakeLists.txt index 8f3ef4a3330c1..ef2d0e360782b 100644 --- a/src/coreclr/src/dlls/dbgshim/CMakeLists.txt +++ b/src/coreclr/src/dlls/dbgshim/CMakeLists.txt @@ -26,25 +26,24 @@ else(CLR_CMAKE_TARGET_WIN32) generate_exports_file(${DEF_SOURCES} ${EXPORTS_FILE}) endif(CLR_CMAKE_TARGET_WIN32) -if(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) +if(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) # This option is necessary to ensure that the overloaded delete operator defined inside # of the utilcode will be used instead of the standard library delete operator. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Xlinker -Bsymbolic") # Add linker exports file option - set(EXPORTS_LINKER_OPTION -Wl,--version-script=${EXPORTS_FILE}) -endif(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) + if(CLR_CMAKE_HOST_SUNOS) + set(EXPORTS_LINKER_OPTION -Wl,-M,${EXPORTS_FILE}) + else(CLR_CMAKE_HOST_SUNOS) + set(EXPORTS_LINKER_OPTION -Wl,--version-script=${EXPORTS_FILE}) + endif(CLR_CMAKE_HOST_SUNOS) +endif(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) if(CLR_CMAKE_HOST_OSX) # Add linker exports file option set(EXPORTS_LINKER_OPTION -Wl,-exported_symbols_list,${EXPORTS_FILE}) endif(CLR_CMAKE_HOST_OSX) -if(CLR_CMAKE_HOST_SUNOS) - # Add linker exports file option - set(EXPORTS_LINKER_OPTION -Wl,-M,${EXPORTS_FILE}) -endif(CLR_CMAKE_HOST_SUNOS) - add_library_clr(dbgshim SHARED ${DBGSHIM_SOURCES}) if(CLR_CMAKE_HOST_UNIX) diff --git a/src/coreclr/src/dlls/mscordac/CMakeLists.txt b/src/coreclr/src/dlls/mscordac/CMakeLists.txt index d005acc8c5a74..ddf66b4a0d45b 100644 --- a/src/coreclr/src/dlls/mscordac/CMakeLists.txt +++ b/src/coreclr/src/dlls/mscordac/CMakeLists.txt @@ -73,7 +73,7 @@ else(CLR_CMAKE_HOST_WIN32) endif(CLR_CMAKE_HOST_LINUX) endif(CLR_CMAKE_HOST_WIN32) -if(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) +if(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) # This option is necessary to ensure that the overloaded delete operator defined inside # of the utilcode will be used instead of the standard library delete operator. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Xlinker -Bsymbolic") @@ -88,19 +88,18 @@ if(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) set(END_WHOLE_ARCHIVE -Wl,--no-whole-archive) # Add linker exports file option - set(EXPORTS_LINKER_OPTION -Wl,--version-script=${EXPORTS_FILE}) -endif(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) + if(CLR_CMAKE_HOST_SUNOS) + set(EXPORTS_LINKER_OPTION -Wl,-M,${EXPORTS_FILE}) + else(CLR_CMAKE_HOST_SUNOS) + set(EXPORTS_LINKER_OPTION -Wl,--version-script=${EXPORTS_FILE}) + endif(CLR_CMAKE_HOST_SUNOS) +endif(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) if(CLR_CMAKE_HOST_OSX) # Add linker exports file option set(EXPORTS_LINKER_OPTION -Wl,-exported_symbols_list,${EXPORTS_FILE}) endif(CLR_CMAKE_HOST_OSX) -if(CLR_CMAKE_HOST_SUNOS) - # Add linker exports file option - set(EXPORTS_LINKER_OPTION -Wl,-M,${EXPORTS_FILE}) -endif(CLR_CMAKE_HOST_SUNOS) - # Create object library to enable creation of proper dependency of mscordaccore.exp on mscordac.obj and # mscordaccore on both the mscordaccore.exp and mscordac.obj. _add_library(mscordacobj OBJECT mscordac.cpp) diff --git a/src/coreclr/src/dlls/mscordbi/CMakeLists.txt b/src/coreclr/src/dlls/mscordbi/CMakeLists.txt index 6a54e77733246..ffd48ee489aba 100644 --- a/src/coreclr/src/dlls/mscordbi/CMakeLists.txt +++ b/src/coreclr/src/dlls/mscordbi/CMakeLists.txt @@ -41,25 +41,24 @@ else(CLR_CMAKE_HOST_WIN32) generate_exports_file(${DEF_SOURCES} ${EXPORTS_FILE}) endif(CLR_CMAKE_HOST_WIN32) -if(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) +if(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) # This option is necessary to ensure that the overloaded new/delete operators defined inside # of the utilcode will be used instead of the standard library delete operator. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Xlinker -Bsymbolic") # Add linker exports file option - set(EXPORTS_LINKER_OPTION -Wl,--version-script=${EXPORTS_FILE}) -endif(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD) + if(CLR_CMAKE_HOST_SUNOS) + set(EXPORTS_LINKER_OPTION -Wl,-M,${EXPORTS_FILE}) + else(CLR_CMAKE_HOST_SUNOS) + set(EXPORTS_LINKER_OPTION -Wl,--version-script=${EXPORTS_FILE}) + endif(CLR_CMAKE_HOST_SUNOS) +endif(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) if(CLR_CMAKE_HOST_OSX) # Add linker exports file option set(EXPORTS_LINKER_OPTION -Wl,-exported_symbols_list,${EXPORTS_FILE}) endif(CLR_CMAKE_HOST_OSX) -if(CLR_CMAKE_HOST_SUNOS) - # Add linker exports file option - set(EXPORTS_LINKER_OPTION -Wl,-M,${EXPORTS_FILE}) -endif(CLR_CMAKE_HOST_SUNOS) - add_library_clr(mscordbi SHARED ${MSCORDBI_SOURCES}) target_precompile_header(TARGET mscordbi HEADER stdafx.h) diff --git a/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt b/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt index 4260ea92d1916..918fbf27a6848 100644 --- a/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt +++ b/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt @@ -32,7 +32,7 @@ else(CLR_CMAKE_HOST_WIN32) set(EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/coreclr.exports) generate_exports_file(${DEF_SOURCES} ${EXPORTS_FILE}) - if(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_NETBSD) + if(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_NETBSD OR CLR_CMAKE_TARGET_SUNOS) # This option is necessary to ensure that the overloaded delete operator defined inside # of the utilcode will be used instead of the standard library delete operator. add_link_options("LINKER:-Bsymbolic") @@ -46,8 +46,12 @@ else(CLR_CMAKE_HOST_WIN32) set(START_WHOLE_ARCHIVE -Wl,--whole-archive) set(END_WHOLE_ARCHIVE -Wl,--no-whole-archive) - set(EXPORTS_LINKER_OPTION -Wl,--version-script=${EXPORTS_FILE}) - endif(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_NETBSD) + if(CLR_CMAKE_TARGET_SUNOS) + set(EXPORTS_LINKER_OPTION -Wl,-M,${EXPORTS_FILE}) + elseif(CLR_CMAKE_TARGET_SUNOS) + set(EXPORTS_LINKER_OPTION -Wl,--version-script=${EXPORTS_FILE}) + endif(CLR_CMAKE_TARGET_SUNOS) + endif(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_NETBSD OR CLR_CMAKE_TARGET_SUNOS) if(CLR_CMAKE_TARGET_OSX) # These options are used to force every object to be included even if it's unused. @@ -61,11 +65,6 @@ else(CLR_CMAKE_HOST_WIN32) set(EXPORTS_LINKER_OPTION "${EXPORTS_LINKER_OPTION} -Wl,--no-warn-shared-textrel") endif(CLR_CMAKE_TARGET_ANDROID AND CLR_CMAKE_HOST_ARCH_ARM) - if(CLR_CMAKE_TARGET_SUNOS) - # Add linker exports file option - set(EXPORTS_LINKER_OPTION -Wl,-M,${EXPORTS_FILE}) - endif(CLR_CMAKE_TARGET_SUNOS) - endif (CLR_CMAKE_HOST_WIN32) add_definitions(-DFX_VER_INTERNALNAME_STR=CoreCLR.dll) @@ -151,6 +150,10 @@ if(CLR_CMAKE_TARGET_LINUX) tracepointprovider ${END_WHOLE_ARCHIVE} ) +elseif(CLR_CMAKE_TARGET_SUNOS) + list(APPEND CORECLR_LIBRARIES + socket + ) endif(CLR_CMAKE_TARGET_LINUX) if(FEATURE_PERFTRACING) diff --git a/src/coreclr/src/hosts/unixcoreruncommon/coreruncommon.cpp b/src/coreclr/src/hosts/unixcoreruncommon/coreruncommon.cpp index b927f3802e683..1b6e1fa820410 100644 --- a/src/coreclr/src/hosts/unixcoreruncommon/coreruncommon.cpp +++ b/src/coreclr/src/hosts/unixcoreruncommon/coreruncommon.cpp @@ -131,18 +131,11 @@ bool GetEntrypointExecutableAbsolutePath(std::string& entrypointExecutable) } else { - char *joined; - if (asprintf(&joined, "%s/%s", cwd, path) < 0) - { - result = false; - } - else - { - entrypointExecutable.assign(joined); - result = true; - free(joined); - } - + entrypointExecutable + .assign(cwd) + .append("/") + .append(path); + result = true; free(cwd); } } @@ -151,8 +144,6 @@ bool GetEntrypointExecutableAbsolutePath(std::string& entrypointExecutable) entrypointExecutable.assign(path); result = true; } - - free((void*)path); #else #if HAVE_GETAUXVAL && defined(AT_EXECFN) diff --git a/src/coreclr/src/jit/CMakeLists.txt b/src/coreclr/src/jit/CMakeLists.txt index 0fd69af598209..a3f0b1aeb2e0d 100644 --- a/src/coreclr/src/jit/CMakeLists.txt +++ b/src/coreclr/src/jit/CMakeLists.txt @@ -318,16 +318,17 @@ else() set(JIT_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/clrjit.exports) generate_exports_file(${CLRJIT_EXPORTS} ${JIT_EXPORTS_FILE}) - if(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_NETBSD) + if(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_FREEBSD OR CLR_CMAKE_TARGET_NETBSD OR CLR_CMAKE_TARGET_SUNOS) # This is required to force using our own PAL, not one that we are loaded with. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Xlinker -Bsymbolic") - set(JIT_EXPORTS_LINKER_OPTION -Wl,--version-script=${JIT_EXPORTS_FILE}) + if(CLR_CMAKE_TARGET_SUNOS) + set(JIT_EXPORTS_LINKER_OPTION -Wl,-M,${JIT_EXPORTS_FILE}) + else(CLR_CMAKE_TARGET_SUNOS) + set(JIT_EXPORTS_LINKER_OPTION -Wl,--version-script=${JIT_EXPORTS_FILE}) + endif(CLR_CMAKE_TARGET_SUNOS) elseif(CLR_CMAKE_TARGET_OSX) set(JIT_EXPORTS_LINKER_OPTION -Wl,-exported_symbols_list,${JIT_EXPORTS_FILE}) - elseif(CLR_CMAKE_TARGET_SUNOS) - # Add linker exports file option - set(JIT_EXPORTS_LINKER_OPTION -Wl,-M,${JIT_EXPORTS_FILE}) endif() set(SHARED_LIB_SOURCES ${SOURCES}) diff --git a/src/installer/corehost/cli/common.cmake b/src/installer/corehost/cli/common.cmake index 5f9289659684c..1ad7ee619abd8 100644 --- a/src/installer/corehost/cli/common.cmake +++ b/src/installer/corehost/cli/common.cmake @@ -38,7 +38,7 @@ endif() # This is required to map a symbol reference to a matching definition local to the module (.so) # containing the reference instead of using definitions from other modules. -if(CLR_CMAKE_TARGET_LINUX) +if(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_SUNOS) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Xlinker -Bsymbolic") endif() diff --git a/src/libraries/Native/Unix/System.IO.Compression.Native/CMakeLists.txt b/src/libraries/Native/Unix/System.IO.Compression.Native/CMakeLists.txt index d1bfa9f4b8490..602d6a3989715 100644 --- a/src/libraries/Native/Unix/System.IO.Compression.Native/CMakeLists.txt +++ b/src/libraries/Native/Unix/System.IO.Compression.Native/CMakeLists.txt @@ -5,6 +5,8 @@ if (CLR_CMAKE_TARGET_BROWSER) elseif (CLR_CMAKE_TARGET_ANDROID) # need special case here since we want to link against libz.so but find_package() would resolve libz.a set(ZLIB_LIBRARIES z) +elseif (CLR_CMAKE_TARGET_SUNOS) + set(ZLIB_LIBRARIES z m) else () find_package(ZLIB REQUIRED) endif () diff --git a/src/libraries/Native/Unix/System.Native/CMakeLists.txt b/src/libraries/Native/Unix/System.Native/CMakeLists.txt index 884e1b065814e..e72161d0ee77e 100644 --- a/src/libraries/Native/Unix/System.Native/CMakeLists.txt +++ b/src/libraries/Native/Unix/System.Native/CMakeLists.txt @@ -52,14 +52,14 @@ if (GEN_SHARED_LIB) ) if (CLR_CMAKE_TARGET_LINUX AND NOT CLR_CMAKE_TARGET_ANDROID) target_link_libraries(System.Native rt) - endif () - - if (CLR_CMAKE_TARGET_FREEBSD) + elseif (CLR_CMAKE_TARGET_FREEBSD) target_link_libraries(System.Native pthread) if (HAVE_INOTIFY) find_library(INOTIFY_LIBRARY inotify HINTS /usr/local/lib) target_link_libraries(System.Native ${INOTIFY_LIBRARY}) endif () + elseif (CLR_CMAKE_TARGET_SUNOS) + target_link_libraries(System.Native socket) endif () install_with_stripped_symbols (System.Native PROGRAMS .) endif ()