Skip to content

Commit b32d486

Browse files
authored
Enable CoreCLR/tvOS build (#111804)
* Enable CoreCLR/tvOS build * #import -> #include * Fix Linux build * Fix merge
1 parent 9d4faf1 commit b32d486

File tree

12 files changed

+68
-46
lines changed

12 files changed

+68
-46
lines changed

docs/workflow/building/coreclr/ios.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Cross Compilation for iOS Simulator on macOS
1+
# Cross Compilation for iOS/tvOS Simulator on macOS
22

33
## Requirements
44

@@ -9,7 +9,7 @@ Build requirements are the same as for building native CoreCLR on macOS. iPhone
99
Build the runtime pack and tools with
1010

1111
```
12-
./build.sh clr+clr.runtime+libs+packs -os [iossimulator/maccatalyst] -arch [x64/arm64] -cross -c Release
12+
./build.sh clr+clr.runtime+libs+packs -os [iossimulator/tvossimulator/maccatalyst] -arch [x64/arm64] -cross -c Release
1313
```
1414

1515
## Running the sample iOS app

src/coreclr/CMakeLists.txt

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ if(CLR_CMAKE_HOST_UNIX)
105105
add_linker_flag(-Wl,-z,notext)
106106
endif()
107107

108-
if(NOT CLR_CMAKE_HOST_TVOS)
109-
add_subdirectory(pal)
110-
endif()
108+
add_subdirectory(pal)
109+
111110
if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
112111
add_subdirectory(hosts)
113112
endif()
@@ -135,9 +134,7 @@ add_subdirectory(${CLR_SRC_NATIVE_DIR}/containers containers)
135134
add_subdirectory(${CLR_SRC_NATIVE_DIR}/eventpipe eventpipe)
136135
add_subdirectory(${CLR_SRC_NATIVE_DIR}/minipal shared_minipal)
137136

138-
if(NOT CLR_CMAKE_HOST_TVOS)
139-
add_subdirectory(debug/debug-pal)
140-
endif()
137+
add_subdirectory(debug/debug-pal)
141138

142139
add_subdirectory(minipal)
143140

@@ -273,36 +270,34 @@ if(CLR_CMAKE_HOST_UNIX)
273270
add_subdirectory(nativeresources)
274271
endif(CLR_CMAKE_HOST_UNIX)
275272

276-
if(NOT CLR_CMAKE_HOST_TVOS)
277-
add_subdirectory(utilcode)
278-
add_subdirectory(inc)
273+
add_subdirectory(utilcode)
274+
add_subdirectory(inc)
279275

280-
if (CLR_CMAKE_BUILD_TOOLS)
281-
add_subdirectory(ilasm)
282-
add_subdirectory(ildasm)
283-
endif(CLR_CMAKE_BUILD_TOOLS)
284-
add_subdirectory(gcinfo)
276+
if (CLR_CMAKE_BUILD_TOOLS)
277+
add_subdirectory(ilasm)
278+
add_subdirectory(ildasm)
279+
endif(CLR_CMAKE_BUILD_TOOLS)
280+
add_subdirectory(gcinfo)
285281

286-
if (NOT CLR_CMAKE_TARGET_ARCH_WASM)
287-
add_subdirectory(jit)
288-
endif()
282+
if (NOT CLR_CMAKE_TARGET_ARCH_WASM)
283+
add_subdirectory(jit)
284+
endif()
289285

290-
add_subdirectory(vm)
291-
add_subdirectory(md)
286+
add_subdirectory(vm)
287+
add_subdirectory(md)
292288

293-
if (NOT CLR_CMAKE_TARGET_ARCH_WASM)
294-
add_subdirectory(debug)
295-
endif()
289+
if (NOT CLR_CMAKE_TARGET_ARCH_WASM)
290+
add_subdirectory(debug)
291+
endif()
296292

297-
add_subdirectory(binder)
298-
add_subdirectory(classlibnative)
299-
add_subdirectory(dlls)
293+
add_subdirectory(binder)
294+
add_subdirectory(classlibnative)
295+
add_subdirectory(dlls)
300296

301-
if (NOT CLR_CMAKE_TARGET_ARCH_WASM)
302-
add_subdirectory(unwinder)
303-
add_subdirectory(interop)
304-
endif()
305-
endif(NOT CLR_CMAKE_HOST_TVOS)
297+
if (NOT CLR_CMAKE_TARGET_ARCH_WASM)
298+
add_subdirectory(unwinder)
299+
add_subdirectory(interop)
300+
endif()
306301

307302
if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
308303
add_subdirectory(tools)

src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ endif(CLR_CMAKE_TARGET_WIN32)
228228

229229
# add the install targets
230230
install_clr(TARGETS coreclr DESTINATIONS . sharedFramework COMPONENT runtime)
231-
if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS)
231+
if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS)
232232
install_clr(TARGETS coreclr_static DESTINATIONS . sharedFramework COMPONENT runtime)
233233
endif()
234234

src/coreclr/pal/src/config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#cmakedefine01 HAVE__LWP_SELF
4646
#cmakedefine01 HAVE_MACH_THREADS
4747
#cmakedefine01 HAVE_MACH_EXCEPTIONS
48+
#cmakedefine01 HAVE_SIGALTSTACK
4849
#cmakedefine01 HAVE_VM_ALLOCATE
4950
#cmakedefine01 HAVE_VM_READ
5051
#cmakedefine01 HAVE_DIRECTIO

src/coreclr/pal/src/configure.cmake

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,20 @@ check_function_exists(statvfs HAVE_STATVFS)
120120
check_function_exists(thread_self HAVE_THREAD_SELF)
121121
check_function_exists(_lwp_self HAVE__LWP_SELF)
122122
check_function_exists(pthread_mach_thread_np HAVE_MACH_THREADS)
123-
check_function_exists(thread_set_exception_ports HAVE_MACH_EXCEPTIONS)
123+
check_cxx_source_compiles("
124+
#include <mach/mach.h>
125+
int main(int argc, char **argv) {
126+
static mach_port_name_t port;
127+
thread_set_exception_ports(mach_thread_self(), EXC_MASK_BAD_ACCESS, port, EXCEPTION_DEFAULT, MACHINE_THREAD_STATE);
128+
return 0;
129+
}" HAVE_MACH_EXCEPTIONS)
130+
check_cxx_source_compiles("
131+
#include <signal.h>
132+
#include <stdlib.h>
133+
int main(int argc, char **argv) {
134+
sigaltstack(NULL, NULL);
135+
return 0;
136+
}" HAVE_SIGALTSTACK)
124137
check_function_exists(vm_allocate HAVE_VM_ALLOCATE)
125138
check_function_exists(vm_read HAVE_VM_READ)
126139
check_function_exists(directio HAVE_DIRECTIO)

src/coreclr/pal/src/debug/debug.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const BOOL DBG_DETACH = FALSE;
8888
#endif
8989
static const char PAL_OUTPUTDEBUGSTRING[] = "PAL_OUTPUTDEBUGSTRING";
9090

91-
#ifdef _DEBUG
91+
#if defined(_DEBUG) && !defined(TARGET_IOS) && !defined(TARGET_TVOS)
9292
#define ENABLE_RUN_ON_DEBUG_BREAK 1
9393
#endif // _DEBUG
9494

src/coreclr/pal/src/exception/seh.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ PAL_ERROR SEHEnable(CPalThread *pthrCurrent)
304304
{
305305
#if HAVE_MACH_EXCEPTIONS
306306
return pthrCurrent->EnableMachExceptions();
307-
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__) || defined(__wasm__)
307+
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__) || defined(__APPLE__) || defined(__wasm__)
308308
return NO_ERROR;
309-
#else// HAVE_MACH_EXCEPTIONS
309+
#else // HAVE_MACH_EXCEPTIONS
310310
#error not yet implemented
311311
#endif // HAVE_MACH_EXCEPTIONS
312312
}
@@ -329,7 +329,7 @@ PAL_ERROR SEHDisable(CPalThread *pthrCurrent)
329329
{
330330
#if HAVE_MACH_EXCEPTIONS
331331
return pthrCurrent->DisableMachExceptions();
332-
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__) || defined(__wasm__)
332+
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__) || defined(__APPLE__) || defined(__wasm__)
333333
return NO_ERROR;
334334
#else // HAVE_MACH_EXCEPTIONS
335335
#error not yet implemented

src/coreclr/pal/src/exception/signal.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ BOOL SEHInitializeSignals(CorUnix::CPalThread *pthrCurrent, DWORD flags)
188188
handle_signal(SIGINT, sigint_handler, &g_previous_sigint, 0 /* additionalFlags */, true /* skipIgnored */);
189189
handle_signal(SIGQUIT, sigquit_handler, &g_previous_sigquit, 0 /* additionalFlags */, true /* skipIgnored */);
190190

191-
#if HAVE_MACH_EXCEPTIONS
191+
#if HAVE_MACH_EXCEPTIONS || !HAVE_SIGALTSTACK
192192
handle_signal(SIGSEGV, sigsegv_handler, &g_previous_sigsegv);
193193
#else
194194
handle_signal(SIGTRAP, sigtrap_handler, &g_previous_sigtrap);
@@ -569,6 +569,7 @@ extern "C" void signal_handler_worker(int code, siginfo_t *siginfo, void *contex
569569
RtlRestoreContext(&returnPoint->context, NULL);
570570
}
571571

572+
#if HAVE_SIGALTSTACK
572573
/*++
573574
Function :
574575
SwitchStackAndExecuteHandler
@@ -609,6 +610,7 @@ static bool SwitchStackAndExecuteHandler(int code, siginfo_t *siginfo, void *con
609610

610611
return pReturnPoint->returnFromHandler;
611612
}
613+
#endif
612614

613615
#endif // !HAVE_MACH_EXCEPTIONS
614616

@@ -644,6 +646,10 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context)
644646
{
645647
if (GetCurrentPalThread())
646648
{
649+
#if defined(TARGET_TVOS)
650+
(void)!write(STDERR_FILENO, StackOverflowMessage, sizeof(StackOverflowMessage) - 1);
651+
PROCAbort(SIGSEGV, siginfo);
652+
#else // TARGET_TVOS
647653
size_t handlerStackTop = __sync_val_compare_and_swap((size_t*)&g_stackOverflowHandlerStack, (size_t)g_stackOverflowHandlerStack, 0);
648654
if (handlerStackTop == 0)
649655
{
@@ -672,6 +678,7 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context)
672678
PROCAbort(SIGSEGV, siginfo);
673679
}
674680
(void)!write(STDERR_FILENO, StackOverflowHandlerReturnedMessage, sizeof(StackOverflowHandlerReturnedMessage) - 1);
681+
#endif // TARGET_TVOS
675682
}
676683
else
677684
{
@@ -686,6 +693,7 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context)
686693
// Now that we know the SIGSEGV didn't happen due to a stack overflow, execute the common
687694
// hardware signal handler on the original stack.
688695

696+
#if HAVE_SIGALTSTACK
689697
if (GetCurrentPalThread() && IsRunningOnAlternateStack(context))
690698
{
691699
if (SwitchStackAndExecuteHandler(code, siginfo, context, 0 /* sp */)) // sp == 0 indicates execution on the original stack
@@ -694,6 +702,7 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context)
694702
}
695703
}
696704
else
705+
#endif
697706
{
698707
// The code flow gets here when the signal handler is not running on an alternate stack or when it wasn't created
699708
// by coreclr. In both cases, we execute the common_signal_handler directly.

src/coreclr/pal/src/include/pal/thread.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ namespace CorUnix
572572
m_pNext = pNext;
573573
};
574574

575-
#if !HAVE_MACH_EXCEPTIONS
575+
#if !HAVE_MACH_EXCEPTIONS && HAVE_SIGALTSTACK
576576
BOOL
577577
EnsureSignalAlternateStack(
578578
void

src/coreclr/pal/src/init/sxs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ AllocatePalThread(CPalThread **ppThread)
6464
goto exit;
6565
}
6666

67-
#if !HAVE_MACH_EXCEPTIONS
67+
#if !HAVE_MACH_EXCEPTIONS && HAVE_SIGALTSTACK
6868
// Ensure alternate stack for SIGSEGV handling. Our SIGSEGV handler is set to
6969
// run on an alternate stack and the stack needs to be allocated per thread.
7070
if (!pThread->EnsureSignalAlternateStack())

src/coreclr/pal/src/thread/process.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ CorUnix::InternalCreateProcess(
513513
LPPROCESS_INFORMATION lpProcessInformation
514514
)
515515
{
516+
#ifdef TARGET_TVOS
517+
return ERROR_NOT_SUPPORTED;
518+
#else
516519
PAL_ERROR palError = NO_ERROR;
517520
IPalObject *pobjProcess = NULL;
518521
IPalObject *pobjProcessRegistered = NULL;
@@ -1049,6 +1052,7 @@ CorUnix::InternalCreateProcess(
10491052
}
10501053

10511054
return palError;
1055+
#endif // !TARGET_TVOS
10521056
}
10531057

10541058

@@ -2180,7 +2184,7 @@ PROCCreateCrashDump(
21802184
INT cbErrorMessageBuffer,
21812185
bool serialize)
21822186
{
2183-
#if defined(TARGET_IOS)
2187+
#if defined(TARGET_IOS) || defined(TARGET_TVOS)
21842188
return FALSE;
21852189
#else
21862190
_ASSERTE(argv.size() > 0);
@@ -2310,7 +2314,7 @@ PROCCreateCrashDump(
23102314
}
23112315
}
23122316
return true;
2313-
#endif // !TARGET_IOS
2317+
#endif // !TARGET_IOS && !TARGET_TVOS
23142318
}
23152319

23162320
/*++

src/coreclr/pal/src/thread/thread.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static void InternalEndCurrentThreadWrapper(void *arg)
134134
will lock its own critical section */
135135
LOADCallDllMain(DLL_THREAD_DETACH, NULL);
136136

137-
#if !HAVE_MACH_EXCEPTIONS
137+
#if !HAVE_MACH_EXCEPTIONS && HAVE_SIGALTSTACK
138138
pThread->FreeSignalAlternateStack();
139139
#endif // !HAVE_MACH_EXCEPTIONS
140140

@@ -1552,7 +1552,7 @@ CPalThread::ThreadEntry(
15521552
}
15531553
#endif // HAVE_SCHED_GETAFFINITY && HAVE_SCHED_SETAFFINITY
15541554

1555-
#if !HAVE_MACH_EXCEPTIONS
1555+
#if !HAVE_MACH_EXCEPTIONS && HAVE_SIGALTSTACK
15561556
if (!pThread->EnsureSignalAlternateStack())
15571557
{
15581558
ASSERT("Cannot allocate alternate stack for SIGSEGV!\n");
@@ -2275,7 +2275,7 @@ CPalThread::WaitForStartStatus(
22752275
return m_fStartStatus;
22762276
}
22772277

2278-
#if !HAVE_MACH_EXCEPTIONS
2278+
#if !HAVE_MACH_EXCEPTIONS && HAVE_SIGALTSTACK
22792279
/*++
22802280
Function :
22812281
EnsureSignalAlternateStack

0 commit comments

Comments
 (0)