From 1d8c4d761a5f1aad401328069520c7fc357045ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Tue, 28 Nov 2023 09:51:48 +0100 Subject: [PATCH] Fixes for Bionic on x64 Fixes #93942. Works around #95223 (a better but more risky fix is in #95312, so I'm not going to resolve that with this PR). The first issue is that we don't consider x64 Windows (or x64 Linux) to x64 Bionic build a crossbuild. The crossbuild detection only looks at architecture, not at the OS. The fix is very conservative so that we can backport to 8.0. Bionic is always a crossbuild. The second part is a port of https://github.com/dotnet/corert/pull/8323 to x64. It is a lot less work than on arm64 because x64 Linux already has to assume `INLINE_GETTHREAD` could be a call so everything is setup for it. I tested this all on a x64 Bionic hello world. I also ran all of smoke tests on x64 Linux with `FEATURE_EMULATED_TLS` enabled. All of this looks very non-risky so I'm going to ask for a backport. --- .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets | 1 + src/coreclr/nativeaot/Runtime/amd64/InteropThunksHelpers.S | 6 ++++++ src/coreclr/nativeaot/Runtime/unix/unixasmmacrosamd64.inc | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index fe49cab873abf1..a64d20b4ca37e4 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -34,6 +34,7 @@ The .NET Foundation licenses this file to you under the MIT license. $(RuntimeIdentifier) + $(RuntimeIdentifier) x86_64 diff --git a/src/coreclr/nativeaot/Runtime/amd64/InteropThunksHelpers.S b/src/coreclr/nativeaot/Runtime/amd64/InteropThunksHelpers.S index 5c0b6f631ef539..a53dd3c63624f6 100644 --- a/src/coreclr/nativeaot/Runtime/amd64/InteropThunksHelpers.S +++ b/src/coreclr/nativeaot/Runtime/amd64/InteropThunksHelpers.S @@ -14,7 +14,11 @@ LEAF_ENTRY RhCommonStub, _TEXT alloc_stack SIZEOF_FP_REGS SAVE_FLOAT_ARGUMENT_REGISTERS 0 +#ifdef FEATURE_EMULATED_TLS + call C_FUNC(RhpGetThunkData) +#else INLINE_GET_TLS_VAR tls_thunkData +#endif RESTORE_FLOAT_ARGUMENT_REGISTERS 0 free_stack SIZEOF_FP_REGS @@ -36,6 +40,7 @@ LEAF_ENTRY RhGetCommonStubAddress, _TEXT LEAF_END RhGetCommonStubAddress, _TEXT +#ifndef FEATURE_EMULATED_TLS LEAF_ENTRY RhGetCurrentThunkContext, _TEXT INLINE_GET_TLS_VAR tls_thunkData @@ -43,3 +48,4 @@ LEAF_ENTRY RhGetCurrentThunkContext, _TEXT mov rax, qword ptr [rax] ret LEAF_END RhGetCurrentThunkContext, _TEXT +#endif //FEATURE_EMULATED_TLS diff --git a/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosamd64.inc b/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosamd64.inc index ab64ef9ce92b49..11225c0ad5ed2b 100644 --- a/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosamd64.inc +++ b/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosamd64.inc @@ -300,8 +300,12 @@ C_FUNC(\Name): .macro INLINE_GETTHREAD +#ifdef FEATURE_EMULATED_TLS + call C_FUNC(RhpGetThread) +#else // Inlined version of call C_FUNC(RhpGetThread) INLINE_GET_TLS_VAR tls_CurrentThread +#endif .endm .macro INLINE_THREAD_UNHIJACK threadReg, trashReg1, trashReg2