diff --git a/eng/native/configureplatform.cmake b/eng/native/configureplatform.cmake index 174cce725d557..ab48a342fe446 100644 --- a/eng/native/configureplatform.cmake +++ b/eng/native/configureplatform.cmake @@ -7,9 +7,9 @@ include(${CMAKE_CURRENT_LIST_DIR}/functions.cmake) # - for windows we use the passed in parameter to CMAKE to determine build arch #---------------------------------------- set(CLR_CMAKE_HOST_OS ${CMAKE_SYSTEM_NAME}) -if(CLR_CMAKE_HOST_OS STREQUAL Linux) +if(CLR_CMAKE_HOST_OS STREQUAL Linux OR CLR_CMAKE_HOST_OS STREQUAL Android) set(CLR_CMAKE_HOST_UNIX 1) - if(CLR_CROSS_COMPONENTS_BUILD) + if(CLR_CROSS_COMPONENTS_BUILD AND NOT CLR_CMAKE_HOST_OS STREQUAL Android) # CMAKE_HOST_SYSTEM_PROCESSOR returns the value of `uname -p` on host. if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL amd64) if(CLR_CMAKE_TARGET_ARCH STREQUAL "arm" OR CLR_CMAKE_TARGET_ARCH STREQUAL "armel") @@ -36,7 +36,7 @@ if(CLR_CMAKE_HOST_OS STREQUAL Linux) elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l) set(CLR_CMAKE_HOST_UNIX_ARM 1) set(CLR_CMAKE_HOST_UNIX_ARMV7L 1) - elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm OR CMAKE_SYSTEM_PROCESSOR STREQUAL armv7-a) set(CLR_CMAKE_HOST_UNIX_ARM 1) elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64) set(CLR_CMAKE_HOST_UNIX_ARM64 1) @@ -54,10 +54,12 @@ if(CLR_CMAKE_HOST_OS STREQUAL Linux) set(LINUX_ID_FILE "${CMAKE_SYSROOT}${LINUX_ID_FILE}") endif() - execute_process( - COMMAND bash -c "source ${LINUX_ID_FILE} && echo \$ID" - OUTPUT_VARIABLE CLR_CMAKE_LINUX_ID - OUTPUT_STRIP_TRAILING_WHITESPACE) + if(EXISTS ${LINUX_ID_FILE}) + execute_process( + COMMAND bash -c "source ${LINUX_ID_FILE} && echo \$ID" + OUTPUT_VARIABLE CLR_CMAKE_LINUX_ID + OUTPUT_STRIP_TRAILING_WHITESPACE) + endif() if(DEFINED CLR_CMAKE_LINUX_ID) if(CLR_CMAKE_LINUX_ID STREQUAL tizen) @@ -66,12 +68,14 @@ if(CLR_CMAKE_HOST_OS STREQUAL Linux) elseif(CLR_CMAKE_LINUX_ID STREQUAL alpine) set(CLR_CMAKE_HOST_ALPINE_LINUX 1) set(CLR_CMAKE_HOST_OS ${CLR_CMAKE_LINUX_ID}) - elseif(CLR_CMAKE_LINUX_ID STREQUAL android) - set(CLR_CMAKE_HOST_ANDROID 1) - set(CLR_CMAKE_HOST_OS ${CLR_CMAKE_LINUX_ID}) endif() endif(DEFINED CLR_CMAKE_LINUX_ID) -endif(CLR_CMAKE_HOST_OS STREQUAL Linux) + + if(CLR_CMAKE_HOST_OS STREQUAL Android) + set(CLR_CMAKE_HOST_ANDROID 1) + set(CLR_CMAKE_HOST_OS ${CLR_CMAKE_HOST_OS}) + endif() +endif(CLR_CMAKE_HOST_OS STREQUAL Linux OR CLR_CMAKE_HOST_OS STREQUAL Android) if(CLR_CMAKE_HOST_OS STREQUAL Darwin) set(CLR_CMAKE_HOST_UNIX 1) @@ -233,11 +237,11 @@ if(CLR_CMAKE_TARGET_OS STREQUAL alpine) set(CLR_CMAKE_TARGET_ALPINE_LINUX 1) endif(CLR_CMAKE_TARGET_OS STREQUAL alpine) -if(CLR_CMAKE_TARGET_OS STREQUAL android) +if(CLR_CMAKE_TARGET_OS STREQUAL Android) set(CLR_CMAKE_TARGET_UNIX 1) set(CLR_CMAKE_TARGET_LINUX 1) set(CLR_CMAKE_TARGET_ANDROID 1) -endif(CLR_CMAKE_TARGET_OS STREQUAL android) +endif(CLR_CMAKE_TARGET_OS STREQUAL Android) if(CLR_CMAKE_TARGET_OS STREQUAL Darwin) set(CLR_CMAKE_TARGET_UNIX 1) diff --git a/eng/native/configuretools.cmake b/eng/native/configuretools.cmake index b59504a10e761..b91237da89bfb 100644 --- a/eng/native/configuretools.cmake +++ b/eng/native/configuretools.cmake @@ -1,6 +1,4 @@ -if(NOT CLR_CMAKE_CONFIGURE_PLATFORM_INCLUDED) - message(FATAL_ERROR "configuretools.cmake needs to be included after configureplatform.cmake") -endif() +include(${CMAKE_CURRENT_LIST_DIR}/configureplatform.cmake) # Get the version of the compiler that is in the file name for tool location. set (CLR_CMAKE_COMPILER_FILE_NAME_VERSION "") @@ -52,7 +50,9 @@ if(NOT WIN32) if(NOT CLR_CMAKE_TARGET_DARWIN AND NOT CLR_CMAKE_TARGET_IOS) locate_toolchain_exec(objdump CMAKE_OBJDUMP) - if(CMAKE_CROSSCOMPILING AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD AND (CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l OR + if(CMAKE_SYSTEM_NAME STREQUAL Android) + set(TOOSET_PREFIX ${ANDROID_TOOLCHAIN_PREFIX}) + elseif(CMAKE_CROSSCOMPILING AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD AND (CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l OR CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm)) set(TOOLSET_PREFIX "${TOOLCHAIN}-") else() diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index aa2c9411ab68d..cc806fed26343 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -1,10 +1,10 @@ function(clr_unknown_arch) if (WIN32) - message(FATAL_ERROR "Only AMD64, ARM64, ARM and I386 are supported") + message(FATAL_ERROR "Only AMD64, ARM64, ARM and I386 are supported. Found: ${CMAKE_SYSTEM_PROCESSOR}") elseif(CLR_CROSS_COMPONENTS_BUILD) - message(FATAL_ERROR "Only AMD64, I386 host are supported for linux cross-architecture component") + message(FATAL_ERROR "Only AMD64, I386 host are supported for linux cross-architecture component. Found: ${CMAKE_SYSTEM_PROCESSOR}") else() - message(FATAL_ERROR "Only AMD64, ARM64 and ARM are supported") + message(FATAL_ERROR "Only AMD64, ARM64 and ARM are supported. Found: ${CMAKE_SYSTEM_PROCESSOR}") endif() endfunction() diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 7e2b66caeec02..709b5754775d1 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_policy(SET CMP0042 NEW) # Set the project name project(CoreCLR) -include(${CLR_ENG_NATIVE_DIR}/configureplatform.cmake) +include(${CLR_ENG_NATIVE_DIR}/configuretools.cmake) if (CLR_CMAKE_HOST_WIN32) message(STATUS "VS_PLATFORM_TOOLSET is ${CMAKE_VS_PLATFORM_TOOLSET}") @@ -110,11 +110,14 @@ else (CLR_CMAKE_HOST_WIN32) endif() endif(CLR_CMAKE_HOST_WIN32) +if(CLR_CMAKE_TARGET_ANDROID) + add_definitions(-DTARGET_ANDROID) +endif() + #---------------------------------------------------- # Configure compiler settings for environment #---------------------------------------------------- include(configurecompiler.cmake) -include(${CLR_ENG_NATIVE_DIR}/configuretools.cmake) #---------------------------------------------------- # Cross target Component build specific configuration @@ -141,6 +144,18 @@ endif(NOT CLR_CROSS_COMPONENTS_BUILD) # - do not depend on clr's compile definitions #----------------------------------------- if(CLR_CMAKE_HOST_UNIX) + if(CLR_CMAKE_TARGET_ANDROID) + find_library(LZMA NAMES lzma) + if(LZMA STREQUAL LZMA-NOTFOUND) + message(FATAL_ERROR "Cannot find liblzma.") + endif(LZMA STREQUAL LZMA-NOTFOUND) + + find_library(ANDROID_GLOB NAMES android-glob) + if(ANDROID_GLOB STREQUAL ANDROID_GLOB-NOTFOUND) + message(FATAL_ERROR "Cannot find android-glob.") + endif() + endif() + add_subdirectory(src/pal) add_subdirectory(src/hosts) endif(CLR_CMAKE_HOST_UNIX) diff --git a/src/coreclr/clrfeatures.cmake b/src/coreclr/clrfeatures.cmake index 078b4e73ac804..9025602a3c68c 100644 --- a/src/coreclr/clrfeatures.cmake +++ b/src/coreclr/clrfeatures.cmake @@ -11,7 +11,7 @@ if(NOT DEFINED FEATURE_PERFTRACING AND FEATURE_EVENT_TRACE) endif(NOT DEFINED FEATURE_PERFTRACING AND FEATURE_EVENT_TRACE) if(NOT DEFINED FEATURE_DBGIPC) - if(CLR_CMAKE_TARGET_UNIX AND (NOT CLR_CMAKE_TARGET_ANDROID)) + if(CLR_CMAKE_TARGET_UNIX) set(FEATURE_DBGIPC 1) endif() endif(NOT DEFINED FEATURE_DBGIPC) diff --git a/src/coreclr/src/CMakeLists.txt b/src/coreclr/src/CMakeLists.txt index b6584b2de7830..262e6b7d021c3 100644 --- a/src/coreclr/src/CMakeLists.txt +++ b/src/coreclr/src/CMakeLists.txt @@ -16,9 +16,9 @@ endif(CLR_CMAKE_TARGET_WIN32 AND FEATURE_EVENT_TRACE) add_subdirectory(debug/dbgutil) if(CLR_CMAKE_HOST_UNIX) - if(CLR_CMAKE_HOST_LINUX AND NOT CLR_CMAKE_HOST_UNIX_X86) + if(CLR_CMAKE_HOST_LINUX AND NOT CLR_CMAKE_HOST_UNIX_X86 AND NOT CLR_CMAKE_HOST_ANDROID) add_subdirectory(debug/createdump) - endif(CLR_CMAKE_HOST_LINUX AND NOT CLR_CMAKE_HOST_UNIX_X86) + endif(CLR_CMAKE_HOST_LINUX AND NOT CLR_CMAKE_HOST_UNIX_X86 AND NOT CLR_CMAKE_HOST_ANDROID) # Include the dummy c++ include files include_directories("pal/inc/rt/cpp") diff --git a/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt b/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt index e86e91f6a69e8..0517bb50df321 100644 --- a/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt +++ b/src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt @@ -57,6 +57,10 @@ else(CLR_CMAKE_HOST_WIN32) set(EXPORTS_LINKER_OPTION -Wl,-exported_symbols_list,${EXPORTS_FILE}) endif(CLR_CMAKE_TARGET_DARWIN) + if(CLR_CMAKE_TARGET_ANDROID AND CLR_CMAKE_HOST_ARCH_ARM) + set(EXPORTS_LINKER_OPTION "${EXPORTS_LINKER_OPTION} -Wl,--no-warn-shared-textrel") + endif() + endif (CLR_CMAKE_HOST_WIN32) add_definitions(-DFX_VER_INTERNALNAME_STR=CoreCLR.dll) diff --git a/src/coreclr/src/gc/unix/gcenv.unix.cpp b/src/coreclr/src/gc/unix/gcenv.unix.cpp index f32308c90106c..855f2da02a982 100644 --- a/src/coreclr/src/gc/unix/gcenv.unix.cpp +++ b/src/coreclr/src/gc/unix/gcenv.unix.cpp @@ -25,6 +25,8 @@ #undef min #undef max +#include + #if HAVE_SYS_TIME_H #include #else diff --git a/src/coreclr/src/inc/eventtracebase.h b/src/coreclr/src/inc/eventtracebase.h index cde996a92185e..a02d8f5fbda69 100644 --- a/src/coreclr/src/inc/eventtracebase.h +++ b/src/coreclr/src/inc/eventtracebase.h @@ -242,7 +242,7 @@ extern UINT32 g_nClrInstanceId; #endif // defined(HOST_UNIX) && (defined(FEATURE_EVENT_TRACE) || defined(FEATURE_EVENTSOURCE_XPLAT)) -#if defined(FEATURE_PERFTRACING) +#if defined(FEATURE_PERFTRACING) || defined(FEATURE_EVENTSOURCE_XPLAT) /***************************************/ /* Tracing levels supported by CLR ETW */ @@ -397,7 +397,7 @@ class XplatEventLoggerConfiguration NewArrayHolder _argument; bool _isValid; }; -#endif // FEATURE_PERFTRACING +#endif // defined(FEATURE_PERFTRACING) || defined(FEATURE_EVENTSOURCE_XPLAT) #if defined(HOST_UNIX) && (defined(FEATURE_EVENT_TRACE) || defined(FEATURE_EVENTSOURCE_XPLAT)) diff --git a/src/coreclr/src/pal/src/CMakeLists.txt b/src/coreclr/src/pal/src/CMakeLists.txt index 249936cd39270..37aee43257783 100644 --- a/src/coreclr/src/pal/src/CMakeLists.txt +++ b/src/coreclr/src/pal/src/CMakeLists.txt @@ -290,34 +290,11 @@ if(CLR_CMAKE_TARGET_LINUX) pthread rt ) - endif() - - if(CLR_CMAKE_TARGET_ANDROID) - find_library(LZMA NAMES lzma) - - if(LZMA STREQUAL LZMA-NOTFOUND) - message(FATAL_ERROR "Cannot find liblzma.") - endif(LZMA STREQUAL LZMA-NOTFOUND) - + else(NOT CLR_CMAKE_TARGET_ANDROID) target_link_libraries(coreclrpal - gnustl_shared - android-support - android-glob + ${ANDROID_GLOB} ${LZMA}) - endif() - - if(CLR_MAKE_TARGET_ANDROID) - find_library(ANDROID_SUPPORT NAMES android-support) - find_library(ANDROID_GLOB NAMES android-glob) - - if(ANDROID_SUPPORT STREQUAL ANDROID_SUPPORT-NOTFOUND) - message(FATAL_ERROR "Cannot find android-support.") - endif() - - if(ANDROID_GLOB STREQUAL ANDROID_GLOB-NOTFOUND) - message(FATAL_ERROR "Cannot find android-glob.") - endif() - endif() + endif(NOT CLR_CMAKE_TARGET_ANDROID) target_link_libraries(coreclrpal dl diff --git a/src/coreclr/src/pal/src/safecrt/mbusafecrt_internal.h b/src/coreclr/src/pal/src/safecrt/mbusafecrt_internal.h index 83c1db99a80bf..00136ecfe2839 100644 --- a/src/coreclr/src/pal/src/safecrt/mbusafecrt_internal.h +++ b/src/coreclr/src/pal/src/safecrt/mbusafecrt_internal.h @@ -18,6 +18,8 @@ #ifndef MBUSAFECRT_INTERNAL_H #define MBUSAFECRT_INTERNAL_H +#define PAL_IMPLEMENTATION + #include "pal_mstypes.h" #ifndef DLLEXPORT diff --git a/src/coreclr/src/pal/src/thread/context.cpp b/src/coreclr/src/pal/src/thread/context.cpp index d00f688856479..a89bdb2649f0d 100644 --- a/src/coreclr/src/pal/src/thread/context.cpp +++ b/src/coreclr/src/pal/src/thread/context.cpp @@ -203,7 +203,7 @@ BOOL CONTEXT_GetRegisters(DWORD processId, LPCONTEXT lpContext) ucontext_t registers; #if HAVE_PT_REGS struct pt_regs ptrace_registers; - if (ptrace((__ptrace_request)PT_GETREGS, processId, (caddr_t) &ptrace_registers, 0) == -1) + if (ptrace((__ptrace_request)PTRACE_GETREGS, processId, (caddr_t) &ptrace_registers, 0) == -1) #elif HAVE_BSD_REGS_T struct reg ptrace_registers; if (PAL_PTRACE(PT_GETREGS, processId, &ptrace_registers, 0) == -1) @@ -352,7 +352,7 @@ CONTEXT_SetThreadContext( (CONTEXT_CONTROL | CONTEXT_INTEGER) & CONTEXT_AREA_MASK) { #if HAVE_PT_REGS - if (ptrace((__ptrace_request)PT_GETREGS, dwProcessId, (caddr_t)&ptrace_registers, 0) == -1) + if (ptrace((__ptrace_request)PTRACE_GETREGS, dwProcessId, (caddr_t)&ptrace_registers, 0) == -1) #elif HAVE_BSD_REGS_T if (PAL_PTRACE(PT_GETREGS, dwProcessId, &ptrace_registers, 0) == -1) #endif @@ -383,7 +383,7 @@ CONTEXT_SetThreadContext( #undef ASSIGN_REG #if HAVE_PT_REGS - if (ptrace((__ptrace_request)PT_SETREGS, dwProcessId, (caddr_t)&ptrace_registers, 0) == -1) + if (ptrace((__ptrace_request)PTRACE_SETREGS, dwProcessId, (caddr_t)&ptrace_registers, 0) == -1) #elif HAVE_BSD_REGS_T if (PAL_PTRACE(PT_SETREGS, dwProcessId, &ptrace_registers, 0) == -1) #endif diff --git a/src/coreclr/src/scripts/genEventing.py b/src/coreclr/src/scripts/genEventing.py index 50fde02fbd02c..69c96adf5a063 100644 --- a/src/coreclr/src/scripts/genEventing.py +++ b/src/coreclr/src/scripts/genEventing.py @@ -639,7 +639,8 @@ def generatePlatformIndependentFiles(sClrEtwAllMan, incDir, etmDummyFile, extern { int const Level; ULONGLONG const Keyword; -} EVENT_DESCRIPTOR;""") +} EVENT_DESCRIPTOR; +""") if not is_windows: Clrproviders.write(eventpipe_trace_context_typedef) # define EVENTPIPE_TRACE_CONTEXT diff --git a/src/coreclr/src/vm/ceemain.cpp b/src/coreclr/src/vm/ceemain.cpp index 1a95656aa2b47..2ef8137a89ea7 100644 --- a/src/coreclr/src/vm/ceemain.cpp +++ b/src/coreclr/src/vm/ceemain.cpp @@ -924,10 +924,12 @@ void EEStartupHelper() hr = g_pGCHeap->Initialize(); IfFailGo(hr); +#ifdef FEATURE_EVENT_TRACE // Finish setting up rest of EventPipe - specifically enable SampleProfiler if it was requested at startup. // SampleProfiler needs to cooperate with the GC which hasn't fully finished setting up in the first part of the // EventPipe initialization, so this is done after the GC has been fully initialized. EventPipe::FinishInitialize(); +#endif // This isn't done as part of InitializeGarbageCollector() above because thread // creation requires AppDomains to have been set up. diff --git a/src/coreclr/src/vm/gctoclreventsink.cpp b/src/coreclr/src/vm/gctoclreventsink.cpp index 1389d417737c2..a9bc4bd7654d1 100644 --- a/src/coreclr/src/vm/gctoclreventsink.cpp +++ b/src/coreclr/src/vm/gctoclreventsink.cpp @@ -25,6 +25,7 @@ void GCToCLREventSink::FireDynamicEvent(const char* eventName, void* payload, ui void GCToCLREventSink::FireGCStart_V2(uint32_t count, uint32_t depth, uint32_t reason, uint32_t type) { +#ifdef FEATURE_EVENT_TRACE LIMITED_METHOD_CONTRACT; ETW::GCLog::ETW_GC_INFO gcStartInfo; @@ -33,6 +34,7 @@ void GCToCLREventSink::FireGCStart_V2(uint32_t count, uint32_t depth, uint32_t r gcStartInfo.GCStart.Reason = static_cast(reason); gcStartInfo.GCStart.Type = static_cast(type); ETW::GCLog::FireGcStart(&gcStartInfo); +#endif } void GCToCLREventSink::FireGCGenerationRange(uint8_t generation, void* rangeStart, uint64_t rangeUsedLength, uint64_t rangeReservedLength) diff --git a/src/coreclr/tests/CMakeLists.txt b/src/coreclr/tests/CMakeLists.txt index 47ee1e3a9a4de..1ea31cdd8a035 100644 --- a/src/coreclr/tests/CMakeLists.txt +++ b/src/coreclr/tests/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.14.2) cmake_policy(SET CMP0042 NEW) project(Tests) -include(${CLR_ENG_NATIVE_DIR}/configureplatform.cmake) +include(${CLR_ENG_NATIVE_DIR}/configuretools.cmake) set(INC_PLATFORM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/Common/Platform) if (CLR_CMAKE_TARGET_WIN32) @@ -12,7 +12,6 @@ endif() # Include global configure settings include(${CMAKE_CURRENT_SOURCE_DIR}/../configurecompiler.cmake) -include(${CLR_ENG_NATIVE_DIR}/configuretools.cmake) # Compile options if (CLR_CMAKE_HOST_WIN32) diff --git a/src/installer/corehost/CMakeLists.txt b/src/installer/corehost/CMakeLists.txt index 49bcbcfe1815e..7d1854cee4266 100644 --- a/src/installer/corehost/CMakeLists.txt +++ b/src/installer/corehost/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.14.2) project(corehost) -include(${CLR_ENG_NATIVE_DIR}/configureplatform.cmake) include(${CLR_ENG_NATIVE_DIR}/configuretools.cmake) include(../settings.cmake) include(../functions.cmake) diff --git a/src/installer/corehost/cli/common.cmake b/src/installer/corehost/cli/common.cmake index f64377711a65e..4cd09d3747b52 100644 --- a/src/installer/corehost/cli/common.cmake +++ b/src/installer/corehost/cli/common.cmake @@ -36,7 +36,7 @@ function(set_common_libs TargetType) # Libraries used for exe projects if (${TargetType} STREQUAL "exe") - if(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_FREEBSD) + if((CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_FREEBSD) AND NOT CLR_CMAKE_TARGET_ANDROID) target_link_libraries (${DOTNET_PROJECT_NAME} "pthread") endif() diff --git a/src/installer/settings.cmake b/src/installer/settings.cmake index 6c56313847a68..9bb9d81106e40 100644 --- a/src/installer/settings.cmake +++ b/src/installer/settings.cmake @@ -149,6 +149,10 @@ elseif(CLR_CMAKE_TARGET_FREEBSD) add_compile_options(-fstack-protector) endif() +if(CLR_CMAKE_TARGET_ANDROID) + add_compile_options(-Wno-user-defined-warnings) +endif() + add_definitions(-D_NO_ASYNCRTIMP) add_definitions(-D_NO_PPLXIMP) if(CLR_CMAKE_TARGET_LINUX) diff --git a/src/libraries/Native/Unix/CMakeLists.txt b/src/libraries/Native/Unix/CMakeLists.txt index ef99465e3c77e..d964b445e23cc 100644 --- a/src/libraries/Native/Unix/CMakeLists.txt +++ b/src/libraries/Native/Unix/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_policy(SET CMP0042 NEW) project(CoreFX C) -include(${CLR_ENG_NATIVE_DIR}/configureplatform.cmake) +include(${CLR_ENG_NATIVE_DIR}/configuretools.cmake) if(CLR_CMAKE_TARGET_IOS) cmake_minimum_required(VERSION 3.14.5) @@ -84,6 +84,11 @@ elseif (CLR_CMAKE_TARGET_ARCH_ARM) endif() endif () +if(CLR_CMAKE_TARGET_ANDROID) + add_definitions(-DTARGET_ANDROID) + include_directories(SYSTEM "${CROSS_ROOTFS}/usr/include") +endif() + string(TOUPPER ${CMAKE_BUILD_TYPE} UPPERCASE_CMAKE_BUILD_TYPE) if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG) add_compile_options(-O0) @@ -195,7 +200,6 @@ function(install_library_and_symbols targetName) endfunction() include(configure.cmake) -include(${CLR_ENG_NATIVE_DIR}/configuretools.cmake) add_subdirectory(System.IO.Compression.Native) diff --git a/src/libraries/Native/Unix/Common/pal_config.h.in b/src/libraries/Native/Unix/Common/pal_config.h.in index 08e9fe7fd9f3e..e1b4a3f962559 100644 --- a/src/libraries/Native/Unix/Common/pal_config.h.in +++ b/src/libraries/Native/Unix/Common/pal_config.h.in @@ -100,6 +100,7 @@ #cmakedefine01 HAVE_TCP_H_TCP_KEEPALIVE #cmakedefine01 HAVE_BUILTIN_MUL_OVERFLOW #cmakedefine01 HAVE_DISCONNECTX +#cmakedefine01 HAVE_PTHREAD_SETCANCELSTATE // Mac OS X has stat64, but it is deprecated since plain stat now // provides the same 64-bit aware struct when targeting OS X > 10.5 diff --git a/src/libraries/Native/Unix/System.Globalization.Native/configure.cmake b/src/libraries/Native/Unix/System.Globalization.Native/configure.cmake index 75388ab621136..6114a1bb31ed6 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/configure.cmake +++ b/src/libraries/Native/Unix/System.Globalization.Native/configure.cmake @@ -3,6 +3,11 @@ include(CheckSymbolExists) set(CMAKE_REQUIRED_INCLUDES ${UTYPES_H} ${ICU_HOMEBREW_INC_PATH}) +if(CLR_CMAKE_TARGET_ANDROID) + string(REPLACE ";" ":" ANDROID_RPATHS "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}:${CMAKE_SYSTEM_LIBRARY_PATH}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rpath ${ANDROID_RPATHS}") +endif() + CHECK_C_SOURCE_COMPILES(" #include int main(void) { enum UDateFormatSymbolType e = UDAT_STANDALONE_SHORTER_WEEKDAYS; } diff --git a/src/libraries/Native/Unix/System.Native/pal_console.c b/src/libraries/Native/Unix/System.Native/pal_console.c index e2f15174001fb..00ca624c1b840 100644 --- a/src/libraries/Native/Unix/System.Native/pal_console.c +++ b/src/libraries/Native/Unix/System.Native/pal_console.c @@ -34,6 +34,7 @@ int32_t SystemNative_GetWindowSize(WinSize* windowSize) return error; #else + (void)windowSize; // unused errno = ENOTSUP; return -1; #endif diff --git a/src/libraries/Native/Unix/System.Native/pal_interfaceaddresses.c b/src/libraries/Native/Unix/System.Native/pal_interfaceaddresses.c index 1a6986845c817..4d090d3d9686a 100644 --- a/src/libraries/Native/Unix/System.Native/pal_interfaceaddresses.c +++ b/src/libraries/Native/Unix/System.Native/pal_interfaceaddresses.c @@ -114,7 +114,7 @@ int32_t SystemNative_EnumerateInterfaceAddresses(IPv4AddressFound onIpv4Found, freeifaddrs(headAddr); return -1; } - + assert(result == actualName); int family = current->ifa_addr->sa_family; if (family == AF_INET) @@ -377,7 +377,11 @@ int32_t SystemNative_GetNetworkInterfaces(int32_t * interfaceCount, NetworkInter ecmd.cmd = ETHTOOL_GSET; if (ioctl(socketfd, SIOCETHTOOL, &ifr) == 0) { +#ifdef TARGET_ANDROID + nii->Speed = (int64_t)ecmd.speed; +#else nii->Speed = (int64_t)ethtool_cmd_speed(&ecmd); +#endif if (nii->Speed > 0) { // If we did not get -1 diff --git a/src/libraries/Native/Unix/System.Native/pal_networking.c b/src/libraries/Native/Unix/System.Native/pal_networking.c index 426b831bae468..f036fe9802990 100644 --- a/src/libraries/Native/Unix/System.Native/pal_networking.c +++ b/src/libraries/Native/Unix/System.Native/pal_networking.c @@ -394,7 +394,7 @@ int32_t SystemNative_GetHostEntryForName(const uint8_t* address, HostEntry* entr } // Skip loopback addresses if at least one interface has non-loopback one. - if ((!includeIPv4Loopback && ifa->ifa_addr->sa_family == AF_INET && (ifa->ifa_flags & IFF_LOOPBACK) != 0) || + if ((!includeIPv4Loopback && ifa->ifa_addr->sa_family == AF_INET && (ifa->ifa_flags & IFF_LOOPBACK) != 0) || (!includeIPv6Loopback && ifa->ifa_addr->sa_family == AF_INET6 && (ifa->ifa_flags & IFF_LOOPBACK) != 0)) { entry->IPAddressCount--; @@ -904,7 +904,7 @@ static void ConvertMessageHeaderToMsghdr(struct msghdr* header, const MessageHea iovlen = (int)IOV_MAX; } header->msg_name = messageHeader->SocketAddress; - header->msg_namelen = (unsigned int)messageHeader->SocketAddressLen; + header->msg_namelen = (socklen_t)messageHeader->SocketAddressLen; header->msg_iov = (struct iovec*)messageHeader->IOVectors; header->msg_iovlen = (__typeof__(header->msg_iovlen))iovlen; header->msg_control = messageHeader->ControlBuffer; @@ -1474,7 +1474,7 @@ int32_t SystemNative_Bind(intptr_t socket, int32_t protocolType, uint8_t* socket if (socketAddress == NULL || socketAddressLen < 0) { return Error_EFAULT; - } + } int fd = ToFileDescriptor(socket); diff --git a/src/libraries/Native/Unix/System.Native/pal_process.c b/src/libraries/Native/Unix/System.Native/pal_process.c index 529be7d428c52..641ac120a3269 100644 --- a/src/libraries/Native/Unix/System.Native/pal_process.c +++ b/src/libraries/Native/Unix/System.Native/pal_process.c @@ -227,12 +227,15 @@ int32_t SystemNative_ForkAndExecProcess(const char* filename, int stdinFds[2] = {-1, -1}, stdoutFds[2] = {-1, -1}, stderrFds[2] = {-1, -1}, waitForChildToExecPipe[2] = {-1, -1}; pid_t processId = -1; uint32_t* getGroupsBuffer = NULL; - int thread_cancel_state; sigset_t signal_set; sigset_t old_signal_set; +#ifndef HAVE_PTHREAD_SETCANCELSTATE + int thread_cancel_state; + // None of this code can be canceled without leaking handles, so just don't allow it pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &thread_cancel_state); +#endif // Validate arguments if (NULL == filename || NULL == argv || NULL == envp || NULL == stdinFd || NULL == stdoutFd || @@ -498,9 +501,11 @@ done:; errno = priorErrno; } +#ifndef HAVE_PTHREAD_SETCANCELSTATE // Restore thread cancel state pthread_setcancelstate(thread_cancel_state, &thread_cancel_state); - +#endif + free(getGroupsBuffer); return success ? 0 : -1; @@ -593,7 +598,7 @@ static void ConvertFromPalRLimitToManaged(const struct rlimit* native, RLimit* p pal->MaximumLimit = ConvertFromNativeRLimitInfinityToManagedIfNecessary(native->rlim_max); } -#if defined __USE_GNU && !defined __cplusplus +#if defined(__USE_GNU) && !defined(__cplusplus) && !defined(TARGET_ANDROID) typedef __rlimit_resource_t rlimitResource; typedef __priority_which_t priorityWhich; #else @@ -788,7 +793,7 @@ int32_t SystemNative_SchedSetAffinity(int32_t pid, intptr_t* mask) cpu_set_t set; CPU_ZERO(&set); - intptr_t bits = *mask; + intptr_t bits = *mask; for (int cpu = 0; cpu < maxCpu; cpu++) { if ((bits & (((intptr_t)1u) << cpu)) != 0) @@ -796,7 +801,7 @@ int32_t SystemNative_SchedSetAffinity(int32_t pid, intptr_t* mask) CPU_SET(cpu, &set); } } - + return sched_setaffinity(pid, sizeof(cpu_set_t), &set); } #endif diff --git a/src/libraries/Native/Unix/configure.cmake b/src/libraries/Native/Unix/configure.cmake index 473157178a2c2..6641104a99fdf 100644 --- a/src/libraries/Native/Unix/configure.cmake +++ b/src/libraries/Native/Unix/configure.cmake @@ -6,6 +6,7 @@ include(CheckPrototypeDefinition) include(CheckStructHasMember) include(CheckSymbolExists) include(CheckTypeSize) +include(CheckFunctionExists) if (CLR_CMAKE_TARGET_LINUX) set(PAL_UNIX_NAME \"LINUX\") @@ -899,6 +900,8 @@ check_c_source_compiles( " HAVE_BUILTIN_MUL_OVERFLOW) +check_function_exists(pthread_setcancelstate HAVE_PTHREAD_SETCANCELSTATE) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/Common/pal_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Common/pal_config.h)