Skip to content

Commit

Permalink
[NativeAOT] Use SoftFP ABI on linux-bionic-arm (#100392)
Browse files Browse the repository at this point in the history
Android uses the SoftFP ABI on ARM32 (https://android.googlesource.com/platform/ndk/+/ndk-r12-release/docs/HardFloatAbi.md).

- Copy Crossgen2 logic for "armel" target into ILCompiler
- Use "armel" for linux-bionic-arm ILC target
  • Loading branch information
filipnavara authored Apr 1, 2024
1 parent e3dc83a commit ec4437b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<_linuxToken>linux-</_linuxToken>
<_linuxLibcFlavor Condition="$(_targetOS.StartsWith($(_linuxToken)))">$(_targetOS.SubString($(_linuxToken.Length)))</_linuxLibcFlavor>
<_targetOS Condition="$(_targetOS.StartsWith($(_linuxToken)))">linux</_targetOS>

<!-- linux-bionic on ARM uses armel (softfp) ABI -->
<_targetArchitectureWithAbi>$(_targetArchitecture)</_targetArchitectureWithAbi>
<_targetArchitectureWithAbi Condition="'$(_linuxLibcFlavor)' == 'bionic' and '$(_targetArchitecture)' == 'arm'">armel</_targetArchitectureWithAbi>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<IlcArg Include="@(MibcFile->'--mibc:%(Identity)')" />
<IlcArg Condition="$(IlcGenerateMetadataLog) == 'true'" Include="--metadatalog:$(NativeIntermediateOutputPath)%(ManagedBinary.Filename).metadata.csv" />
<IlcArg Condition="$(_targetOS) != ''" Include="--targetos:$(_targetOS)" />
<IlcArg Condition="$(_targetArchitecture) != ''" Include="--targetarch:$(_targetArchitecture)" />
<IlcArg Condition="$(_targetArchitectureWithAbi) != ''" Include="--targetarch:$(_targetArchitectureWithAbi)" />
<IlcArg Condition="$(IlcMultiModule) == 'true'" Include="--multifile" />
<IlcArg Condition="$(IlcMultiModule) != 'true' and '$(IlcDehydrate)' != 'false' and '$(ControlFlowGuard)' != 'Guard'" Include="--dehydrate" />
<IlcArg Condition="$(Optimize) == 'true'" Include="-O" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal sealed class ElfObjectWriter : UnixObjectWriter
{
private readonly bool _useInlineRelocationAddends;
private readonly ushort _machine;
private readonly bool _useSoftFPAbi;
private readonly List<ElfSectionDefinition> _sections = new();
private readonly List<ElfSymbol> _symbols = new();
private uint _localSymbolCount;
Expand All @@ -61,6 +62,7 @@ public ElfObjectWriter(NodeFactory factory, ObjectWritingOptions options)
_ => throw new NotSupportedException("Unsupported architecture")
};
_useInlineRelocationAddends = _machine is EM_386 or EM_ARM;
_useSoftFPAbi = _machine is EM_ARM && factory.Target.Abi == TargetAbi.NativeAotArmel;

// By convention the symbol table starts with empty symbol
_symbols.Add(new ElfSymbol {});
Expand Down Expand Up @@ -513,7 +515,7 @@ private protected override void EmitSectionsAndLayout()
attributesBuilder.WriteAttribute(Tag_ABI_FP_number_model, 3); // IEEE 754
attributesBuilder.WriteAttribute(Tag_ABI_align_needed, 1); // 8-byte
attributesBuilder.WriteAttribute(Tag_ABI_align_preserved, 1); // 8-byte
attributesBuilder.WriteAttribute(Tag_ABI_VFP_args, 1); // FP parameters passes in VFP registers
attributesBuilder.WriteAttribute(Tag_ABI_VFP_args, _useSoftFPAbi ? 0ul : 1ul); // FP parameters passes in VFP registers
attributesBuilder.WriteAttribute(Tag_CPU_unaligned_access, 0); // None
attributesBuilder.EndSection();
}
Expand Down
15 changes: 14 additions & 1 deletion src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ internal sealed class ILCompilerRootCommand : CliRootCommand
public CliOption<bool> RootDefaultAssemblies { get; } =
new("--defaultrooting") { Description = "Root assemblies that are not marked [IsTrimmable]" };
public CliOption<TargetArchitecture> TargetArchitecture { get; } =
new("--targetarch") { CustomParser = result => Helpers.GetTargetArchitecture(result.Tokens.Count > 0 ? result.Tokens[0].Value : null), DefaultValueFactory = result => Helpers.GetTargetArchitecture(result.Tokens.Count > 0 ? result.Tokens[0].Value : null), Description = "Target architecture for cross compilation", HelpName = "arg" };
new("--targetarch") { CustomParser = MakeTargetArchitecture, DefaultValueFactory = MakeTargetArchitecture, Description = "Target architecture for cross compilation", HelpName = "arg" };
public CliOption<TargetOS> TargetOS { get; } =
new("--targetos") { CustomParser = result => Helpers.GetTargetOS(result.Tokens.Count > 0 ? result.Tokens[0].Value : null), DefaultValueFactory = result => Helpers.GetTargetOS(result.Tokens.Count > 0 ? result.Tokens[0].Value : null), Description = "Target OS for cross compilation", HelpName = "arg" };
public CliOption<string> JitPath { get; } =
Expand All @@ -170,6 +170,7 @@ internal sealed class ILCompilerRootCommand : CliRootCommand

public OptimizationMode OptimizationMode { get; private set; }
public ParseResult Result;
public static bool IsArmel { get; private set; }

public ILCompilerRootCommand(string[] args) : base(".NET Native IL Compiler")
{
Expand Down Expand Up @@ -373,6 +374,18 @@ public static IEnumerable<Func<HelpContext, bool>> GetExtendedHelp(HelpContext _
};
}

private static TargetArchitecture MakeTargetArchitecture(ArgumentResult result)
{
string firstToken = result.Tokens.Count > 0 ? result.Tokens[0].Value : null;
if (firstToken != null && firstToken.Equals("armel", StringComparison.OrdinalIgnoreCase))
{
IsArmel = true;
return Internal.TypeSystem.TargetArchitecture.ARM;
}

return Helpers.GetTargetArchitecture(firstToken);
}

private static int MakeParallelism(ArgumentResult result)
{
if (result.Tokens.Count > 0)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/aot/ILCompiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public int Run()
SharedGenericsMode genericsMode = SharedGenericsMode.CanonicalReferenceTypes;

var simdVectorLength = instructionSetSupport.GetVectorTSimdVector();
var targetAbi = TargetAbi.NativeAot;
var targetAbi = ILCompilerRootCommand.IsArmel ? TargetAbi.NativeAotArmel : TargetAbi.NativeAot;
var targetDetails = new TargetDetails(targetArchitecture, targetOS, targetAbi, simdVectorLength);
CompilerTypeSystemContext typeSystemContext =
new CompilerTypeSystemContext(targetDetails, genericsMode, supportsReflection ? DelegateFeature.All : 0,
Expand Down

0 comments on commit ec4437b

Please sign in to comment.