Skip to content

Commit

Permalink
Update Architecture to unknown machine (#101038)
Browse files Browse the repository at this point in the history
* Update Architecture to unknown machine

* Update src/tools/illink/src/linker/Linker.Steps/OutputStep.cs

Suggested by @am11. Thank you.

Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>

---------

Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
  • Loading branch information
3 people authored Apr 15, 2024
1 parent 64a937c commit 69062fd
Showing 1 changed file with 1 addition and 31 deletions.
32 changes: 1 addition & 31 deletions src/tools/illink/src/linker/Linker.Steps/OutputStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,13 @@ namespace Mono.Linker.Steps

public class OutputStep : BaseStep
{
private Dictionary<ushort, TargetArchitecture>? architectureMap;

private enum NativeOSOverride
{
Apple = 0x4644,
FreeBSD = 0xadc4,
Linux = 0x7b79,
NetBSD = 0x1993,
Default = 0
}

readonly List<string> assembliesWritten;

public OutputStep ()
{
assembliesWritten = new List<string> ();
}

TargetArchitecture CalculateArchitecture (TargetArchitecture readyToRunArch)
{
if (architectureMap == null) {
architectureMap = new Dictionary<ushort, TargetArchitecture> ();
foreach (var os in Enum.GetValues (typeof (NativeOSOverride))) {
ushort osVal = (ushort) (NativeOSOverride) os;
foreach (var arch in Enum.GetValues (typeof (TargetArchitecture))) {
ushort archVal = (ushort) (TargetArchitecture) arch;
architectureMap.Add ((ushort) (archVal ^ osVal), (TargetArchitecture) arch);
}
}
}

if (architectureMap.TryGetValue ((ushort) readyToRunArch, out TargetArchitecture pureILArch)) {
return pureILArch;
}
throw new BadImageFormatException ("unrecognized module attributes");
}

protected override bool ConditionToProcess ()
{
return Context.ErrorsCount == 0;
Expand Down Expand Up @@ -125,7 +95,7 @@ protected virtual void WriteAssembly (AssemblyDefinition assembly, string direct
if (module.IsCrossgened ()) {
module.Attributes |= ModuleAttributes.ILOnly;
module.Attributes ^= ModuleAttributes.ILLibrary;
module.Architecture = CalculateArchitecture (module.Architecture);
module.Architecture = TargetArchitecture.I386; // I386+ILOnly which ultimately translates to AnyCPU
}
}

Expand Down

0 comments on commit 69062fd

Please sign in to comment.