From 9f0c54098abe5610eae92eed3bc86beefff18261 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid Date: Sat, 4 Apr 2020 19:27:01 +0300 Subject: [PATCH] Define dirent d_type for Solaris based OS (#34263) --- eng/native/configurecompiler.cmake | 10 +++++++--- src/installer/corehost/cli/common.cmake | 4 +--- .../corehost/cli/hostmisc/CMakeLists.txt | 3 +++ src/installer/corehost/cli/hostmisc/config.h.in | 6 ++++++ .../corehost/cli/hostmisc/configure.cmake | 5 +++++ src/installer/corehost/cli/hostmisc/pal.h | 1 + src/installer/corehost/cli/hostmisc/pal.unix.cpp | 16 +++++++++++++++- 7 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 src/installer/corehost/cli/hostmisc/config.h.in create mode 100644 src/installer/corehost/cli/hostmisc/configure.cmake diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index a4c66676e32..d9832b6c664 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -179,11 +179,15 @@ endif(CLR_CMAKE_HOST_UNIX) if(CLR_CMAKE_HOST_LINUX) add_compile_options($<$:-Wa,--noexecstack>) add_link_options(-Wl,--build-id=sha1 -Wl,-z,relro,-z,now) -endif(CLR_CMAKE_HOST_LINUX) -if(CLR_CMAKE_HOST_FREEBSD) +elseif(CLR_CMAKE_HOST_FREEBSD) add_compile_options($<$:-Wa,--noexecstack>) add_link_options(LINKER:--build-id=sha1) -endif(CLR_CMAKE_HOST_FREEBSD) +elseif(CLR_CMAKE_HOST_SUNOS) + set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /opt/local/include) + set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /opt/local/lib) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector") +endif() #------------------------------------ # Definitions (for platform) diff --git a/src/installer/corehost/cli/common.cmake b/src/installer/corehost/cli/common.cmake index 4cd09d3747b..e8693dddb88 100644 --- a/src/installer/corehost/cli/common.cmake +++ b/src/installer/corehost/cli/common.cmake @@ -40,9 +40,7 @@ function(set_common_libs TargetType) target_link_libraries (${DOTNET_PROJECT_NAME} "pthread") endif() - if(CLR_CMAKE_TARGET_LINUX) - target_link_libraries (${DOTNET_PROJECT_NAME} "dl") - endif() + target_link_libraries (${DOTNET_PROJECT_NAME} ${CMAKE_DL_LIBS}) endif() if (NOT ${TargetType} STREQUAL "lib-static") diff --git a/src/installer/corehost/cli/hostmisc/CMakeLists.txt b/src/installer/corehost/cli/hostmisc/CMakeLists.txt index 8e0c24c9e33..8db9d857a8a 100644 --- a/src/installer/corehost/cli/hostmisc/CMakeLists.txt +++ b/src/installer/corehost/cli/hostmisc/CMakeLists.txt @@ -6,6 +6,9 @@ project(hostmisc) set(DOTNET_PROJECT_NAME "hostmisc") +include(configure.cmake) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + # CMake does not recommend using globbing since it messes with the freshness checks set(SOURCES trace.cpp diff --git a/src/installer/corehost/cli/hostmisc/config.h.in b/src/installer/corehost/cli/hostmisc/config.h.in new file mode 100644 index 00000000000..3b1dc149f8d --- /dev/null +++ b/src/installer/corehost/cli/hostmisc/config.h.in @@ -0,0 +1,6 @@ +#ifndef _PAL_CONFIG_H_INCLUDED +#define _PAL_CONFIG_H_INCLUDED 1 + +#cmakedefine01 HAVE_DIRENT_D_TYPE + +#endif diff --git a/src/installer/corehost/cli/hostmisc/configure.cmake b/src/installer/corehost/cli/hostmisc/configure.cmake new file mode 100644 index 00000000000..68193ace156 --- /dev/null +++ b/src/installer/corehost/cli/hostmisc/configure.cmake @@ -0,0 +1,5 @@ +include(CheckStructHasMember) + +check_struct_has_member("struct dirent" d_type dirent.h HAVE_DIRENT_D_TYPE) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) diff --git a/src/installer/corehost/cli/hostmisc/pal.h b/src/installer/corehost/cli/hostmisc/pal.h index d713fc5b664..432756a3f37 100644 --- a/src/installer/corehost/cli/hostmisc/pal.h +++ b/src/installer/corehost/cli/hostmisc/pal.h @@ -46,6 +46,7 @@ #define xout std::cout #define DIR_SEPARATOR '/' #define PATH_SEPARATOR ':' +#undef _X #define _X(s) s #define S_OK 0x00000000 diff --git a/src/installer/corehost/cli/hostmisc/pal.unix.cpp b/src/installer/corehost/cli/hostmisc/pal.unix.cpp index ba4fa60141c..4b637e4f728 100644 --- a/src/installer/corehost/cli/hostmisc/pal.unix.cpp +++ b/src/installer/corehost/cli/hostmisc/pal.unix.cpp @@ -14,6 +14,7 @@ #include #include #include +#include "config.h" #if defined(TARGET_OSX) #include @@ -27,6 +28,13 @@ #define symlinkEntrypointExecutable "/proc/curproc/exe" #endif +#if !HAVE_DIRENT_D_TYPE +#define DT_UNKNOWN 0 +#define DT_DIR 4 +#define DT_REG 8 +#define DT_LNK 10 +#endif + pal::string_t pal::to_string(int value) { return std::to_string(value); } pal::string_t pal::to_lower(const pal::string_t& in) @@ -821,8 +829,14 @@ static void readdir(const pal::string_t& path, const pal::string_t& pattern, boo continue; } +#if HAVE_DIRENT_D_TYPE + int dirEntryType = entry->d_type; +#else + int dirEntryType = DT_UNKNOWN; +#endif + // We are interested in files only - switch (entry->d_type) + switch (dirEntryType) { case DT_DIR: break; -- 2.34.1