Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Documentation/how-to-build-WebAssembly.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Build WebAssembly on Windows ##

1. Install Emscripten by following the instructions [here](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html).
2. Follow the instructions [here](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html#updating-the-sdk) to update Emscripten to 1.39.8 ```./emsdk install 1.39.8``` followed by ```./emsdk activate 1.39.8```
2. Follow the instructions [here](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html#updating-the-sdk) to update Emscripten to 1.39.19 ```./emsdk install 1.39.19``` followed by ```./emsdk activate 1.39.19```
3. Install [Firefox](https://www.getfirefox.com) (for testing).
3. Get CoreRT set up by following the [Visual Studio instructions](how-to-build-and-run-ilcompiler-in-visual-studio.md).
4. Build the WebAssembly runtime by running ```build.cmd wasm``` from the repo root.
Expand Down
1 change: 1 addition & 0 deletions Documentation/using-corert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ In that area contains list of topics which describe how to use CoreRT on your pr
- [Reflection Free Mode](reflection-free-mode.md)
- [Reflection In AOT](reflection-in-aot-mode.md)
- [Troubleshooting](troubleshooting-corert.md)
- [RD.xml Documentation](rd-xml-format.md)
20 changes: 10 additions & 10 deletions Documentation/using-corert/rd-xml-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ An rd.xml file can be supplemented to help ILCompiler find types that should be

Minimal Rd.xml configuration

```
```xml
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<Assembly Name="mscorlib" />
Expand All @@ -25,7 +25,7 @@ There 3 forms how assembly can be configured
- Module metadata and selected types.

Module metadata only just need simple `<Assembly>` tag with short name of the assembly.
```
```xml
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<Assembly Name="mscorlib" />
Expand All @@ -34,7 +34,7 @@ Module metadata only just need simple `<Assembly>` tag with short name of the as
```

All types in the assembly require adding `Dynamic` attribute with value `Required All`. *NOTE*: This is the only available value for this attribute.
```
```xml
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<Assembly Name="mscorlib" Dynamic="Required All" />
Expand All @@ -45,7 +45,7 @@ Note that if you have generic types in the assembly, then specific instantiation
then you should include these instantiation using nested `<Type>` tag.

Module metadata and selected types option based on module metadata only mode with added `<Type>` tags inside `<Assembly>`.
```
```xml
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<Assembly Name="MonoGame.Framework">
Expand All @@ -61,12 +61,12 @@ Type directive provides a way to specify what types are needed. Developer has tw
- Select which methods should be rooted.

Take all type methods:
```
```xml
<Type Name="Microsoft.Xna.Framework.Content.ListReader`1[[System.Char,mscorlib]]" Dynamic="Required All" />
```

Example how specify typenames
```
```c#
// just int
System.Int32
// string[]
Expand All @@ -83,13 +83,13 @@ System.Collections.Generic.Dictionary`2[[System.Int32,System.Private.CoreLib],[S

Note that it likely does not make sense to have generic type to be placed here, since code generated over specific instantiation of the generic type.
Example of invalid scenario:
```
```c#
// List<T>
System.Collections.Generic.List`1
```

To select which methods should be rooted add nested `<Method>` tags.
```
```xml
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<Assembly Name="System.Private.CoreLib">
Expand All @@ -102,7 +102,7 @@ To select which methods should be rooted add nested `<Method>` tags.
```

Alternatively you can specify optional `<Parameter>` tag, if you want only specific overload. For example:
```
```xml
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<Assembly Name="System.Private.CoreLib">
Expand All @@ -117,7 +117,7 @@ Alternatively you can specify optional `<Parameter>` tag, if you want only speci
```

or if you want instantiate generic method you can pass `<GenericArgument>`.
```
```xml
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<Assembly Name="System.Private.CoreLib">
Expand Down
6 changes: 3 additions & 3 deletions eng/install-emscripten.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ git clone https://github.com/emscripten-core/emsdk.git

cd emsdk
rem checkout a known good version to avoid a random break when emscripten changes the top of tree.
git checkout 92d512f
git checkout dec8a63

powershell -NoProfile -NoLogo -ExecutionPolicy ByPass -command "& """%~dp0update-machine-certs.ps1""" %*"

rem Use the python that is downloaded to native-tools explicitly as its not on the path
call "%1"\..\native-tools\bin\python3 emsdk.py install 1.39.8
call "%1"\..\native-tools\bin\python3 emsdk.py install 1.39.19
if %errorlevel% NEQ 0 goto fail
call emsdk activate 1.39.8
call emsdk activate 1.39.19
if %errorlevel% NEQ 0 goto fail

exit /b 0
Expand Down
29 changes: 25 additions & 4 deletions src/BuildIntegration/Microsoft.NETCore.Native.targets
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ The .NET Foundation licenses this file to you under the MIT license.

<PropertyGroup>
<NativeObjectExt Condition="'$(TargetOS)' == 'Windows_NT'">.obj</NativeObjectExt>
<NativeObjectExt Condition="'$(TargetOS)' != 'Windows_NT'">.o</NativeObjectExt>
<NativeObjectExt Condition="'$(NativeCodeGen)' == 'wasm'">.bc</NativeObjectExt>
<NativeObjectExt Condition="'$(TargetOS)' != 'Windows_NT' or '$(NativeCodeGen)' == 'wasm'">.o</NativeObjectExt>
<LlvmObjectExt Condition="'$(NativeCodeGen)' == 'wasm'">.bc</LlvmObjectExt>

<LibFileExt Condition="'$(TargetOS)' == 'Windows_NT'">.lib</LibFileExt>
<LibFileExt Condition="'$(TargetOS)' != 'Windows_NT'">.a</LibFileExt>
Expand All @@ -61,6 +61,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<ExportsFileExt Condition="'$(TargetOS)' == 'Windows_NT'">.def</ExportsFileExt>
<ExportsFileExt Condition="'$(TargetOS)' != 'Windows_NT'">.exports</ExportsFileExt>

<LlvmObject Condition="'$(NativeCodeGen)' == 'wasm'">$(NativeIntermediateOutputPath)$(TargetName)$(LlvmObjectExt)</LlvmObject>
<NativeObject>$(NativeIntermediateOutputPath)$(TargetName)$(NativeObjectExt)</NativeObject>
<NativeBinary>$(NativeOutputPath)$(TargetName)$(NativeBinaryExt)</NativeBinary>
<ExportsFile Condition="$(NativeLib) == 'Shared' and $(ExportsFile) == ''">$(NativeIntermediateOutputPath)$(TargetName)$(ExportsFileExt)</ExportsFile>
Expand All @@ -70,7 +71,7 @@ The .NET Foundation licenses this file to you under the MIT license.

<LinkNativeDependsOn Condition="$(NativeCodeGen) == ''">IlcCompile</LinkNativeDependsOn>
<LinkNativeDependsOn Condition="$(NativeCodeGen) == 'cpp'">CppCompile</LinkNativeDependsOn>
<LinkNativeDependsOn Condition="$(NativeCodeGen) == 'wasm'">IlcCompile</LinkNativeDependsOn>
<LinkNativeDependsOn Condition="$(NativeCodeGen) == 'wasm'">WasmObject</LinkNativeDependsOn>

<FrameworkLibPath Condition="'$(FrameworkLibPath)' == ''">$(NativeOutputPath)</FrameworkLibPath>
<FrameworkObjPath Condition="'$(FrameworkObjPath)' == ''">$(NativeIntermediateOutputPath)</FrameworkObjPath>
Expand Down Expand Up @@ -275,6 +276,26 @@ The .NET Foundation licenses this file to you under the MIT license.

</Target>

<Target Name="WasmObject"
Inputs="$(LlvmObject)"
Outputs="$(NativeObject)"
DependsOnTargets="IlcCompile;GenerateResFile"
Condition="'$(NativeCodeGen)' == 'wasm'">

<MakeDir Directories="$([System.IO.Path]::GetDirectoryName($(NativeBinary)))" />

<PropertyGroup>
<EmccArgs>&quot;$(LlvmObject)&quot; -c -o &quot;$(NativeObject)&quot; -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s DISABLE_EXCEPTION_CATCHING=0</EmccArgs>
<EmccArgs Condition="'$(Configuration)'=='Release'">$(EmccArgs) -O2</EmccArgs>
<EmccArgs Condition="'$(Configuration)'=='Debug'">$(EmccArgs) -g3</EmccArgs>
</PropertyGroup>

<Exec Command="&quot;$(EMSDK)/upstream/emscripten/emcc.bat&quot; $(EmccArgs)" Condition="'$(EMSDK)' != '' and '$(OS)' == 'Windows_NT'" />
<Exec Command="&quot;$(EMSDK)/upstream/emscripten/emcc&quot; $(EmccArgs)" Condition="'$(EMSDK)' != '' and '$(OS)' != 'Windows_NT'" />
<Message Text="Emscripten not found, not linking WebAssembly. To enable WebAssembly linking, install Emscripten and ensure the EMSDK environment variable points to the directory containing upstream/emscripten/emcc.bat"
Condition="'$(EMSDK)' == ''" />
</Target>

<Target Name="LinkNative"
Inputs="$(NativeObject);@(NativeLibrary)"
Outputs="$(NativeBinary)"
Expand Down Expand Up @@ -312,7 +333,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<Exec Command="$(CppLibCreator) @&quot;$(NativeIntermediateOutputPath)lib.rsp&quot;" Condition="'$(OS)' == 'Windows_NT' and '$(NativeLib)' == 'Static' and '$(NativeCodeGen)' != 'wasm'" />

<PropertyGroup>
<EmccArgs>&quot;$(NativeObject)&quot; -o &quot;$(NativeBinary)&quot; -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s DISABLE_EXCEPTION_CATCHING=0 --emrun </EmccArgs>
<EmccArgs>&quot;$(NativeObject)&quot; -o &quot;$(NativeBinary)&quot; -s ALLOW_MEMORY_GROWTH=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s DISABLE_EXCEPTION_CATCHING=0 --emrun </EmccArgs>
<EmccArgs Condition="'$(Platform)'=='wasm'">$(EmccArgs) &quot;$(IlcPath)/sdk/libPortableRuntime.a&quot; &quot;$(IlcPath)/sdk/libbootstrappercpp.a&quot; &quot;$(IlcPath)/sdk/libSystem.Private.CoreLib.Native.a&quot; $(EmccExtraArgs)</EmccArgs>
<EmccArgs Condition="'$(Configuration)'=='Release'">$(EmccArgs) -O2 -flto</EmccArgs>
<EmccArgs Condition="'$(Configuration)'=='Debug'">$(EmccArgs) -g3</EmccArgs>
Expand Down
4 changes: 2 additions & 2 deletions src/Common/src/TypeSystem/Common/TargetDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ public LayoutInt GetObjectAlignment(LayoutInt fieldAlignment)
switch (Architecture)
{
case TargetArchitecture.ARM:
// ARM supports two alignments for objects on the GC heap (4 byte and 8 byte)
case TargetArchitecture.Wasm32:
// ARM & Wasm32 support two alignments for objects on the GC heap (4 byte and 8 byte)
if (fieldAlignment.IsIndeterminate)
return LayoutInt.Indeterminate;

Expand All @@ -286,7 +287,6 @@ public LayoutInt GetObjectAlignment(LayoutInt fieldAlignment)
case TargetArchitecture.ARM64:
return new LayoutInt(8);
case TargetArchitecture.X86:
case TargetArchitecture.Wasm32:
return new LayoutInt(4);
default:
throw new NotSupportedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)

public int Offset => 0;
protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);
public override ObjectNodeSection Section => ObjectNodeSection.ReadOnlyDataSection;
public override ObjectNodeSection Section
{
get
{
if (_identity.Context.Target.IsWindows)
return ObjectNodeSection.ReadOnlyDataSection;
else
return ObjectNodeSection.DataSection;
}
}
public override bool IsShareable => false;
public override bool StaticDependenciesAreComputed => true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ public void EmitReloc(ISymbolNode symbol, RelocType relocType, int delta = 0)
case RelocType.IMAGE_REL_BASED_THUMB_MOV32:
case RelocType.IMAGE_REL_BASED_ARM64_PAGEBASE_REL21:
case RelocType.IMAGE_REL_BASED_ARM64_PAGEOFFSET_12L:
case RelocType.IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A:
// Do not vacate space for this kind of relocation, because
// the space is embedded in the instruction.
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,8 @@ public void EmitSymbolDefinition(int currentOffset)
{
foreach (var name in nodes)
{


_sb.Clear();
AppendExternCPrefix(_sb);
name.AppendMangledName(_nodeFactory.NameMangler, _sb);
Expand Down Expand Up @@ -1043,7 +1045,7 @@ public static void EmitObject(string objectFilePath, IEnumerable<DependencyNode>
// The DWARF CFI unwind is implemented for AMD64 & ARM32 only.
TargetArchitecture tarch = factory.Target.Architecture;
if (!factory.Target.IsWindows &&
(tarch == TargetArchitecture.X64 || tarch == TargetArchitecture.ARM))
(tarch == TargetArchitecture.X64 || tarch == TargetArchitecture.ARM || tarch == TargetArchitecture.ARM64))
objectWriter.BuildCFIMap(factory, node);

// Build debug location map
Expand Down Expand Up @@ -1089,17 +1091,24 @@ public static void EmitObject(string objectFilePath, IEnumerable<DependencyNode>
}
int size = objectWriter.EmitSymbolReference(reloc.Target, (int)delta, reloc.RelocType);

// Emit a copy of original Thumb2 instruction that came from RyuJIT
if (reloc.RelocType == RelocType.IMAGE_REL_BASED_THUMB_MOV32 ||
reloc.RelocType == RelocType.IMAGE_REL_BASED_THUMB_BRANCH24)
// Emit a copy of original Thumb2/ARM64 instruction that came from RyuJIT

switch (reloc.RelocType)
{
unsafe
{
fixed (void* location = &nodeContents.Data[i])
case RelocType.IMAGE_REL_BASED_THUMB_MOV32:
case RelocType.IMAGE_REL_BASED_THUMB_BRANCH24:
case RelocType.IMAGE_REL_BASED_ARM64_BRANCH26:
case RelocType.IMAGE_REL_BASED_ARM64_PAGEBASE_REL21:
case RelocType.IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A:
case RelocType.IMAGE_REL_BASED_ARM64_PAGEOFFSET_12L:
unsafe
{
objectWriter.EmitBytes((IntPtr)location, size);
fixed (void* location = &nodeContents.Data[i])
{
objectWriter.EmitBytes((IntPtr)location, size);
}
}
}
break;
}

// Update nextRelocIndex/Offset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,45 @@ private static unsafe void PutArm64Rel12(uint* pCode, int imm12)
Debug.Assert(GetArm64Rel12(pCode) == imm12);
}

private static unsafe int GetArm64Rel28(uint* pCode)
{
uint branchInstr = *pCode;

// first shift 6 bits left to set the sign bit,
// then arithmetic shift right by 4 bits
int imm28 = (((int)(branchInstr & 0x03FFFFFF)) << 6) >> 4;

return imm28;
}

private static bool FitsInArm64Rel28(long imm28)
{
return (imm28 >= -0x08000000L) && (imm28 < 0x08000000L);
}

private static unsafe void PutArm64Rel28(uint* pCode, long imm28)
{
// Verify that we got a valid offset
Debug.Assert(FitsInArm64Rel28(imm28));

Debug.Assert((imm28 & 0x3) == 0); // the low two bits must be zero

uint branchInstr = *pCode;

branchInstr &= 0xFC000000; // keep bits 31-26

Debug.Assert((branchInstr & 0x7FFFFFFF) == 0x14000000); // Must be B or BL

// Assemble the pc-relative delta 'imm28' into the branch instruction
branchInstr |= (uint)(((imm28 >> 2) & 0x03FFFFFFU));

*pCode = branchInstr; // write the assembled instruction

Debug.Assert(GetArm64Rel28(pCode) == imm28);
}



public Relocation(RelocType relocType, int offset, ISymbolNode target)
{
RelocType = relocType;
Expand Down Expand Up @@ -286,6 +325,9 @@ public static unsafe void WriteValue(RelocType relocType, void* location, long v
case RelocType.IMAGE_REL_BASED_THUMB_BRANCH24:
PutThumb2BlRel24((ushort*)location, (uint)value);
break;
case RelocType.IMAGE_REL_BASED_ARM64_BRANCH26:
PutArm64Rel28((uint*)location, value);
break;
case RelocType.IMAGE_REL_BASED_ARM64_PAGEBASE_REL21:
PutArm64Rel21((uint*)location, (int)value);
break;
Expand Down Expand Up @@ -318,6 +360,8 @@ public static unsafe long ReadValue(RelocType relocType, void* location)
return (long)GetThumb2Mov32((ushort*)location);
case RelocType.IMAGE_REL_BASED_THUMB_BRANCH24:
return (long)GetThumb2BlRel24((ushort*)location);
case RelocType.IMAGE_REL_BASED_ARM64_BRANCH26:
return (long)GetArm64Rel28((uint*)location);
case RelocType.IMAGE_REL_BASED_ARM64_PAGEBASE_REL21:
return GetArm64Rel21((uint*)location);
case RelocType.IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A:
Expand Down
Loading