Skip to content

Commit

Permalink
Fix missing symbol issues in SunOS build (#36455)
Browse files Browse the repository at this point in the history
* Fix missing symbol issues in SunOS build

* Fix SIGSEGV due to invalid free()
  • Loading branch information
am11 authored May 21, 2020
1 parent 00c0328 commit c1052b4
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 55 deletions.
15 changes: 7 additions & 8 deletions src/coreclr/src/dlls/dbgshim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 7 additions & 8 deletions src/coreclr/src/dlls/mscordac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
15 changes: 7 additions & 8 deletions src/coreclr/src/dlls/mscordbi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
19 changes: 11 additions & 8 deletions src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 5 additions & 14 deletions src/coreclr/src/hosts/unixcoreruncommon/coreruncommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -151,8 +144,6 @@ bool GetEntrypointExecutableAbsolutePath(std::string& entrypointExecutable)
entrypointExecutable.assign(path);
result = true;
}

free((void*)path);
#else

#if HAVE_GETAUXVAL && defined(AT_EXECFN)
Expand Down
11 changes: 6 additions & 5 deletions src/coreclr/src/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
2 changes: 1 addition & 1 deletion src/installer/corehost/cli/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
6 changes: 3 additions & 3 deletions src/libraries/Native/Unix/System.Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down

0 comments on commit c1052b4

Please sign in to comment.