diff --git a/eng/Subsets.props b/eng/Subsets.props index 0ccf99e83f7223..1f4987bfc30c8f 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -99,7 +99,7 @@ - true + true true diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index 7d1ce8d705d3d6..c28c30514832df 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -139,7 +139,7 @@ add_subdirectory(tools/aot/jitinterface) if(NOT CLR_CROSS_COMPONENTS_BUILD) # NativeAOT only buildable for a subset of CoreCLR-supported configurations - if((CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_WIN32) AND (CLR_CMAKE_HOST_ARCH_ARM64 OR CLR_CMAKE_HOST_ARCH_AMD64) AND NOT (CLR_CMAKE_HOST_OSX AND CLR_CMAKE_HOST_ARCH_ARM64)) + if((CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_WIN32) AND (CLR_CMAKE_HOST_ARCH_ARM64 OR CLR_CMAKE_HOST_ARCH_AMD64)) add_subdirectory(nativeaot) endif() endif(NOT CLR_CROSS_COMPONENTS_BUILD) diff --git a/src/coreclr/gc/unix/gcenv.unix.cpp b/src/coreclr/gc/unix/gcenv.unix.cpp index 85d6a001b03822..a250b528d8096e 100644 --- a/src/coreclr/gc/unix/gcenv.unix.cpp +++ b/src/coreclr/gc/unix/gcenv.unix.cpp @@ -633,7 +633,7 @@ void GCToOSInterface::YieldThread(uint32_t switchCount) static void* VirtualReserveInner(size_t size, size_t alignment, uint32_t flags, uint32_t hugePagesFlag = 0) { assert(!(flags & VirtualReserveFlags::WriteWatch) && "WriteWatch not supported on Unix"); - if (alignment == 0) + if (alignment < OS_PAGE_SIZE) { alignment = OS_PAGE_SIZE; } diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets index 31fd3e65e351ea..cbed76ebd4142f 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets @@ -61,8 +61,7 @@ - compactInst; + int stepRet = compactInst.stepWithCompactEncoding(procInfo.format, pc, _addressSpace, *(Registers_REGDISPLAY*)regs); + return stepRet == UNW_STEP_SUCCESS; + } else { + dwarfOffsetHint = procInfo.format & UNWIND_ARM64_DWARF_SECTION_OFFSET; + } +#elif defined(TARGET_AMD64) + if ((procInfo.format & UNWIND_X86_64_MODE_MASK) != UNWIND_X86_64_MODE_DWARF) { + CompactUnwinder_x86_64 compactInst; + int stepRet = compactInst.stepWithCompactEncoding(procInfo.format, pc, _addressSpace, *(Registers_REGDISPLAY*)regs); + return stepRet == UNW_STEP_SUCCESS; + } else { + dwarfOffsetHint = procInfo.format & UNWIND_X86_64_DWARF_SECTION_OFFSET; + } +#else + PORTABILITY_ASSERT("DoTheStep"); +#endif + } +#endif + + bool retVal = uc.getInfoFromDwarfSection(pc, uwInfoSections, dwarfOffsetHint); if (!retVal) { return false; diff --git a/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm64.inc b/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm64.inc index 9284c7bbf4d757..2323b9f24f8fb2 100644 --- a/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm64.inc +++ b/src/coreclr/nativeaot/Runtime/unix/unixasmmacrosarm64.inc @@ -73,6 +73,7 @@ C_FUNC(\Name): #if defined(__APPLE__) adrp \HelperReg, C_FUNC(\Name)@GOTPAGE ldr \HelperReg, [\HelperReg, C_FUNC(\Name)@GOTPAGEOFF] + ldr \HelperReg, [\HelperReg] #else adrp \HelperReg, C_FUNC(\Name) ldr \HelperReg, [\HelperReg, :lo12:C_FUNC(\Name)] @@ -82,7 +83,8 @@ C_FUNC(\Name): .macro PREPARE_EXTERNAL_VAR_INDIRECT_W Name, HelperReg #if defined(__APPLE__) adrp x\HelperReg, C_FUNC(\Name)@GOTPAGE - ldr w\HelperReg, [x\HelperReg, C_FUNC(\Name)@GOTPAGEOFF] + ldr x\HelperReg, [x\HelperReg, C_FUNC(\Name)@GOTPAGEOFF] + ldr w\HelperReg, [x\HelperReg] #else adrp x\HelperReg, C_FUNC(\Name) ldr w\HelperReg, [x\HelperReg, :lo12:C_FUNC(\Name)] @@ -182,6 +184,10 @@ C_FUNC(\Name): .endif stp x0, lr, [sp,#-0x10]! +#if defined(__APPLE__) + // Apple's tls_get_var trashes xip0 (and possibly xip1) + stp xip0, xip1, [sp,#-0x10]! +#endif // This sequence of instructions is recognized and potentially patched // by the linker (GD->IE/LE relaxation). @@ -206,6 +212,9 @@ C_FUNC(\Name): add \target, \target, x0 #endif +#if defined(__APPLE__) + ldp xip0, xip1, [sp],#0x10 +#endif ldp x0, lr, [sp],#0x10 .endm diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/FatFunctionPointerNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/FatFunctionPointerNode.cs index a4622553d4c9ed..4e7396e8ff609e 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/FatFunctionPointerNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/FatFunctionPointerNode.cs @@ -60,8 +60,9 @@ public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { var builder = new ObjectDataBuilder(factory, relocsOnly); - // These need to be aligned the same as methods because they show up in same contexts - builder.RequireInitialAlignment(factory.Target.MinimumFunctionAlignment); + // These need to be aligned the same as method pointers because they show up in same contexts + // (macOS ARM64 has even stricter alignment requirement for the linker, so round up to pointer size) + builder.RequireInitialAlignment(factory.Target.PointerSize); builder.AddSymbol(this); diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ModuleInitializerListNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ModuleInitializerListNode.cs index a88d3893e6697d..034e173083ed55 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ModuleInitializerListNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ModuleInitializerListNode.cs @@ -135,6 +135,7 @@ public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) // the time of startup. (Linker likely can't do it, unfortunately.) ObjectDataBuilder builder = new ObjectDataBuilder(factory, relocsOnly); + builder.RequireInitialAlignment(factory.Target.PointerSize); builder.AddSymbol(this); builder.AddSymbol(_endSymbol); diff --git a/src/native/external/llvm-libunwind-version.txt b/src/native/external/llvm-libunwind-version.txt index 0a2c1f4f2f4007..3f5f8b71918963 100644 --- a/src/native/external/llvm-libunwind-version.txt +++ b/src/native/external/llvm-libunwind-version.txt @@ -3,3 +3,5 @@ https://github.com/llvm/llvm-project/releases/tag/llvmorg-14.0.6 Apply https://github.com/dotnet/runtime/commit/e57194552327bccaf2b45a9190f0e6e1289472e4 Apply https://github.com/dotnet/runtime/commit/db7ed089a9e20a391a53e0b547f95dc8bf916765 +Apply https://github.com/dotnet/runtime/commit/828c8d0b2a8cdc2479524c5229939641d3610a1b +Apply https://github.com/dotnet/runtime/commit/92e7dffffbcd9725616741fbd73a7e7e1f5e97a4 \ No newline at end of file diff --git a/src/native/external/llvm-libunwind/src/CompactUnwinder.hpp b/src/native/external/llvm-libunwind/src/CompactUnwinder.hpp index 41ec272e1e4fba..95456b067f9fd3 100644 --- a/src/native/external/llvm-libunwind/src/CompactUnwinder.hpp +++ b/src/native/external/llvm-libunwind/src/CompactUnwinder.hpp @@ -28,34 +28,34 @@ namespace libunwind { #if defined(_LIBUNWIND_TARGET_I386) /// CompactUnwinder_x86 uses a compact unwind info to virtually "step" (aka /// unwind) by modifying a Registers_x86 register set -template +template class CompactUnwinder_x86 { public: static int stepWithCompactEncoding(compact_unwind_encoding_t info, uint32_t functionStart, A &addressSpace, - Registers_x86 ®isters); + R ®isters); private: typename A::pint_t pint_t; - static void frameUnwind(A &addressSpace, Registers_x86 ®isters); + static void frameUnwind(A &addressSpace, R ®isters); static void framelessUnwind(A &addressSpace, typename A::pint_t returnAddressLocation, - Registers_x86 ®isters); + R ®isters); static int stepWithCompactEncodingEBPFrame(compact_unwind_encoding_t compactEncoding, uint32_t functionStart, A &addressSpace, - Registers_x86 ®isters); + R ®isters); static int stepWithCompactEncodingFrameless( compact_unwind_encoding_t compactEncoding, uint32_t functionStart, - A &addressSpace, Registers_x86 ®isters, bool indirectStackSize); + A &addressSpace, R ®isters, bool indirectStackSize); }; -template -int CompactUnwinder_x86::stepWithCompactEncoding( +template +int CompactUnwinder_x86::stepWithCompactEncoding( compact_unwind_encoding_t compactEncoding, uint32_t functionStart, - A &addressSpace, Registers_x86 ®isters) { + A &addressSpace, R ®isters) { switch (compactEncoding & UNWIND_X86_MODE_MASK) { case UNWIND_X86_MODE_EBP_FRAME: return stepWithCompactEncodingEBPFrame(compactEncoding, functionStart, @@ -70,10 +70,10 @@ int CompactUnwinder_x86::stepWithCompactEncoding( _LIBUNWIND_ABORT("invalid compact unwind encoding"); } -template -int CompactUnwinder_x86::stepWithCompactEncodingEBPFrame( +template +int CompactUnwinder_x86::stepWithCompactEncodingEBPFrame( compact_unwind_encoding_t compactEncoding, uint32_t functionStart, - A &addressSpace, Registers_x86 ®isters) { + A &addressSpace, R ®isters) { uint32_t savedRegistersOffset = EXTRACT_BITS(compactEncoding, UNWIND_X86_EBP_FRAME_OFFSET); uint32_t savedRegistersLocations = @@ -114,10 +114,10 @@ int CompactUnwinder_x86::stepWithCompactEncodingEBPFrame( return UNW_STEP_SUCCESS; } -template -int CompactUnwinder_x86::stepWithCompactEncodingFrameless( +template +int CompactUnwinder_x86::stepWithCompactEncodingFrameless( compact_unwind_encoding_t encoding, uint32_t functionStart, - A &addressSpace, Registers_x86 ®isters, bool indirectStackSize) { + A &addressSpace, R ®isters, bool indirectStackSize) { uint32_t stackSizeEncoded = EXTRACT_BITS(encoding, UNWIND_X86_FRAMELESS_STACK_SIZE); uint32_t stackAdjust = @@ -233,9 +233,9 @@ int CompactUnwinder_x86::stepWithCompactEncodingFrameless( } -template -void CompactUnwinder_x86::frameUnwind(A &addressSpace, - Registers_x86 ®isters) { +template +void CompactUnwinder_x86::frameUnwind(A &addressSpace, + R ®isters) { typename A::pint_t bp = registers.getEBP(); // ebp points to old ebp registers.setEBP(addressSpace.get32(bp), bp); @@ -245,10 +245,10 @@ void CompactUnwinder_x86::frameUnwind(A &addressSpace, registers.setIP(addressSpace.get32(bp + 4), bp + 4); } -template -void CompactUnwinder_x86::framelessUnwind( +template +void CompactUnwinder_x86::framelessUnwind( A &addressSpace, typename A::pint_t returnAddressLocation, - Registers_x86 ®isters) { + R ®isters) { // return address is on stack after last saved register registers.setIP(addressSpace.get32(returnAddressLocation), returnAddressLocation); // old esp is before return address @@ -260,33 +260,33 @@ void CompactUnwinder_x86::framelessUnwind( #if defined(_LIBUNWIND_TARGET_X86_64) /// CompactUnwinder_x86_64 uses a compact unwind info to virtually "step" (aka /// unwind) by modifying a Registers_x86_64 register set -template +template class CompactUnwinder_x86_64 { public: static int stepWithCompactEncoding(compact_unwind_encoding_t compactEncoding, uint64_t functionStart, A &addressSpace, - Registers_x86_64 ®isters); + R ®isters); private: typename A::pint_t pint_t; - static void frameUnwind(A &addressSpace, Registers_x86_64 ®isters); + static void frameUnwind(A &addressSpace, R ®isters); static void framelessUnwind(A &addressSpace, uint64_t returnAddressLocation, - Registers_x86_64 ®isters); + R ®isters); static int stepWithCompactEncodingRBPFrame(compact_unwind_encoding_t compactEncoding, uint64_t functionStart, A &addressSpace, - Registers_x86_64 ®isters); + R ®isters); static int stepWithCompactEncodingFrameless( compact_unwind_encoding_t compactEncoding, uint64_t functionStart, - A &addressSpace, Registers_x86_64 ®isters, bool indirectStackSize); + A &addressSpace, R ®isters, bool indirectStackSize); }; -template -int CompactUnwinder_x86_64::stepWithCompactEncoding( +template +int CompactUnwinder_x86_64::stepWithCompactEncoding( compact_unwind_encoding_t compactEncoding, uint64_t functionStart, - A &addressSpace, Registers_x86_64 ®isters) { + A &addressSpace, R ®isters) { switch (compactEncoding & UNWIND_X86_64_MODE_MASK) { case UNWIND_X86_64_MODE_RBP_FRAME: return stepWithCompactEncodingRBPFrame(compactEncoding, functionStart, @@ -301,10 +301,10 @@ int CompactUnwinder_x86_64::stepWithCompactEncoding( _LIBUNWIND_ABORT("invalid compact unwind encoding"); } -template -int CompactUnwinder_x86_64::stepWithCompactEncodingRBPFrame( +template +int CompactUnwinder_x86_64::stepWithCompactEncodingRBPFrame( compact_unwind_encoding_t compactEncoding, uint64_t functionStart, - A &addressSpace, Registers_x86_64 ®isters) { + A &addressSpace, R ®isters) { uint32_t savedRegistersOffset = EXTRACT_BITS(compactEncoding, UNWIND_X86_64_RBP_FRAME_OFFSET); uint32_t savedRegistersLocations = @@ -345,10 +345,10 @@ int CompactUnwinder_x86_64::stepWithCompactEncodingRBPFrame( return UNW_STEP_SUCCESS; } -template -int CompactUnwinder_x86_64::stepWithCompactEncodingFrameless( +template +int CompactUnwinder_x86_64::stepWithCompactEncodingFrameless( compact_unwind_encoding_t encoding, uint64_t functionStart, A &addressSpace, - Registers_x86_64 ®isters, bool indirectStackSize) { + R ®isters, bool indirectStackSize) { uint32_t stackSizeEncoded = EXTRACT_BITS(encoding, UNWIND_X86_64_FRAMELESS_STACK_SIZE); uint32_t stackAdjust = @@ -464,9 +464,9 @@ int CompactUnwinder_x86_64::stepWithCompactEncodingFrameless( } -template -void CompactUnwinder_x86_64::frameUnwind(A &addressSpace, - Registers_x86_64 ®isters) { +template +void CompactUnwinder_x86_64::frameUnwind(A &addressSpace, + R ®isters) { uint64_t rbp = registers.getRBP(); // ebp points to old ebp registers.setRBP(addressSpace.get64(rbp), rbp); @@ -476,10 +476,10 @@ void CompactUnwinder_x86_64::frameUnwind(A &addressSpace, registers.setIP(addressSpace.get64(rbp + 8), rbp + 8); } -template -void CompactUnwinder_x86_64::framelessUnwind(A &addressSpace, - uint64_t returnAddressLocation, - Registers_x86_64 ®isters) { +template +void CompactUnwinder_x86_64::framelessUnwind(A &addressSpace, + uint64_t returnAddressLocation, + R ®isters) { // return address is on stack after last saved register registers.setIP(addressSpace.get64(returnAddressLocation), returnAddressLocation); // old esp is before return address @@ -492,13 +492,13 @@ void CompactUnwinder_x86_64::framelessUnwind(A &addressSpace, #if defined(_LIBUNWIND_TARGET_AARCH64) /// CompactUnwinder_arm64 uses a compact unwind info to virtually "step" (aka /// unwind) by modifying a Registers_arm64 register set -template +template class CompactUnwinder_arm64 { public: static int stepWithCompactEncoding(compact_unwind_encoding_t compactEncoding, uint64_t functionStart, A &addressSpace, - Registers_arm64 ®isters); + R ®isters); private: typename A::pint_t pint_t; @@ -506,16 +506,16 @@ class CompactUnwinder_arm64 { static int stepWithCompactEncodingFrame(compact_unwind_encoding_t compactEncoding, uint64_t functionStart, A &addressSpace, - Registers_arm64 ®isters); + R ®isters); static int stepWithCompactEncodingFrameless( compact_unwind_encoding_t compactEncoding, uint64_t functionStart, - A &addressSpace, Registers_arm64 ®isters); + A &addressSpace, R ®isters); }; -template -int CompactUnwinder_arm64::stepWithCompactEncoding( +template +int CompactUnwinder_arm64::stepWithCompactEncoding( compact_unwind_encoding_t compactEncoding, uint64_t functionStart, - A &addressSpace, Registers_arm64 ®isters) { + A &addressSpace, R ®isters) { switch (compactEncoding & UNWIND_ARM64_MODE_MASK) { case UNWIND_ARM64_MODE_FRAME: return stepWithCompactEncodingFrame(compactEncoding, functionStart, @@ -527,10 +527,10 @@ int CompactUnwinder_arm64::stepWithCompactEncoding( _LIBUNWIND_ABORT("invalid compact unwind encoding"); } -template -int CompactUnwinder_arm64::stepWithCompactEncodingFrameless( +template +int CompactUnwinder_arm64::stepWithCompactEncodingFrameless( compact_unwind_encoding_t encoding, uint64_t, A &addressSpace, - Registers_arm64 ®isters) { + R ®isters) { uint32_t stackSize = 16 * EXTRACT_BITS(encoding, UNWIND_ARM64_FRAMELESS_STACK_SIZE_MASK); @@ -609,10 +609,10 @@ int CompactUnwinder_arm64::stepWithCompactEncodingFrameless( return UNW_STEP_SUCCESS; } -template -int CompactUnwinder_arm64::stepWithCompactEncodingFrame( +template +int CompactUnwinder_arm64::stepWithCompactEncodingFrame( compact_unwind_encoding_t encoding, uint64_t, A &addressSpace, - Registers_arm64 ®isters) { + R ®isters) { uint64_t savedRegisterLoc = registers.getFP() - 8; if (encoding & UNWIND_ARM64_FRAME_X19_X20_PAIR) { diff --git a/src/native/external/llvm-libunwind/src/DwarfParser.hpp b/src/native/external/llvm-libunwind/src/DwarfParser.hpp index 3c8a5d5caa8e78..0a57f69a62745c 100644 --- a/src/native/external/llvm-libunwind/src/DwarfParser.hpp +++ b/src/native/external/llvm-libunwind/src/DwarfParser.hpp @@ -269,7 +269,7 @@ bool CFI_Parser::findFDE(A &addressSpace, pint_t pc, pint_t ehSectionStart, pint_t pcRange = addressSpace.getEncodedP( p, nextCFI, cieInfo->pointerEncoding & 0x0F); // Test if pc is within the function this FDE covers. - if ((pcStart < pc) && (pc <= pcStart + pcRange)) { + if ((pcStart <= pc) && (pc < pcStart + pcRange)) { // parse rest of info fdeInfo->lsda = 0; // check for augmentation length