From ec4437be46d8b90bc9fa6740c556bd860d9fe5ab Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Mon, 1 Apr 2024 09:50:56 +0200 Subject: [PATCH] [NativeAOT] Use SoftFP ABI on linux-bionic-arm (#100392) 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 --- ...icrosoft.DotNet.ILCompiler.SingleEntry.targets | 4 ++++ .../Microsoft.NETCore.Native.targets | 2 +- .../Compiler/ObjectWriter/ElfObjectWriter.cs | 4 +++- .../tools/aot/ILCompiler/ILCompilerRootCommand.cs | 15 ++++++++++++++- src/coreclr/tools/aot/ILCompiler/Program.cs | 2 +- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets index 62f159c5dc526..c2627502f9ddd 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets @@ -30,6 +30,10 @@ <_linuxToken>linux- <_linuxLibcFlavor Condition="$(_targetOS.StartsWith($(_linuxToken)))">$(_targetOS.SubString($(_linuxToken.Length))) <_targetOS Condition="$(_targetOS.StartsWith($(_linuxToken)))">linux + + + <_targetArchitectureWithAbi>$(_targetArchitecture) + <_targetArchitectureWithAbi Condition="'$(_linuxLibcFlavor)' == 'bionic' and '$(_targetArchitecture)' == 'arm'">armel diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets index 75f579fc4a861..988a02dd8792d 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets @@ -227,7 +227,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/ElfObjectWriter.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/ElfObjectWriter.cs index 11303f8eb2759..503985d92934e 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/ElfObjectWriter.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/ElfObjectWriter.cs @@ -35,6 +35,7 @@ internal sealed class ElfObjectWriter : UnixObjectWriter { private readonly bool _useInlineRelocationAddends; private readonly ushort _machine; + private readonly bool _useSoftFPAbi; private readonly List _sections = new(); private readonly List _symbols = new(); private uint _localSymbolCount; @@ -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 {}); @@ -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(); } diff --git a/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs b/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs index 917f1b612942e..f38811fd93d2d 100644 --- a/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs +++ b/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs @@ -148,7 +148,7 @@ internal sealed class ILCompilerRootCommand : CliRootCommand public CliOption RootDefaultAssemblies { get; } = new("--defaultrooting") { Description = "Root assemblies that are not marked [IsTrimmable]" }; public CliOption 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 { 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 JitPath { get; } = @@ -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") { @@ -373,6 +374,18 @@ public static IEnumerable> 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) diff --git a/src/coreclr/tools/aot/ILCompiler/Program.cs b/src/coreclr/tools/aot/ILCompiler/Program.cs index 2cf88e34a65e0..baf589f6af494 100644 --- a/src/coreclr/tools/aot/ILCompiler/Program.cs +++ b/src/coreclr/tools/aot/ILCompiler/Program.cs @@ -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,