Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix native components build for Android #32800

Merged
merged 6 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions eng/native/configureplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions eng/native/configuretools.cmake
Original file line number Diff line number Diff line change
@@ -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 "")
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions eng/native/functions.cmake
Original file line number Diff line number Diff line change
@@ -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()

Expand Down
19 changes: 17 additions & 2 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/clrfeatures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/src/debug/createdump/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ target_link_libraries(createdump
dbgutil
# share the PAL in the dac module
mscordaccore
${ANDROID_GLOB}
${LZMA}
)

add_dependencies(createdump mscordaccore)
Expand Down
10 changes: 7 additions & 3 deletions src/coreclr/src/debug/createdump/crashinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ typedef Elf32_auxv_t elf_aux_entry;
#define PRIu PRIu32
#define PRId PRId32
#define PRIA "08"
#define PRIxA PRIA PRIx
#elif defined(__x86_64__) || defined(__aarch64__)
typedef Elf64_auxv_t elf_aux_entry;
#ifdef TARGET_ANDROID
#define PRIx __PRI_PTR_prefix PRIx64 // PRIx64 in defined as "lu" on aarch64 Android, prepend it with another macro to form "llu"
#else // TARGET_ANDROID
#define PRIx PRIx64
#define PRIu PRIu64
#endif // TARGET_ANDROID
#define PRIu PRIx
#define PRId PRId64
#define PRIA "016"
#define PRIxA PRIA PRIx
#endif

#define PRIxA PRIA PRIx

typedef __typeof__(((elf_aux_entry*) 0)->a_un.a_val) elf_aux_val_t;

// All interesting auvx entry types are AT_SYSINFO_EHDR and below
Expand Down
40 changes: 40 additions & 0 deletions src/coreclr/src/debug/createdump/createdump.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,44 @@ typedef int T_CONTEXT;
#include "threadinfo.h"
#include "memoryregion.h"
#include "crashinfo.h"

#ifdef TARGET_ANDROID
// copied from .tools/android-rootfs/android-ndk-r21/sysroot/usr/include/linux/elfcore.h
am11 marked this conversation as resolved.
Show resolved Hide resolved
// (after running eng/common/cross/build-android-rootfs.sh), because we should not use
// Linux headers in Android build, and if we do it clashes with sys/procfs.h (included above).

struct elf_prstatus {
struct elf_siginfo pr_info;
short pr_cursig;
unsigned long pr_sigpend;
unsigned long pr_sighold;
pid_t pr_pid;
pid_t pr_ppid;
pid_t pr_pgrp;
pid_t pr_sid;
struct timeval pr_utime;
struct timeval pr_stime;
struct timeval pr_cutime;
struct timeval pr_cstime;
elf_gregset_t pr_reg;
int pr_fpvalid;
};

struct elf_prpsinfo {
char pr_state;
char pr_sname;
char pr_zomb;
char pr_nice;
unsigned long pr_flag;
__kernel_uid_t pr_uid;
__kernel_gid_t pr_gid;
pid_t pr_pid, pr_ppid, pr_pgrp, pr_sid;
char pr_fname[16];
char pr_psargs[ELF_PRARGSZ];
};

typedef struct elf_prstatus prstatus_t;
typedef struct elf_prpsinfo prpsinfo_t;
#endif

#include "dumpwriter.h"
2 changes: 1 addition & 1 deletion src/coreclr/src/debug/createdump/memoryregion.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#if defined(__arm__) || defined(__aarch64__)
#if !defined(PAGE_SIZE) && (defined(__arm__) || defined(__aarch64__))
#define PAGE_SIZE sysconf(_SC_PAGESIZE)
#define PAGE_MASK (~(PAGE_SIZE-1))
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/src/dlls/mscoree/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://android-developers.googleblog.com/2016/06/android-changes-for-ndk-developers.html - NDK picked up some shared textrels during the arm (32-bit) build of libcoreclr. Looking at some of your coreclr PRs, @janvorli, I understood that coreclr intends to comply with hardened kernels (at least in 64-bit). The (warning-as) error message was:

Warning: shared library text segment is not shareable

Maybe it could be investigated, as the rootcause might not be Android specific?


endif (CLR_CMAKE_HOST_WIN32)

add_definitions(-DFX_VER_INTERNALNAME_STR=CoreCLR.dll)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/src/gc/unix/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#undef min
#undef max

#include <algorithm>

#if HAVE_SYS_TIME_H
#include <sys/time.h>
#else
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/src/inc/eventtracebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -397,7 +397,7 @@ class XplatEventLoggerConfiguration
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))

Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/src/pal/inc/pal_mstypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,16 @@ extern "C" {
#ifndef PAL_IMPLEMENTATION

// OS X already defines these types in 64 bit
#if !defined(TARGET_OSX)
#ifndef TARGET_OSX
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
#if !defined(TARGET_ANDROID) || defined(FEATURE_NO_HOST)
am11 marked this conversation as resolved.
Show resolved Hide resolved
typedef __int8 int8_t;
#endif
typedef unsigned __int8 uint8_t;
#endif

Expand Down
29 changes: 3 additions & 26 deletions src/coreclr/src/pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,34 +286,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
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/src/pal/src/thread/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/src/scripts/genEventing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/src/vm/ceemain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading