Fix native components build for Android (#32800)
authorAdeel Mujahid <adeelbm@outlook.com>
Tue, 17 Mar 2020 23:03:37 +0000 (01:03 +0200)
committerGitHub <noreply@github.com>
Tue, 17 Mar 2020 23:03:37 +0000 (16:03 -0700)
* Fix native components build for Android

* Add cmake introspection for pthread_setcancelstate

* Address CR feedback

* Use calculated eth speed for Android

* Use #ifdef FEATURE_EVENT_TRACE

27 files changed:
eng/native/configureplatform.cmake
eng/native/configuretools.cmake
eng/native/functions.cmake
src/coreclr/CMakeLists.txt
src/coreclr/clrfeatures.cmake
src/coreclr/src/CMakeLists.txt
src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt
src/coreclr/src/gc/unix/gcenv.unix.cpp
src/coreclr/src/inc/eventtracebase.h
src/coreclr/src/pal/src/CMakeLists.txt
src/coreclr/src/pal/src/safecrt/mbusafecrt_internal.h
src/coreclr/src/pal/src/thread/context.cpp
src/coreclr/src/scripts/genEventing.py
src/coreclr/src/vm/ceemain.cpp
src/coreclr/src/vm/gctoclreventsink.cpp
src/coreclr/tests/CMakeLists.txt
src/installer/corehost/CMakeLists.txt
src/installer/corehost/cli/common.cmake
src/installer/settings.cmake
src/libraries/Native/Unix/CMakeLists.txt
src/libraries/Native/Unix/Common/pal_config.h.in
src/libraries/Native/Unix/System.Globalization.Native/configure.cmake
src/libraries/Native/Unix/System.Native/pal_console.c
src/libraries/Native/Unix/System.Native/pal_interfaceaddresses.c
src/libraries/Native/Unix/System.Native/pal_networking.c
src/libraries/Native/Unix/System.Native/pal_process.c
src/libraries/Native/Unix/configure.cmake

index 174cce725d557e0217388ef82d78fde75ed9b699..ab48a342fe44674fa50389e986b1cbfbec07815d 100644 (file)
@@ -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)
index b59504a10e7616dd19464e802f3b42d65bdc4f78..b91237da89bfb707e559381e4b46ff7ae04f64f7 100644 (file)
@@ -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()
index aa2c9411ab68d7c423aaec1668caa37431df6f27..cc806fed2634336c8364dcfc75412470253bbcda 100644 (file)
@@ -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()
 
index 7e2b66caeec025b51aed1ab3e346bb602a01125a..709b5754775d1da502b629f7c69623ed71df6b6f 100644 (file)
@@ -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)
index 078b4e73ac8044c26274c63f1e163ef5d1ea45d0..9025602a3c68c3e90ab740efbba38b765795651a 100644 (file)
@@ -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)
index b6584b2de7830144f96ed369eea5d4470713df3c..262e6b7d021c3e24e8e2c62d17b4ae0479c54f31 100644 (file)
@@ -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")
index e86e91f6a69e88251428d975f6b5e3410553917a..0517bb50df32183dcbbc40ca44ca3a3ed15f3edf 100644 (file)
@@ -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)
index f32308c90106c801c6d67635df3ced9de2e76a98..855f2da02a98229339ba010739494ce1a1ce6730 100644 (file)
@@ -25,6 +25,8 @@
 #undef min
 #undef max
 
+#include <algorithm>
+
 #if HAVE_SYS_TIME_H
  #include <sys/time.h>
 #else
index cde996a92185e2bf0f8a7b7e76ef823a76162196..a02d8f5fbda696fc109b3b904d62964943d25744 100644 (file)
@@ -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 @@ private:
     NewArrayHolder<WCHAR> _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))
 
index 249936cd392708d29ff6760359d4ffb870ce16d8..37aee432577830a93b0bf546aa4193a12d9dde27 100644 (file)
@@ -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
index 83c1db99a80bf9af030e3c1dceb0201c2d6ade56..00136ecfe2839ff85b9b24a68f46ba4deea5c165 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef MBUSAFECRT_INTERNAL_H
 #define MBUSAFECRT_INTERNAL_H
 
+#define PAL_IMPLEMENTATION
+
 #include "pal_mstypes.h"
 
 #ifndef DLLEXPORT
index d00f6888564793b74c11e11d0f28446d02fcfddf..a89bdb2649f0d4ec3875ae99635f8faa3d1b2fc6 100644 (file)
@@ -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
index 50fde02fbd02c6cb65ffc6cdf7a40c081b424e29..69c96adf5a063f3e98ed1073d67cb937cb329797 100644 (file)
@@ -639,7 +639,8 @@ typedef struct _EVENT_DESCRIPTOR
 {
     int const Level;
     ULONGLONG const Keyword;
-} EVENT_DESCRIPTOR;""")
+} EVENT_DESCRIPTOR;
+""")
 
             if not is_windows:
                 Clrproviders.write(eventpipe_trace_context_typedef)  # define EVENTPIPE_TRACE_CONTEXT
index 050904315b804fa2efa1f342ccc6ee0bff7b4437..5f7965e0a0abf5be2dfade98a5bd8244de530a55 100644 (file)
@@ -925,10 +925,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.
index 1389d417737c2e734c4e9c8f8bc493b2c9c94432..a9bc4bd7654d1701d15151499869aaeedc5c9dd5 100644 (file)
@@ -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<ETW::GCLog::ETW_GC_INFO::GC_REASON>(reason);
     gcStartInfo.GCStart.Type = static_cast<ETW::GCLog::ETW_GC_INFO::GC_TYPE>(type);
     ETW::GCLog::FireGcStart(&gcStartInfo);
+#endif
 }
 
 void GCToCLREventSink::FireGCGenerationRange(uint8_t generation, void* rangeStart, uint64_t rangeUsedLength, uint64_t rangeReservedLength)
index 47ee1e3a9a4de3a8ae60b28e4bea93de73130b46..1ea31cdd8a0357c5d8a253ccd4c3dc402b7c126d 100644 (file)
@@ -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)
index 49bcbcfe1815eb430e0f88dbd9662309be1a50b2..7d1854cee4266a9b9ef48a29af6345114f3db8e7 100644 (file)
@@ -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)
index f64377711a65e61d37275b1d7907b5d97c11828a..4cd09d3747b527a737e5ab963ee223bfae657b40 100644 (file)
@@ -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()
 
index 6c56313847a68621ca6cca04788f9ba38faa86d7..9bb9d81106e40ae91c30ed43ddc5337766948219 100644 (file)
@@ -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)
index ef99465e3c77e6373fc152eff9152e16e15cfa9a..d964b445e23cc8e3325e1bc4a389f5b6aa82f5e3 100644 (file)
@@ -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)
 
index 08e9fe7fd9f3efad87d6018331d4753aa0bd89bf..e1b4a3f96255932087d124e1346f41b81ab6ad15 100644 (file)
 #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
index 75388ab621136a10df7c17ff2393a96c1b589c8d..6114a1bb31ed67e4beaea27ccaa4aff50898e315 100644 (file)
@@ -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 <unicode/udat.h>
     int main(void) { enum UDateFormatSymbolType e = UDAT_STANDALONE_SHORTER_WEEKDAYS; }
index e2f15174001fbb90e5803f2476848c4977016b17..00ca624c1b840b7eeee59b86cb822e2c06ad0554 100644 (file)
@@ -34,6 +34,7 @@ int32_t SystemNative_GetWindowSize(WinSize* windowSize)
 
     return error;
 #else
+    (void)windowSize; // unused
     errno = ENOTSUP;
     return -1;
 #endif
index 1a6986845c81737cd916e89eae6713ec56edbfff..4d090d3d9686a501d64c6d1a8ade9438b93114e8 100644 (file)
@@ -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
index 426b831bae4680e602d2fcc14e36803b09c545cb..f036fe98029909a94bbd32d41c1b0f87301a4903 100644 (file)
@@ -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);
 
index 529be7d428c52ecefa49dd2c000bbf9151c25373..641ac120a3269a78ac8e9e370fc3f92479c458d7 100644 (file)
@@ -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
index 473157178a2c2cbc67abfd05cd1aab40307eb0af..6641104a99fdfc8bc474df7c30a39bd165f5066f 100644 (file)
@@ -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)