Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8d01b3d
Fix AV checks
filipnavara Feb 28, 2024
59d83fb
Implement RhpLockCmpXchg64
filipnavara Feb 28, 2024
456e06e
Fix accessing ThunkParamSlot
filipnavara Feb 28, 2024
2a0c256
Implement P/Invoke asm helpers
filipnavara Feb 28, 2024
20fabf9
WIP: Math helpers
filipnavara Feb 28, 2024
e91de71
Update runtime tests to work in win-x86 configuration
filipnavara Feb 26, 2024
79b6075
Enable win-x86 NativeAOT build
filipnavara Feb 28, 2024
ddf5055
Replace InternalCalls.memmove with Unsafe.CopyBlock
filipnavara Mar 8, 2024
27da448
Use ref version of Unsafe.CopyBlock
filipnavara Mar 8, 2024
7b664a1
Add support for P/Invoke resolution with mangled stdcall signatures
filipnavara Mar 8, 2024
1a0e399
Fix build.
filipnavara Mar 8, 2024
610d40c
Move SignatureBytes into Flags in MethodFixupCell
filipnavara Mar 9, 2024
cf69135
Attempt to remove the non-sense key in PInvokeLazyFixupFieldHashtable
filipnavara Mar 9, 2024
392cce9
Cleanup the math helpers not to depend on CRT internals
filipnavara Mar 9, 2024
1736ccf
RhCpuIdEx is FCall, fix the import declaration
filipnavara Mar 9, 2024
8638f55
Make sure that thunk allocation functions can be resolved by the linker
filipnavara Mar 9, 2024
e5a4ca7
RhEnumerateConfigurationValues was incorrectly marked as FCall
filipnavara Mar 9, 2024
514bee1
Fix Mac/iOS/tvOS build
filipnavara Mar 9, 2024
1bf01b2
Add FCIMPL1_D/FCIMPL2_FF/FCIMPL2_DD macros and mark RhpDbl2ULng/RhpFl…
filipnavara Mar 9, 2024
8ac691d
x86: Use FCalls for CRT math
filipnavara Mar 9, 2024
d6ca24f
s/REDHAWK_CALLCONV/F_CALL_CONV/g
filipnavara Mar 9, 2024
e168e24
Make RhCpuIdEx a QCall
filipnavara Mar 9, 2024
44168a2
PR feedback: Move SignatureBytes computation and fix up Equals/CompareTo
filipnavara Mar 9, 2024
a0e279f
Use existing C helpers for Int/UInt/Long to Double conversions
filipnavara Mar 9, 2024
880d97f
Update comment
filipnavara Mar 9, 2024
37816ae
Apply suggestions from code review
filipnavara Mar 9, 2024
a8d355e
Apply suggestions from code review
filipnavara Mar 9, 2024
30aae4b
Copy CoreCLR version of LMul.
filipnavara Mar 10, 2024
543a4c8
Use consistent syntax
filipnavara Mar 10, 2024
b8c9ae0
Fix issue compiling some runtime tests for interop marshallers where …
filipnavara Mar 10, 2024
03efa07
Update src/tests/nativeaot/SmokeTests/ControlFlowGuard/ControlFlowGua…
filipnavara Mar 11, 2024
9dd4866
Use PInvokeLazyFixupFieldKey to pass NativeSignature
filipnavara Mar 11, 2024
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
4 changes: 3 additions & 1 deletion eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@

<PropertyGroup>
<!-- CLR NativeAot only builds in a subset of the matrix -->
<NativeAotSupported Condition="('$(TargetOS)' == 'windows' or '$(TargetOS)' == 'linux' or '$(TargetOS)' == 'osx' or '$(TargetOS)' == 'maccatalyst' or '$(TargetOS)' == 'iossimulator' or '$(TargetOS)' == 'ios' or '$(TargetOS)' == 'tvossimulator' or '$(TargetOS)' == 'tvos' or '$(TargetOS)' == 'freebsd') and ('$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'arm64' or '$(TargetArchitecture)' == 'arm')">true</NativeAotSupported>
<_NativeAotSupportedOS Condition="'$(TargetOS)' == 'windows' or '$(TargetOS)' == 'linux' or '$(TargetOS)' == 'osx' or '$(TargetOS)' == 'maccatalyst' or '$(TargetOS)' == 'iossimulator' or '$(TargetOS)' == 'ios' or '$(TargetOS)' == 'tvossimulator' or '$(TargetOS)' == 'tvos' or '$(TargetOS)' == 'freebsd'">true</_NativeAotSupportedOS>
Copy link
Copy Markdown
Member

@am11 am11 Mar 7, 2024

Choose a reason for hiding this comment

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

Looks like we can invert it NativeAotUnsupportedOS; that set seems to be getting smaller. 😅

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I would love to do that eventually;)

Copy link
Copy Markdown
Member Author

@filipnavara filipnavara Mar 8, 2024

Choose a reason for hiding this comment

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

Seems like the unsupported OSes are tizen, wasi, and browser. Not sure of the status for haiku, illumos, solaris and netbsd which happen to have some build system support.

Unsupported archs are RV64, LA64, PowerPC (supported by Mono), WASM, and linux-x86. We may be able to shrink this list before .NET 9 ships.

Copy link
Copy Markdown
Member

@am11 am11 Mar 10, 2024

Choose a reason for hiding this comment

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

Yup, something like:

<NativeAotUnsupportedOS Condition="$([MSBuild]::ValueOrDefault(',browser,haiku,illumos,netbsd,tizen,wasi,', '').Contains(',$(TargetOS),'))">true</NativeAotUnsupportedOS>

usage: Condition="'$(NativeAotUnsupportedOS)' != 'true'"

Unsupported archs are RV64, LA64, PowerPC (supported by Mono), WASM, and linux-x86

and s390x.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FWIW, this only needs to create a subset of what can already build with CoreCLR but does not build for native AOT (so that we don't break ./build.sh clr for a platform that already works otherwise).

I don't think browser/wasi/powerpc/s390 builds with CoreCLR, so we don't mind if native AOT makes ./build.sh clr more broken. If someone brings up a new platform and wants native AOT out of the way, they can exclude it, same way they can exclude anything else they don't (yet) want as part of bringup.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think browser/wasi/powerpc/s390 builds with CoreCLR,

Given we have to ensure that clr.iltools and clr.packages remain intact:

buildArgs: -s mono+libs+host+packs+libs.tests+clr.iltools+clr.packages -c $(_BuildConfig) /p:ArchiveTests=true

we might as well just list the 'not yet supported' ones without classifying them further.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Given we have to ensure that clr.iltools and clr.packages remain intact:

Clr.iltools "just works" because clr.iltools doesn't include coreclr VM and doesn't include any native AOT parts either, same for clr.packages.

Does building the clr subset (the entire clr subset, not just ilasm/dasm) work on s390 today? If not, I don't see why we'd need an extra exclusion for the native aot part. We shouldn't need to add extra exclusions (that are specific to native AOT) every time someone adds an obscure platform for mono. We either skip the entire clr build (i.e. we do the thing where build is skipped for all of coreclr, not just native AOT - except for iltools), or let it do whatever it does (break, probably). I think the latter is fine because that's how it is today.

<_NativeAotSupportedArch Condition="'$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'arm64' or '$(TargetArchitecture)' == 'arm' or ('$(TargetOS)' == 'windows' and '$(TargetArchitecture)' == 'x86')">true</_NativeAotSupportedArch>
<NativeAotSupported Condition="'$(_NativeAotSupportedOS)' == 'true' and $(_NativeAotSupportedArch) == 'true'">true</NativeAotSupported>

<!-- If we're building clr.nativeaotlibs and not building the CLR runtime, compile libraries against NativeAOT CoreLib -->
<UseNativeAotCoreLib Condition="'$(TestNativeAot)' == 'true' or ($(_subset.Contains('+clr.nativeaotlibs+')) and !$(_subset.Contains('+clr.native+')) and !$(_subset.Contains('+clr.runtime+')))">true</UseNativeAotCoreLib>
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,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_ARCH_ARM64 OR CLR_CMAKE_HOST_ARCH_AMD64 OR CLR_CMAKE_HOST_ARCH_ARM)
if(CLR_CMAKE_HOST_ARCH_ARM64 OR CLR_CMAKE_HOST_ARCH_AMD64 OR CLR_CMAKE_HOST_ARCH_ARM OR (CLR_CMAKE_HOST_ARCH_I386 AND CLR_CMAKE_HOST_WIN32))
add_subdirectory(nativeaot)
endif()
endif(NOT CLR_CROSS_COMPONENTS_BUILD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,15 @@ public static void CopyBlock(void* destination, void* source, uint byteCount)
{
throw new PlatformNotSupportedException();
}

/// <summary>
/// Copies bytes from the source address to the destination address.
/// </summary>
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void CopyBlock(ref byte destination, ref readonly byte source, uint byteCount)
{
throw new PlatformNotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ internal static int RhEndNoGCRegion()
[RuntimeImport(Redhawk.BaseName, "RhpGcSafeZeroMemory")]
internal static extern unsafe ref byte RhpGcSafeZeroMemory(ref byte dmem, nuint size);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
[RuntimeImport(Redhawk.BaseName, "memmove")]
internal static extern unsafe void* memmove(byte* dmem, byte* smem, nuint size);

[MethodImplAttribute(MethodImplOptions.InternalCall)]
[RuntimeImport(Redhawk.BaseName, "RhBulkMoveWithWriteBarrier")]
internal static extern unsafe void RhBulkMoveWithWriteBarrier(ref byte dmem, ref byte smem, nuint size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ public static unsafe object RhBox(MethodTable* pEEType, ref byte data)
}
else
{
fixed (byte* pFields = &result.GetRawData())
fixed (byte* pData = &dataAdjustedForNullable)
InternalCalls.memmove(pFields, pData, pEEType->ValueTypeSize);
Unsafe.CopyBlock(ref result.GetRawData(), ref dataAdjustedForNullable, pEEType->ValueTypeSize);
}

return result;
Expand Down Expand Up @@ -271,9 +269,7 @@ public static unsafe void RhUnbox(object? obj, ref byte data, MethodTable* pUnbo
else
{
// Copy the boxed fields into the new location.
fixed (byte *pData = &data)
fixed (byte* pFields = &fields)
InternalCalls.memmove(pData, pFields, pEEType->ValueTypeSize);
Unsafe.CopyBlock(ref data, ref fields, pEEType->ValueTypeSize);
}
}

Expand Down
68 changes: 65 additions & 3 deletions src/coreclr/nativeaot/Runtime/CommonMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define STDCALL
#endif

#define REDHAWK_CALLCONV FASTCALL
#define F_CALL_CONV FASTCALL
#define QCALLTYPE

#ifdef _MSC_VER
Expand Down Expand Up @@ -219,6 +219,42 @@ typedef uint8_t CODE_LOCATION;
_Pragma(FCALL_XSTRINGIFY(comment (linker, FCALL_DECL_ALTNAME(FCALL_METHOD_NAME_((__VA_ARGS__)), FCALL_ARGHELPER_STACKSIZE(__VA_ARGS__)))))
#define FCIMPL_RENAME(_rettype, ...) \
_Pragma(FCALL_XSTRINGIFY(comment (linker, FCALL_IMPL_ALTNAME(FCALL_METHOD_NAME_((__VA_ARGS__)), FCALL_ARGHELPER_STACKSIZE(__VA_ARGS__)))))
#define FCIMPL_RENAME_ARGSIZE(_rettype, _method, _argSize) \
_Pragma(FCALL_XSTRINGIFY(comment (linker, FCALL_XSTRINGIFY(/alternatename:_method=@_method##_FCall@_argSize))))

#define FCIMPL1_F(_rettype, _method, a) \
FCIMPL_RENAME_ARGSIZE(_rettype, _method, 4) \
EXTERN_C _rettype F_CALL_CONV _method##_FCall (a) \
{
#define FCIMPL1_D(_rettype, _method, a) \
FCIMPL_RENAME_ARGSIZE(_rettype, _method, 8) \
EXTERN_C _rettype F_CALL_CONV _method##_FCall (a) \
{
#define FCIMPL1_L FCIMPL1_D
#define FCIMPL2_FF(_rettype, _method, a, b) \
FCIMPL_RENAME_ARGSIZE(_rettype, _method, 8) \
EXTERN_C _rettype F_CALL_CONV _method##_FCall (b, a) \
{
#define FCIMPL2_DD(_rettype, _method, a, b) \
FCIMPL_RENAME_ARGSIZE(_rettype, _method, 16) \
EXTERN_C _rettype F_CALL_CONV _method##_FCall (b, a) \
{
#define FCIMPL2_FI(_rettype, _method, a, b) \
FCIMPL_RENAME_ARGSIZE(_rettype, _method, 8) \
EXTERN_C _rettype F_CALL_CONV _method##_FCall (a, b) \
{
#define FCIMPL2_DI(_rettype, _method, a, b) \
FCIMPL_RENAME_ARGSIZE(_rettype, _method, 12) \
EXTERN_C _rettype F_CALL_CONV _method##_FCall (a, b) \
{
#define FCIMPL3_FFF(_rettype, _method, a, b, c) \
FCIMPL_RENAME_ARGSIZE(_rettype, _method, 12) \
EXTERN_C _rettype F_CALL_CONV _method##_FCall (c, b, a) \
{
#define FCIMPL3_DDD(_rettype, _method, a, b, c) \
FCIMPL_RENAME_ARGSIZE(_rettype, _method, 24) \
EXTERN_C _rettype F_CALL_CONV _method##_FCall (c, b, a) \
{

#else

Expand All @@ -228,11 +264,37 @@ typedef uint8_t CODE_LOCATION;
#define FCALL_METHOD_ARGS(dummy, ...) (__VA_ARGS__)
#define FCALL_METHOD_ARGS_(tuple) FCALL_METHOD_ARGS tuple

#define FCIMPL1_F(_rettype, _method, a) \
EXTERN_C _rettype F_CALL_CONV _method (a) \
{
#define FCIMPL1_D(_rettype, _method, a) \
EXTERN_C _rettype F_CALL_CONV _method (a) \
{
#define FCIMPL1_L FCIMPL1_D
#define FCIMPL2_FF(_rettype, _method, a, b) \
EXTERN_C _rettype F_CALL_CONV _method (a, b) \
{
#define FCIMPL2_DD(_rettype, _method, a, b) \
EXTERN_C _rettype F_CALL_CONV _method (a, b) \
{
#define FCIMPL2_FI(_rettype, _method, a, b) \
EXTERN_C _rettype F_CALL_CONV _method (a, b) \
{
#define FCIMPL2_DI(_rettype, _method, a, b) \
EXTERN_C _rettype F_CALL_CONV _method (a, b) \
{
#define FCIMPL3_FFF(_rettype, _method, a, b, c) \
EXTERN_C _rettype F_CALL_CONV _method (a, b, c) \
{
#define FCIMPL3_DDD(_rettype, _method, a, b, c) \
EXTERN_C _rettype F_CALL_CONV _method (a, b, c) \
{

#endif

#define FCDECL_(_rettype, ...) \
FCDECL_RENAME(_rettype, __VA_ARGS__) \
EXTERN_C _rettype REDHAWK_CALLCONV FCALL_METHOD_NAME_((__VA_ARGS__)) FCALL_METHOD_ARGS_((__VA_ARGS__))
EXTERN_C _rettype F_CALL_CONV FCALL_METHOD_NAME_((__VA_ARGS__)) FCALL_METHOD_ARGS_((__VA_ARGS__))
#define FCDECL0(_rettype, _method) FCDECL_(_rettype, _method)
#define FCDECL1(_rettype, _method, a) FCDECL_(_rettype, _method, a)
#define FCDECL2(_rettype, _method, a, b) FCDECL_(_rettype, _method, a, b)
Expand All @@ -242,7 +304,7 @@ typedef uint8_t CODE_LOCATION;

#define FCIMPL_(_rettype, ...) \
FCIMPL_RENAME(_rettype, __VA_ARGS__) \
EXTERN_C _rettype REDHAWK_CALLCONV FCALL_METHOD_NAME_((__VA_ARGS__)) FCALL_METHOD_ARGS_((__VA_ARGS__)) \
EXTERN_C _rettype F_CALL_CONV FCALL_METHOD_NAME_((__VA_ARGS__)) FCALL_METHOD_ARGS_((__VA_ARGS__)) \
{
#define FCIMPL0(_rettype, _method) FCIMPL_(_rettype, _method)
#define FCIMPL1(_rettype, _method, a) FCIMPL_(_rettype, _method, a)
Expand Down
34 changes: 34 additions & 0 deletions src/coreclr/nativeaot/Runtime/EHHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,23 @@ EXTERN_C void* RhpRethrow2 = NULL;
#endif

EXTERN_C CODE_LOCATION RhpAssignRefAVLocation;
#if defined(HOST_X86)
EXTERN_C CODE_LOCATION RhpAssignRefEAXAVLocation;
EXTERN_C CODE_LOCATION RhpAssignRefECXAVLocation;
EXTERN_C CODE_LOCATION RhpAssignRefEBXAVLocation;
EXTERN_C CODE_LOCATION RhpAssignRefESIAVLocation;
EXTERN_C CODE_LOCATION RhpAssignRefEDIAVLocation;
EXTERN_C CODE_LOCATION RhpAssignRefEBPAVLocation;
#endif
EXTERN_C CODE_LOCATION RhpCheckedAssignRefAVLocation;
#if defined(HOST_X86)
EXTERN_C CODE_LOCATION RhpCheckedAssignRefEAXAVLocation;
EXTERN_C CODE_LOCATION RhpCheckedAssignRefECXAVLocation;
EXTERN_C CODE_LOCATION RhpCheckedAssignRefEBXAVLocation;
EXTERN_C CODE_LOCATION RhpCheckedAssignRefESIAVLocation;
EXTERN_C CODE_LOCATION RhpCheckedAssignRefEDIAVLocation;
EXTERN_C CODE_LOCATION RhpCheckedAssignRefEBPAVLocation;
#endif
EXTERN_C CODE_LOCATION RhpCheckedLockCmpXchgAVLocation;
EXTERN_C CODE_LOCATION RhpCheckedXchgAVLocation;
#if !defined(HOST_AMD64) && !defined(HOST_ARM64)
Expand All @@ -335,13 +351,31 @@ static bool InWriteBarrierHelper(uintptr_t faultingIP)
static uintptr_t writeBarrierAVLocations[] =
{
(uintptr_t)&RhpAssignRefAVLocation,
#if defined(HOST_X86)
(uintptr_t)&RhpAssignRefEAXAVLocation,
(uintptr_t)&RhpAssignRefECXAVLocation,
(uintptr_t)&RhpAssignRefEBXAVLocation,
(uintptr_t)&RhpAssignRefESIAVLocation,
(uintptr_t)&RhpAssignRefEDIAVLocation,
(uintptr_t)&RhpAssignRefEBPAVLocation,
#endif
(uintptr_t)&RhpCheckedAssignRefAVLocation,
#if defined(HOST_X86)
(uintptr_t)&RhpCheckedAssignRefEAXAVLocation,
(uintptr_t)&RhpCheckedAssignRefECXAVLocation,
(uintptr_t)&RhpCheckedAssignRefEBXAVLocation,
(uintptr_t)&RhpCheckedAssignRefESIAVLocation,
(uintptr_t)&RhpCheckedAssignRefEDIAVLocation,
(uintptr_t)&RhpCheckedAssignRefEBPAVLocation,
#endif
(uintptr_t)&RhpCheckedLockCmpXchgAVLocation,
(uintptr_t)&RhpCheckedXchgAVLocation,
#if !defined(HOST_AMD64) && !defined(HOST_ARM64)
#if !defined(HOST_X86)
(uintptr_t)&RhpLockCmpXchg8AVLocation,
(uintptr_t)&RhpLockCmpXchg16AVLocation,
(uintptr_t)&RhpLockCmpXchg32AVLocation,
#endif
(uintptr_t)&RhpLockCmpXchg64AVLocation,
#endif
(uintptr_t)&RhpByRefAssignRefAVLocation1,
Expand Down
7 changes: 3 additions & 4 deletions src/coreclr/nativeaot/Runtime/GCHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,11 @@ FCIMPL0(int64_t, RhGetTotalAllocatedBytes)
}
FCIMPLEND

FCIMPL2(void, RhEnumerateConfigurationValues, void* configurationContext, ConfigurationValueFunc callback)
EXTERN_C void QCALLTYPE RhEnumerateConfigurationValues(void* configurationContext, ConfigurationValueFunc callback)
{
IGCHeap* pHeap = GCHeapUtilities::GetGCHeap();
pHeap->EnumerateConfigurationValues(configurationContext, callback);
}
FCIMPLEND

GCHeapHardLimitInfo g_gcHeapHardLimitInfo;
bool g_gcHeapHardLimitInfoSpecified = false;
Expand Down Expand Up @@ -563,7 +562,7 @@ static Object* GcAllocInternal(MethodTable* pEEType, uint32_t uFlags, uintptr_t
// numElements - number of array elements
// pTransitionFrame- transition frame to make stack crawlable
// Returns a pointer to the object allocated or NULL on failure.
EXTERN_C void* REDHAWK_CALLCONV RhpGcAlloc(MethodTable* pEEType, uint32_t uFlags, uintptr_t numElements, PInvokeTransitionFrame* pTransitionFrame)
EXTERN_C void* F_CALL_CONV RhpGcAlloc(MethodTable* pEEType, uint32_t uFlags, uintptr_t numElements, PInvokeTransitionFrame* pTransitionFrame)
{
Thread* pThread = ThreadStore::GetCurrentThread();

Expand Down Expand Up @@ -702,7 +701,7 @@ EXTERN_C UInt32_BOOL g_fGcStressStarted;
UInt32_BOOL g_fGcStressStarted = UInt32_FALSE; // UInt32_BOOL because asm code reads it

// static
EXTERN_C void REDHAWK_CALLCONV RhpStressGc()
EXTERN_C void F_CALL_CONV RhpStressGc()
{
// The GarbageCollect operation below may trash the last win32 error. We save the error here so that it can be
// restored after the GC operation;
Expand Down
Loading