Skip to content

Commit

Permalink
Make libraries build with Native AOT corelib (dotnet#70)
Browse files Browse the repository at this point in the history
Also fixes ApiCompat violations in the process.
  • Loading branch information
MichalStrehovsky authored Aug 28, 2020
1 parent 1ac46af commit 3c109fb
Show file tree
Hide file tree
Showing 36 changed files with 434 additions and 77 deletions.
6 changes: 6 additions & 0 deletions eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
<RuntimeFlavor Condition="'$(RuntimeFlavor)' == ''">CoreCLR</RuntimeFlavor>
</PropertyGroup>

<PropertyGroup>
<!-- We always build the NativeAOT variant out of the NativeAOT branch -->
<!-- In the future, this can be exposed as a runtimeVariant, same as Mono's LLVMJIT or LLVMAOT-->
<ClrNativeAot Condition="'$(BuildAllConfigurations)' != 'true'">true</ClrNativeAot>
</PropertyGroup>

<PropertyGroup>
<DefaultCoreClrSubsets>clr.runtime+linuxdac+clr.corelib+clr.nativecorelib+clr.tools+clr.packages</DefaultCoreClrSubsets>

Expand Down
2 changes: 1 addition & 1 deletion eng/pipelines/runtimelab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
jobParameters:
testGroup: innerloop
nameSuffix: All_Configurations
buildArgs: -s libs -c $(_BuildConfig) -allConfigurations
buildArgs: -s clr.runtime+libs -c $(_BuildConfig) -allConfigurations

#
# CoreCLR Test builds using live libraries release build
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/dir.common.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<Platform Condition="'$(Platform)' == ''">$(TargetArchitecture)</Platform>

<PlatformConfigPathPart>$(TargetOS).$(TargetArchitecture).$(Configuration)</PlatformConfigPathPart>
<PlatformConfigPathPart>$(TargetOS).$(TargetArchitecture).$(CoreCLRConfiguration)</PlatformConfigPathPart>
</PropertyGroup>

<!-- Common properties -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
</ItemGroup>

<PropertyGroup>
<DefineConstants>SYSTEM_PRIVATE_CORELIB;$(DefineConstants)</DefineConstants>
<DefineConstants>SYSTEM_PRIVATE_CORELIB;FEATURE_MANAGED_ETW_CHANNELS;FEATURE_MANAGED_ETW;$(DefineConstants)</DefineConstants>
<TargetsCoreRT>true</TargetsCoreRT>
<UseSyncTable>true</UseSyncTable>
</PropertyGroup>

<PropertyGroup>
<DefineConstants Condition="'$(UseSyncTable)' == 'true'">FEATURE_SYNCTABLE;$(DefineConstants)</DefineConstants>
<DefineConstants Condition="'$(TargetsWindows)'=='true'">FEATURE_MANAGED_ETW_CHANNELS;FEATURE_MANAGED_ETW;$(DefineConstants)</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<FeatureCominterop>false</FeatureCominterop>
Expand Down Expand Up @@ -157,9 +156,11 @@
<Compile Include="src\System\Reflection\FieldInfo.CoreRT.cs" />
<Compile Include="src\System\Reflection\LegacyCustomAttributeApis.cs" />
<Compile Include="src\System\Reflection\MethodBase.CoreRT.cs" />
<Compile Include="src\System\Reflection\Metadata\AssemblyExtensions.cs" />
<Compile Include="src\System\Runtime\InteropServices\CriticalHandle.CoreRT.cs" />
<Compile Include="src\System\Activator.CoreRT.cs" />
<Compile Include="src\System\AppContext.CoreRT.cs" />
<Compile Include="src\System\ArgIterator.cs" />
<Compile Include="src\System\Buffer.CoreRT.cs" />
<Compile Include="src\System\Collections\Generic\ArraySortHelper.CoreRT.cs" />
<Compile Include="src\System\Collections\Generic\Comparer.CoreRT.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;

namespace System
{
[StructLayout(LayoutKind.Sequential)]
public ref struct ArgIterator
{
public ArgIterator(RuntimeArgumentHandle arglist)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator);
}

[CLSCompliant(false)]
public unsafe ArgIterator(RuntimeArgumentHandle arglist, void* ptr)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator);
}

public void End()
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator);
}

public override bool Equals(object? o)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator);
}

public override int GetHashCode()
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator);
}

[CLSCompliant(false)]
public System.TypedReference GetNextArg()
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator);
}

[CLSCompliant(false)]
public System.TypedReference GetNextArg(System.RuntimeTypeHandle rth)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator);
}

public unsafe System.RuntimeTypeHandle GetNextArgType()
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator);
}

public int GetRemainingCount()
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public override int GetHashCode()
//
// This non-contract method is known to the IL transformer. See comments around _ILT_ReadFields() for more detail.
//
[CLSCompliant(false)]
protected virtual int _ILT_GetNumFields()
private protected virtual int _ILT_GetNumFields()
{
return 0;
}
Expand All @@ -78,8 +77,7 @@ protected virtual int _ILT_GetNumFields()
// base class to get any inherited fields. To simplify the IL generation, the generated method only writes the results into a specified
// offset inside a caller-supplied array. Attribute.ReadFields() calls _ILT_GetNumFields() to figure out how large an array is needed.
//
[CLSCompliant(false)]
protected virtual void _ILT_ReadFields(object[] destination, int offset)
private protected virtual void _ILT_ReadFields(object[] destination, int offset)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Internal.Reflection.Augments;
using Internal.Runtime.Augments;
using Internal.Runtime.CompilerServices;
Expand Down Expand Up @@ -44,29 +45,29 @@ protected Delegate(Type target, string method)

// New Delegate Implementation

protected internal object m_firstParameter;
protected internal object m_helperObject;
internal object m_firstParameter;
internal object m_helperObject;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
protected internal IntPtr m_extraFunctionPointerOrData;
internal IntPtr m_extraFunctionPointerOrData;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2111:PointersShouldNotBeVisible")]
protected internal IntPtr m_functionPointer;
internal IntPtr m_functionPointer;

[ThreadStatic]
protected static string s_DefaultValueString;
private static string s_DefaultValueString;

// WARNING: These constants are also declared in System.Private.TypeLoader\Internal\Runtime\TypeLoader\CallConverterThunk.cs
// Do not change their values without updating the values in the calling convention converter component
protected const int MulticastThunk = 0;
protected const int ClosedStaticThunk = 1;
protected const int OpenStaticThunk = 2;
protected const int ClosedInstanceThunkOverGenericMethod = 3; // This may not exist
protected const int DelegateInvokeThunk = 4;
protected const int OpenInstanceThunk = 5; // This may not exist
protected const int ObjectArrayThunk = 6; // This may not exist
private protected const int MulticastThunk = 0;
private protected const int ClosedStaticThunk = 1;
private protected const int OpenStaticThunk = 2;
private protected const int ClosedInstanceThunkOverGenericMethod = 3; // This may not exist
private protected const int DelegateInvokeThunk = 4;
private protected const int OpenInstanceThunk = 5; // This may not exist
private protected const int ObjectArrayThunk = 6; // This may not exist

//
// If the thunk does not exist, the function will return IntPtr.Zero.
protected virtual IntPtr GetThunk(int whichThunk)
private protected virtual IntPtr GetThunk(int whichThunk)
{
#if PROJECTN
// The GetThunk function should be overriden on all delegate types, except for universal
Expand All @@ -87,7 +88,7 @@ protected virtual IntPtr GetThunk(int whichThunk)
//
// If there is a default value string, the overridden function should set the
// s_DefaultValueString field and return true.
protected virtual bool LoadDefaultValueString() { return false; }
private protected virtual bool LoadDefaultValueString() { return false; }

/// <summary>
/// Used by various parts of the runtime as a replacement for Delegate.Method
Expand Down Expand Up @@ -147,7 +148,7 @@ unsafe internal IntPtr GetFunctionPointer(out RuntimeTypeHandle typeOfFirstParam
}

// This function is known to the IL Transformer.
protected void InitializeClosedInstance(object firstParameter, IntPtr functionPointer)
private void InitializeClosedInstance(object firstParameter, IntPtr functionPointer)
{
if (firstParameter == null)
throw new ArgumentException(SR.Arg_DlgtNullInst);
Expand All @@ -157,7 +158,7 @@ protected void InitializeClosedInstance(object firstParameter, IntPtr functionPo
}

// This function is known to the IL Transformer.
protected void InitializeClosedInstanceSlow(object firstParameter, IntPtr functionPointer)
private void InitializeClosedInstanceSlow(object firstParameter, IntPtr functionPointer)
{
// This method is like InitializeClosedInstance, but it handles ALL cases. In particular, it handles generic method with fun function pointers.

Expand All @@ -179,7 +180,7 @@ protected void InitializeClosedInstanceSlow(object firstParameter, IntPtr functi
}

// This function is known to the compiler.
protected void InitializeClosedInstanceWithGVMResolution(object firstParameter, RuntimeMethodHandle tokenOfGenericVirtualMethod)
private void InitializeClosedInstanceWithGVMResolution(object firstParameter, RuntimeMethodHandle tokenOfGenericVirtualMethod)
{
if (firstParameter == null)
throw new ArgumentException(SR.Arg_DlgtNullInst);
Expand Down Expand Up @@ -235,7 +236,7 @@ private void InitializeClosedInstanceWithoutNullCheck(object firstParameter, Int
}

// This function is known to the compiler backend.
protected void InitializeClosedStaticThunk(object firstParameter, IntPtr functionPointer, IntPtr functionPointerThunk)
private void InitializeClosedStaticThunk(object firstParameter, IntPtr functionPointer, IntPtr functionPointerThunk)
{
m_extraFunctionPointerOrData = functionPointer;
m_helperObject = firstParameter;
Expand All @@ -244,15 +245,15 @@ protected void InitializeClosedStaticThunk(object firstParameter, IntPtr functio
}

// This function is known to the compiler backend.
protected void InitializeOpenStaticThunk(object firstParameter, IntPtr functionPointer, IntPtr functionPointerThunk)
private void InitializeOpenStaticThunk(object firstParameter, IntPtr functionPointer, IntPtr functionPointerThunk)
{
// This sort of delegate is invoked by calling the thunk function pointer with the arguments to the delegate + a reference to the delegate object itself.
m_firstParameter = this;
m_functionPointer = functionPointerThunk;
m_extraFunctionPointerOrData = functionPointer;
}

protected void InitializeOpenInstanceThunkDynamic(IntPtr functionPointer, IntPtr functionPointerThunk)
private void InitializeOpenInstanceThunkDynamic(IntPtr functionPointer, IntPtr functionPointerThunk)
{
// This sort of delegate is invoked by calling the thunk function pointer with the arguments to the delegate + a reference to the delegate object itself.
m_firstParameter = this;
Expand All @@ -270,7 +271,7 @@ internal void SetClosedStaticFirstParameter(object firstParameter)
// This function is only ever called by the open instance method thunk, and in that case,
// m_extraFunctionPointerOrData always points to an OpenMethodResolver
[MethodImpl(MethodImplOptions.NoInlining)]
protected IntPtr GetActualTargetFunctionPointer(object thisObject)
private IntPtr GetActualTargetFunctionPointer(object thisObject)
{
return OpenMethodResolver.ResolveMethod(m_extraFunctionPointerOrData, thisObject);
}
Expand Down Expand Up @@ -649,9 +650,11 @@ public object Target
public static Delegate CreateDelegate(Type type, MethodInfo method, bool throwOnBindFailure) => ReflectionAugments.ReflectionCoreCallbacks.CreateDelegate(type, method, throwOnBindFailure);

// V1 api: Creates closed delegates to instance methods only, relaxed signature checking disallowed.
[RequiresUnreferencedCode("The target method might be removed")]
public static Delegate CreateDelegate(Type type, object target, string method, bool ignoreCase, bool throwOnBindFailure) => ReflectionAugments.ReflectionCoreCallbacks.CreateDelegate(type, target, method, ignoreCase, throwOnBindFailure);

// V1 api: Creates open delegates to static methods only, relaxed signature checking disallowed.
[RequiresUnreferencedCode("The target method might be removed")]
public static Delegate CreateDelegate(Type type, Type target, string method, bool ignoreCase, bool throwOnBindFailure) => ReflectionAugments.ReflectionCoreCallbacks.CreateDelegate(type, target, method, ignoreCase, throwOnBindFailure);

internal bool IsOpenStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ private static EnumInfo GetEnumInfo(Type enumType)
return ReflectionAugments.ReflectionCoreCallbacks.GetEnumInfo(enumType);
}

public static bool IsDefined<TEnum>(TEnum value) where TEnum : struct, Enum
{
ulong[] ulValues = GetEnumInfo(typeof(TEnum)).Values;
ulong ulValue = Enum.ToUInt64(value);

return Array.BinarySearch(ulValues, ulValue) >= 0;
}

private static Type ValidateRuntimeType(Type enumType)
{
if (enumType == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -144,6 +145,7 @@ unsafe bool ParseEntry(IntPtr current, out string key, out string value)
}
}

[DoesNotReturn]
private static void ExitRaw() => Interop.Sys.Exit(s_latchedExitCode);

public static long TickCount64 => (long)Interop.Sys.GetTickCount64();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;

namespace System
{
public static partial class Environment
{
[DoesNotReturn]
private static void ExitRaw() => Interop.Kernel32.ExitProcess(s_latchedExitCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.Contracts;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Threading;
using Internal.DeveloperExperience;
Expand All @@ -21,6 +22,7 @@ public static int ExitCode
set => s_latchedExitCode = value;
}

[DoesNotReturn]
public static void Exit(int exitCode)
{
s_latchedExitCode = exitCode;
Expand All @@ -32,9 +34,11 @@ public static void Exit(int exitCode)
// Note: The CLR's Watson bucketization code looks at the caller of the FCALL method
// to assign blame for crashes. Don't mess with this, such as by making it call
// another managed helper method, unless you consult with some CLR Watson experts.
[DoesNotReturn]
public static void FailFast(string message) =>
RuntimeExceptionHelpers.FailFast(message);

[DoesNotReturn]
public static void FailFast(string message, Exception exception) =>
RuntimeExceptionHelpers.FailFast(message, exception);

Expand Down
Loading

0 comments on commit 3c109fb

Please sign in to comment.