Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions src/coreclr/tools/aot/ILCompiler/ILCompiler.props
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@

<ItemGroup>
<Compile Remove="repro\*" />
<Compile Remove="reproZero\*" />
</ItemGroup>
</Project>
64 changes: 64 additions & 0 deletions src/coreclr/tools/aot/ILCompiler/reproZero/reproZero.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<Project Sdk="Microsoft.NET.Sdk">
<!--
This project builds a runtime-less .NET project that can be compiled with ilcompiler with the generated .rsp
and then linked with native libs to create a very barebones executable. Based off zerosharp. Helpful during
platform bringup, like ongoing wasm work, to be able to perform some validation before a runtime and CoreLib are buildable.
-->
Comment thread
jtschuster marked this conversation as resolved.
<PropertyGroup>
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
<OutputType>Exe</OutputType>
<Platforms>x64;x86;wasm</Platforms>
<PlatformTarget>AnyCPU</PlatformTarget>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<Configurations>Debug;Release;Checked</Configurations>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RunAnalyzers>false</RunAnalyzers>
<NoStdLib>true</NoStdLib>
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
<RuntimeMetadataVersion>v4.0.30319</RuntimeMetadataVersion>
<UseAppHost>false</UseAppHost>
</PropertyGroup>

<!-- Strip every resolved reference so csc compiles zerosharp.cs against no metadata at all. -->
<Target Name="RemoveAllReferences" BeforeTargets="CoreCompile">
<ItemGroup>
<ReferencePathWithRefAssemblies Remove="@(ReferencePathWithRefAssemblies)" />
<ReferencePath Remove="@(ReferencePath)" />
<Reference Remove="@(Reference)" />
</ItemGroup>
</Target>

<Target Name="GenerateReproProjectResponseFile"
AfterTargets="Build"
Condition="'$(BuildingInsideVisualStudio)' != 'true'">

<ItemGroup>
<ReproResponseLines Include="$(OutputPath)$(AssemblyName)$(TargetExt)" />
<ReproResponseLines Include="--targetarch:$(Platform)" />
<ReproResponseLines Include="-o:$(OutputPath)$(AssemblyName).obj" />
<!-- <ReproResponseLines Include="-g" /> -->
<ReproResponseLines Include="-O" Condition="'$(Optimize)' == 'true'" />
<ReproResponseLines Include="--systemmodule:reproZero" />
<ReproResponseLines Include="--dehydrate" />
<ReproResponseLines Include="--stacktracedata:lines" />
<ReproResponseLines Include="--scanreflection" />
<ReproResponseLines Include="--feature:System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization=false" />
<ReproResponseLines Include="--feature:System.Diagnostics.Tracing.EventSource.IsSupported=false" />
<ReproResponseLines Include="--feature:System.Resources.ResourceManager.AllowCustomResourceTypes=false" />
<ReproResponseLines Include="--feature:System.Linq.Expressions.CanEmitObjectArrayDelegate=false" />
<ReproResponseLines Include="--feature:System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeSupported=false" />
<ReproResponseLines Include="--feature:System.Globalization.Invariant=true" />
<ReproResponseLines Include="--feature:System.Diagnostics.Debugger.IsSupported=false" />
<ReproResponseLines Include="--feature:System.StartupHookProvider.IsSupported=false" />
</ItemGroup>

<WriteLinesToFile File="$(OutputPath)compile-with-$(LibrariesConfiguration)-libs.rsp"
Lines="@(ReproResponseLines)"
Overwrite="true"
WriteOnlyWhenDifferent="true" />
</Target>
</Project>
129 changes: 129 additions & 0 deletions src/coreclr/tools/aot/ILCompiler/reproZero/zerosharp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime;
using System.Runtime.InteropServices;

#region A couple very basic things
namespace System
{
public class Object
{
#pragma warning disable 169
// The layout of object is a contract with the compiler.
private IntPtr m_pMethodTable;
#pragma warning restore 169
}
public struct Void { }

// The layout of primitive types is special cased because it would be recursive.
// These really don't need any fields to work.
public struct Boolean { }
public struct Char { }
public struct SByte { }
public struct Byte { }
public struct Int16 { }
public struct UInt16 { }
public struct Int32 { }
public struct UInt32 { }
public struct Int64 { }
public struct UInt64 { }
public struct IntPtr { }
public struct UIntPtr { }
public struct Single { }
public struct Double { }

public abstract class ValueType { }
public abstract class Enum : ValueType { }

public struct Nullable<T> where T : struct { }

public sealed class String { public readonly int Length; }
public abstract class Array { }
public abstract class Delegate { }
public abstract class MulticastDelegate : Delegate { }

public struct RuntimeTypeHandle { }
public struct RuntimeMethodHandle { }
public struct RuntimeFieldHandle { }

public class Attribute { }

public enum AttributeTargets { }

public sealed class AttributeUsageAttribute : Attribute
{
public AttributeUsageAttribute(AttributeTargets validOn) { }
public bool AllowMultiple { get; set; }
public bool Inherited { get; set; }
}

public class AppContext
{
public static void SetData(string s, object o) { }
}

namespace Runtime.CompilerServices
{
public class RuntimeHelpers
{
public static unsafe int OffsetToStringData => sizeof(IntPtr) + sizeof(int);
}
}
}
namespace System.Runtime.InteropServices
{
public sealed class DllImportAttribute : Attribute
{
public DllImportAttribute(string dllName) { }
}
}
#endregion

#region Things needed by ILC
namespace System
{
namespace Runtime
{
internal sealed class RuntimeExportAttribute : Attribute
{
public RuntimeExportAttribute(string entry) { }
}
}

class Array<T> : Array { }
}

namespace Internal.Runtime.CompilerHelpers
{
// A class that the compiler looks for that has helpers to initialize the
// process. The compiler can gracefully handle the helpers not being present,
// but the class itself being absent is unhandled. Let's add an empty class.
class StartupCodeHelpers
{
// A couple symbols the generated code will need we park them in this class
// for no particular reason. These aid in transitioning to/from managed code.
// Since we don't have a GC, the transition is a no-op.
[RuntimeExport("RhpReversePInvoke")]
static void RhpReversePInvoke(IntPtr frame) { }
[RuntimeExport("RhpReversePInvokeReturn")]
static void RhpReversePInvokeReturn(IntPtr frame) { }
[RuntimeExport("RhpPInvoke")]
static void RhpPInvoke(IntPtr frame) { }
[RuntimeExport("RhpPInvokeReturn")]
static void RhpPInvokeReturn(IntPtr frame) { }

[RuntimeExport("RhpFallbackFailFast")]
static void RhpFallbackFailFast() { while (true) ; }
}
}
#endregion

unsafe class Program
{
static int Main()
{
return 42;
}
}
Loading