Skip to content

Commit

Permalink
Add build support for Android+CoreCLR (#110471)
Browse files Browse the repository at this point in the history
This change adds build support for the arm64 and x64 CoreCLR runtimes for Android. Initial infrastructure to run a simple sample was also added (src/mono/sample/Android) and we plan to do more in a follow up.

The arm32 and x86 builds are blocked by #111665 since our min API level target is 21. Both will be fixed at a later time.

Contributes to #111491

---------

Co-authored-by: Steve Pfister <stpfiste@microsoft.com>
Co-authored-by: Jan Vorlicek <janvorli@microsoft.com>
Co-authored-by: Ivan Povazan <ivan.povazan@gmail.com>
Co-authored-by: Milos Kotlar <kotlarmilos@gmail.com>
  • Loading branch information
5 people authored Jan 24, 2025
1 parent becfc21 commit ee46066
Show file tree
Hide file tree
Showing 40 changed files with 491 additions and 111 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
<PropertyGroup Label="CalculatePackageRID">
<_packageOS>$(_portableOS)</_packageOS>

<_packageOS Condition="'$(CrossBuild)' == 'true' and '$(_portableOS)' != 'linux-musl' and '$(_portableOS)' != 'linux-bionic'">$(_hostOS)</_packageOS>
<_packageOS Condition="'$(CrossBuild)' == 'true' and '$(_portableOS)' != 'linux-musl' and '$(_portableOS)' != 'linux-bionic' and '$(_portableOS)' != 'android'">$(_hostOS)</_packageOS>

<!-- source-build sets PackageOS to build with non-portable rid packages that were source-built previously. -->
<PackageRID Condition="'$(PackageOS)' != ''">$(PackageOS)-$(TargetArchitecture)</PackageRID>
Expand Down
9 changes: 8 additions & 1 deletion eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
<PropertyGroup>
<!-- Determine if the CoreCLR runtime can build/run for the specified target. -->
<_CoreCLRSupportedOS Condition="'$(TargetsMobile)' != 'true' and '$(TargetsLinuxBionic)' != 'true'">true</_CoreCLRSupportedOS>

<!-- Android 32-bit builds blocked by https://github.com/dotnet/runtime/issues/111665 -->
<_CoreCLRSupportedOS Condition="'$(TargetsAndroid)' == 'true' and '$(TargetArchitecture)' != 'arm' and '$(TargetArchitecture)' != 'x86'">true</_CoreCLRSupportedOS>

<_CoreCLRSupportedArch Condition="'$(TargetArchitecture)' != 'armv6' and '$(TargetArchitecture)' != 'ppc64le' and '$(TargetArchitecture)' != 's390x'">true</_CoreCLRSupportedArch>
<CoreCLRSupported Condition="'$(_CoreCLRSupportedOS)' == 'true' and '$(_CoreCLRSupportedArch)' == 'true'">true</CoreCLRSupported>

Expand Down Expand Up @@ -56,6 +60,7 @@
<PropertyGroup>
<DefaultSubsets>clr+mono+libs+tools+host+packs</DefaultSubsets>
<DefaultSubsets Condition="'$(TargetsMobile)' == 'true'">mono+libs+packs</DefaultSubsets>
<DefaultSubsets Condition="'$(TargetsAndroid)' == 'true' and '$(CoreCLRSupported)' == 'true'">clr.runtime+clr.alljits+clr.corelib+clr.nativecorelib+clr.tools+clr.packages+mono+libs+host+packs</DefaultSubsets>
<DefaultSubsets Condition="'$(TargetsAppleMobile)' == 'true'">clr.nativeaotruntime+clr.nativeaotlibs+mono+libs+packs</DefaultSubsets>
<DefaultSubsets Condition="'$(TargetsLinuxBionic)' == 'true' and '$(MonoSupported)' == 'true'">clr.nativeaotruntime+clr.nativeaotlibs+mono+libs+host+packs</DefaultSubsets>
<DefaultSubsets Condition="'$(TargetsLinuxBionic)' == 'true' and '$(MonoSupported)' != 'true'">clr.nativeaotruntime+clr.nativeaotlibs+libs+packs</DefaultSubsets>
Expand All @@ -80,9 +85,11 @@
<_subset Condition="'$(Subset)' != ''">+$(Subset.ToLowerInvariant())+</_subset>
<_subset Condition="'$(Subset)' == ''">+$(DefaultSubsets)+</_subset>
</PropertyGroup>


<PropertyGroup Condition="'$(RuntimeFlavor)' == ''">
<RuntimeFlavor Condition="('$(TargetsMobile)' == 'true' or '$(TargetsLinuxBionic)' == 'true') and ($(_subset.Contains('+clr.nativeaotlibs+')) or $(_subset.Contains('+clr.runtime+')))">CoreCLR</RuntimeFlavor>
<RuntimeFlavor Condition="'$(TargetsAndroid)' == 'true' and $(_subset.Contains('+clr.'))">CoreCLR</RuntimeFlavor>
<RuntimeFlavor Condition="'$(RuntimeFlavor)' == '' and '$(TargetsMobile)' == 'true'">Mono</RuntimeFlavor>
<RuntimeFlavor Condition="'$(RuntimeFlavor)' == '' and ($(_subset.Contains('+mono+')) or $(_subset.Contains('+mono.runtime+'))) and (!$(_subset.Contains('+clr+')) and !$(_subset.Contains('+clr.runtime+')) and !$(_subset.Contains('+clr.corelib+')))">Mono</RuntimeFlavor>
<RuntimeFlavor Condition="'$(RuntimeFlavor)' == ''">$(PrimaryRuntimeFlavor)</RuntimeFlavor>
Expand Down Expand Up @@ -310,7 +317,7 @@
The cross tools are used as part of the build process with the downloaded build tools, so we need to build them for the host architecture and build them as unsanitized binaries.
-->
<PropertyGroup>
<_BuildAnyCrossArch Condition="'$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(EnableNativeSanitizers)' != ''">true</_BuildAnyCrossArch>
<_BuildAnyCrossArch Condition="'$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(HostOS)' != '$(TargetOS)' or '$(EnableNativeSanitizers)' != ''">true</_BuildAnyCrossArch>
<_BuildCrossComponents Condition="$(_subset.Contains('+clr.crossarchtools+'))">true</_BuildCrossComponents>
<_BuildCrossComponents Condition="'$(ClrRuntimeBuildSubsets)' != '' and ('$(PrimaryRuntimeFlavor)' == 'CoreCLR' or '$(TargetsMobile)' == 'true')">true</_BuildCrossComponents>
<_CrossBitwidthBuild Condition="'$(BuildArchitecture)' == 'x64' and ('$(TargetArchitecture)' == 'x86' or '$(TargetArchitecture)' == 'arm')">true</_CrossBitwidthBuild>
Expand Down
2 changes: 1 addition & 1 deletion eng/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ initDistroRid()
local isCrossBuild="$3"

# Only pass ROOTFS_DIR if __DoCrossArchBuild is specified and the current platform is not an Apple platform (that doesn't use rootfs)
if [[ $isCrossBuild == 1 && "$targetOs" != "osx" && "$targetOs" != "ios" && "$targetOs" != "iossimulator" && "$targetOs" != "tvos" && "$targetOs" != "tvossimulator" && "$targetOs" != "maccatalyst" ]]; then
if [[ $isCrossBuild == 1 && "$targetOs" != "osx" && "$targetOs" != "android" && "$targetOs" != "ios" && "$targetOs" != "iossimulator" && "$targetOs" != "tvos" && "$targetOs" != "tvossimulator" && "$targetOs" != "maccatalyst" ]]; then
passedRootfsDir=${ROOTFS_DIR}
fi
initDistroRidGlobal "${targetOs}" "${targetArch}" "${passedRootfsDir}"
Expand Down
9 changes: 6 additions & 3 deletions eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@ build_native()
fi

if [[ "$targetOS" == android || "$targetOS" == linux-bionic ]]; then
# Keep in sync with $(AndroidApiLevelMin) in Directory.Build.props in the repository rooot
local ANDROID_API_LEVEL=21
if [[ -z "$ANDROID_NDK_ROOT" ]]; then
echo "Error: You need to set the ANDROID_NDK_ROOT environment variable pointing to the Android NDK root."
exit 1
fi

cmakeArgs="-C $__RepoRootDir/eng/native/tryrun.cmake $cmakeArgs"
# cmake cache scripts can't see command line args
export ANDROID_BUILD=1

# keep ANDROID_PLATFORM in sync with SetOSTargetMinVersions in the root Directory.Build.props
cmakeArgs="-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-21 $cmakeArgs"
cmakeArgs="-C $__RepoRootDir/eng/native/tryrun.cmake $cmakeArgs"
cmakeArgs="-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-${ANDROID_API_LEVEL} -DANDROID_NATIVE_API_LEVEL=${ANDROID_API_LEVEL} $cmakeArgs"

# Don't try to set CC/CXX in init-compiler.sh - it's handled in android.toolchain.cmake already
__Compiler="default"
Expand Down
5 changes: 5 additions & 0 deletions eng/native/configureplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,8 @@ if (CLR_CMAKE_TARGET_ANDROID OR CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET
# - Armv6: zlib-ng has build breaks
set(CLR_CMAKE_USE_SYSTEM_ZLIB 1)
endif()

if (NOT CLR_CMAKE_TARGET_ANDROID)
# opt into building tools like ildasm/ilasm
set(CLR_CMAKE_BUILD_TOOLS 1)
endif()
26 changes: 26 additions & 0 deletions eng/native/naming.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@
</PropertyGroup>

<!-- Add path globs specific to native binaries to exclude unnecessary files from packages. -->
<Choose>
<When Condition="$(HostOS.StartsWith('win'))">
<PropertyGroup>
<HostLibSuffix>.dll</HostLibSuffix>
<HostStaticLibSuffix>.lib</HostStaticLibSuffix>
<HostSymbolsSuffix>.pdb</HostSymbolsSuffix>
</PropertyGroup>
</When>
<When Condition="$(HostOS.StartsWith('osx'))">
<PropertyGroup>
<HostLibPrefix>lib</HostLibPrefix>
<HostLibSuffix>.dylib</HostLibSuffix>
<HostStaticLibSuffix>.a</HostStaticLibSuffix>
<HostSymbolsSuffix>.dwarf</HostSymbolsSuffix>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<HostLibPrefix>lib</HostLibPrefix>
<HostLibSuffix>.so</HostLibSuffix>
<HostStaticLibSuffix>.a</HostStaticLibSuffix>
<HostSymbolsSuffix>.dbg</HostSymbolsSuffix>
</PropertyGroup>
</Otherwise>
</Choose>

<Choose>
<When Condition="$(PackageRID.StartsWith('win'))">
<PropertyGroup>
Expand Down
53 changes: 28 additions & 25 deletions eng/native/tryrun.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
set(CROSS_ROOTFS $ENV{ROOTFS_DIR})
set(TARGET_ARCH_NAME $ENV{TARGET_BUILD_ARCH})
set(ANDROID_BUILD $ENV{ANDROID_BUILD})

# Also allow building as Android without specifying `-cross`.
if(NOT DEFINED TARGET_ARCH_NAME AND DEFINED ANDROID_PLATFORM)
if(NOT DEFINED TARGET_ARCH_NAME AND DEFINED ANDROID_BUILD)
if(ANDROID_ABI STREQUAL "arm64-v8a")
set(TARGET_ARCH_NAME "arm64")
elseif(ANDROID_ABI STREQUAL "x86_64")
Expand All @@ -21,34 +22,36 @@ macro(set_cache_value)
set(${ARGV0}__TRYRUN_OUTPUT "dummy output" CACHE STRING "Output from TRY_RUN" FORCE)
endmacro()

if(EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/armv7-alpine-linux-musleabihf OR
EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/armv6-alpine-linux-musleabihf OR
EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/aarch64-alpine-linux-musl OR
EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/s390x-alpine-linux-musl OR
EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/ppc64le-alpine-linux-musl OR
EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/i586-alpine-linux-musl OR
EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/x86_64-alpine-linux-musl OR
EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/riscv64-alpine-linux-musl)
if(NOT DEFINED ANDROID_BUILD)
if(EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/armv7-alpine-linux-musleabihf OR
EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/armv6-alpine-linux-musleabihf OR
EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/aarch64-alpine-linux-musl OR
EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/s390x-alpine-linux-musl OR
EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/ppc64le-alpine-linux-musl OR
EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/i586-alpine-linux-musl OR
EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/x86_64-alpine-linux-musl OR
EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/riscv64-alpine-linux-musl)

set(ALPINE_LINUX 1)
elseif(EXISTS ${CROSS_ROOTFS}/bin/freebsd-version)
set(FREEBSD 1)
set(CMAKE_SYSTEM_NAME FreeBSD)
set(CLR_CMAKE_TARGET_OS freebsd)
elseif(EXISTS ${CROSS_ROOTFS}/usr/platform/i86pc)
set(ILLUMOS 1)
set(CLR_CMAKE_TARGET_OS sunos)
elseif(EXISTS /System/Library/CoreServices)
set(DARWIN 1)
elseif(EXISTS ${CROSS_ROOTFS}/etc/tizen-release)
set(TIZEN 1)
elseif(EXISTS ${CROSS_ROOTFS}/boot/system/develop/headers/config/HaikuConfig.h)
set(HAIKU 1)
set(CLR_CMAKE_TARGET_OS haiku)
set(ALPINE_LINUX 1)
elseif(EXISTS ${CROSS_ROOTFS}/bin/freebsd-version)
set(FREEBSD 1)
set(CMAKE_SYSTEM_NAME FreeBSD)
set(CLR_CMAKE_TARGET_OS freebsd)
elseif(EXISTS ${CROSS_ROOTFS}/usr/platform/i86pc)
set(ILLUMOS 1)
set(CLR_CMAKE_TARGET_OS sunos)
elseif(EXISTS /System/Library/CoreServices)
set(DARWIN 1)
elseif(EXISTS ${CROSS_ROOTFS}/etc/tizen-release)
set(TIZEN 1)
elseif(EXISTS ${CROSS_ROOTFS}/boot/system/develop/headers/config/HaikuConfig.h)
set(HAIKU 1)
set(CLR_CMAKE_TARGET_OS haiku)
endif()
endif()

if(DARWIN)
if(TARGET_ARCH_NAME MATCHES "^(arm64|x64)$")
if(DEFINED ANDROID_BUILD OR TARGET_ARCH_NAME MATCHES "^(arm64|x64)$")
set_cache_value(HAS_POSIX_SEMAPHORES_EXITCODE 1)
set_cache_value(HAVE_BROKEN_FIFO_KEVENT_EXITCODE 1)
set_cache_value(HAVE_BROKEN_FIFO_SELECT_EXITCODE 1)
Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/coreclr/templates/build-perf-sample-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ parameters:
steps:
# Build Android sample app
- ${{ if eq(parameters.osGroup, 'android') }}:
- script: make run MONO_ARCH=arm64 DEPLOY_AND_RUN=false
- script: make run TARGET_ARCH=arm64 DEPLOY_AND_RUN=false
workingDirectory: $(Build.SourcesDirectory)/src/mono/sample/Android
displayName: Build HelloAndroid sample app
- template: /eng/pipelines/common/upload-artifact-step.yml
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/.nuget/coreclr-packages.proj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<ProjectReference Include="ILCompiler.Reflection.ReadyToRun.Experimental\ILCompiler.Reflection.ReadyToRun.Experimental.pkgproj" />
</ItemGroup>

<ItemGroup Condition="'$(RuntimeFlavor)' == 'CoreCLR'">
<ItemGroup Condition="'$(RuntimeFlavor)' == 'CoreCLR' and '$(TargetsMobile)' != 'true' ">
<ProjectReference Include="Microsoft.NETCore.TestHost\Microsoft.NETCore.TestHost.proj" />
</ItemGroup>

<ItemGroup>
<ItemGroup Condition=" '$(TargetsMobile)' != 'true' ">
<ProjectReference Include="Microsoft.NETCore.ILAsm\Microsoft.NETCore.ILAsm.proj" />
<ProjectReference Include="Microsoft.NETCore.ILDAsm\Microsoft.NETCore.ILDAsm.proj" />
</ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,10 @@ if(NOT CLR_CMAKE_HOST_TVOS)
add_subdirectory(utilcode)
add_subdirectory(inc)

add_subdirectory(ilasm)
add_subdirectory(ildasm)
if (CLR_CMAKE_BUILD_TOOLS)
add_subdirectory(ilasm)
add_subdirectory(ildasm)
endif(CLR_CMAKE_BUILD_TOOLS)
add_subdirectory(gcinfo)
add_subdirectory(jit)
add_subdirectory(vm)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/clrfeatures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ endif()

if (CLR_CMAKE_TARGET_WIN32)
set(FEATURE_TYPEEQUIVALENCE 1)
endif(CLR_CMAKE_TARGET_WIN32)
endif(CLR_CMAKE_TARGET_WIN32)
4 changes: 3 additions & 1 deletion src/coreclr/crossgen-corelib.proj
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@
<CrossGenDllCmd>$(CrossGenDllCmd) -o:$(CoreLibOutputPath)</CrossGenDllCmd>
<CrossGenDllCmd>$(CrossGenDllCmd) -r:$([MSBuild]::NormalizePath('$(BinDir)', 'IL', '*.dll'))</CrossGenDllCmd>
<CrossGenDllCmd>$(CrossGenDllCmd) --targetarch:$(TargetArchitecture)</CrossGenDllCmd>
<CrossGenDllCmd>$(CrossGenDllCmd) --targetos:$(TargetOS)</CrossGenDllCmd>
<CrossGenDllCmd Condition="'$(TargetsAndroid)' != 'true'">$(CrossGenDllCmd) --targetos:$(TargetOS)</CrossGenDllCmd>
<!-- Unless and until Android requires R2R specific customizations, we're just dealing with another linux -->
<CrossGenDllCmd Condition="'$(TargetsAndroid)' == 'true'">$(CrossGenDllCmd) --targetos:linux</CrossGenDllCmd>
<CrossGenDllCmd Condition="'$(UsingToolIbcOptimization)' != 'true' and '$(EnableNgenOptimization)' == 'true'">$(CrossGenDllCmd) -m:$(MergedMibcPath) --embed-pgo-data</CrossGenDllCmd>
<CrossGenDllCmd>$(CrossGenDllCmd) -O</CrossGenDllCmd>
<CrossGenDllCmd Condition="'$(Configuration)' == 'Debug' or '$(Configuration)' == 'Checked'">$(CrossGenDllCmd) --verify-type-and-field-layout</CrossGenDllCmd>
Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ else(CLR_CMAKE_HOST_WIN32)

set_exports_linker_option(${EXPORTS_FILE})

if(CLR_CMAKE_TARGET_ANDROID AND CLR_CMAKE_HOST_ARCH_ARM)
set(EXPORTS_LINKER_OPTION "${EXPORTS_LINKER_OPTION} -Wl,--no-warn-shared-textrel")
endif(CLR_CMAKE_TARGET_ANDROID AND CLR_CMAKE_HOST_ARCH_ARM)

endif (CLR_CMAKE_HOST_WIN32)

add_definitions(-DFX_VER_INTERNALNAME_STR=CoreCLR.dll)
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/hosts/inc/coreclrhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@

#include <stdint.h>

#ifdef __cplusplus
#define CORECLR_HOSTING_API_LINKAGE extern "C"
#else
#define CORECLR_HOSTING_API_LINKAGE
#endif

// For each hosting API, we define a function prototype and a function pointer
// The prototype is useful for implicit linking against the dynamic coreclr
// library and the pointer for explicit dynamic loading (dlopen, LoadLibrary)
Expand Down
9 changes: 4 additions & 5 deletions src/coreclr/inc/crosscomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,15 +696,15 @@ typedef struct _T_KNONVOLATILE_CONTEXT_POINTERS {
#define DAC_CS_NATIVE_DATA_SIZE 24
#elif defined(TARGET_FREEBSD) && defined(TARGET_ARM64)
#define DAC_CS_NATIVE_DATA_SIZE 24
#elif defined(TARGET_LINUX) && defined(TARGET_ARM)
#elif (defined(TARGET_LINUX) || defined(TARGET_ANDROID)) && defined(TARGET_ARM)
#define DAC_CS_NATIVE_DATA_SIZE 80
#elif defined(TARGET_LINUX) && defined(TARGET_ARM64)
#elif (defined(TARGET_LINUX) || defined(TARGET_ANDROID)) && defined(TARGET_ARM64)
#define DAC_CS_NATIVE_DATA_SIZE 104
#elif defined(TARGET_LINUX) && defined(TARGET_LOONGARCH64)
#define DAC_CS_NATIVE_DATA_SIZE 96
#elif defined(TARGET_LINUX) && defined(TARGET_X86)
#elif (defined(TARGET_LINUX) || defined(TARGET_ANDROID)) && defined(TARGET_X86)
#define DAC_CS_NATIVE_DATA_SIZE 76
#elif defined(TARGET_LINUX) && defined(TARGET_AMD64)
#elif (defined(TARGET_LINUX) || defined(TARGET_ANDROID)) && defined(TARGET_AMD64)
#define DAC_CS_NATIVE_DATA_SIZE 96
#elif defined(TARGET_LINUX) && defined(TARGET_S390X)
#define DAC_CS_NATIVE_DATA_SIZE 96
Expand Down Expand Up @@ -748,4 +748,3 @@ struct T_CRITICAL_SECTION {
#else
#define T_CRITICAL_SECTION CRITICAL_SECTION
#endif

10 changes: 8 additions & 2 deletions src/coreclr/minipal/Unix/doublemapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#include <linux/memfd.h>
#include <sys/syscall.h> // __NR_memfd_create
#define memfd_create(...) syscall(__NR_memfd_create, __VA_ARGS__)
#elif defined(TARGET_ANDROID)
#include <sys/syscall.h> // __NR_memfd_create
#define memfd_create(...) syscall(__NR_memfd_create, __VA_ARGS__)
#endif // TARGET_LINUX && !MFD_CLOEXEC
#include "minipal.h"
#include "minipal/cpufeatures.h"
Expand Down Expand Up @@ -48,12 +51,13 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu

#ifdef TARGET_FREEBSD
int fd = shm_open(SHM_ANON, O_RDWR | O_CREAT, S_IRWXU);
#elif defined(TARGET_LINUX)
#elif defined(TARGET_LINUX) || defined(TARGET_ANDROID)
int fd = memfd_create("doublemapper", MFD_CLOEXEC);
#else
int fd = -1;
#endif

#ifndef TARGET_ANDROID
// Bionic doesn't have shm_{open,unlink}
// POSIX fallback
if (fd == -1)
{
Expand All @@ -64,11 +68,13 @@ bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecu
fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600);
shm_unlink(name);
}
#endif // !TARGET_ANDROID

if (fd == -1)
{
return false;
}
#endif

if (ftruncate(fd, MaxDoubleMappedSize) == -1)
{
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/pal/src/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,8 @@ elseif(CLR_CMAKE_TARGET_HAIKU)
set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 0)
set(HAVE_SCHED_OTHER_ASSIGNABLE 1)
else() # Anything else is Linux
if(NOT HAVE_LTTNG_TRACEPOINT_H AND FEATURE_EVENT_TRACE)
# LTTNG is not available on Android, so don't error out
if(NOT HAVE_LTTNG_TRACEPOINT_H AND NOT CLR_CMAKE_TARGET_ANDROID AND FEATURE_EVENT_TRACE)
unset(HAVE_LTTNG_TRACEPOINT_H CACHE)
message(FATAL_ERROR "Cannot find liblttng-ust-dev. Try installing liblttng-ust-dev (or the appropriate packages for your platform)")
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/eventprovider/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set(EVENT_MANIFEST ${VM_DIR}/ClrEtwAll.man)

if(CLR_CMAKE_HOST_LINUX)
if(CLR_CMAKE_HOST_LINUX AND NOT CLR_CMAKE_HOST_ANDROID)
add_subdirectory(lttngprovider)
else()
add_subdirectory(dummyprovider)
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/pal/src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2553,6 +2553,8 @@ BOOL MAPMarkSectionAsNotNeeded(LPCVOID lpAddress)
}

BOOL retval = TRUE;

#ifndef TARGET_ANDROID
CPalThread * pThread = InternalGetCurrentThread();
InternalEnterCriticalSection(pThread, &mapping_critsec);
PLIST_ENTRY pLink, pLinkNext = NULL;
Expand Down Expand Up @@ -2583,6 +2585,7 @@ BOOL MAPMarkSectionAsNotNeeded(LPCVOID lpAddress)
}

InternalLeaveCriticalSection(pThread, &mapping_critsec);
#endif // TARGET_ANDROID

TRACE_(LOADER)("MAPMarkSectionAsNotNeeded returning %d\n", retval);
return retval;
Expand Down
8 changes: 3 additions & 5 deletions src/coreclr/runtime.proj
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,14 @@
<ItemGroup Condition="('$(TargetsAndroid)' == 'true' or '$(TargetsLinuxBionic)' == 'true') and '$(ANDROID_NDK_ROOT)' != ''">
<_CoreClrBuildArg Include="-DCMAKE_TOOLCHAIN_FILE=$(ANDROID_NDK_ROOT)/build/cmake/android.toolchain.cmake"/>
<_CoreClrBuildArg Include="-DANDROID_NDK=$(ANDROID_NDK_ROOT)"/>
<_CoreClrBuildArg Include="-DANDROID_STL=none"/>
<_CoreClrBuildArg Include="-DANDROID_CPP_FEATURES=&quot;no-rtti no-exceptions&quot;"/>
<_CoreClrBuildArg Include="-DANDROID_STL=c++_static"/>
<_CoreClrBuildArg Include="-DANDROID_CPP_FEATURES=&quot;no-rtti exceptions&quot;"/>
<_CoreClrBuildArg Include="-DANDROID_PLATFORM=android-$(AndroidApiLevelMin)"/>
<_CoreClrBuildArg Include="-DANDROID_NATIVE_API_LEVEL=$(AndroidApiLevelMin)"/>
<_CoreClrBuildArg Condition="'$(Platform)' == 'arm64'" Include="-DANDROID_ABI=arm64-v8a" />
<_CoreClrBuildArg Condition="'$(Platform)' == 'arm'" Include="-DANDROID_ABI=armeabi-v7a" />
<_CoreClrBuildArg Condition="'$(Platform)' == 'x86'" Include="-DANDROID_ABI=x86" />
<_CoreClrBuildArg Condition="'$(Platform)' == 'x64'" Include="-DANDROID_ABI=x86_64" />

<!-- No LTTNG on Android -->
<_CoreClrBuildArg Include="-cmakeargs -DFEATURE_EVENT_TRACE=0"/>
</ItemGroup>

<PropertyGroup>
Expand Down
Loading

0 comments on commit ee46066

Please sign in to comment.