Skip to content

Commit ec4437b

Browse files
authored
[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
1 parent e3dc83a commit ec4437b

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
<_linuxToken>linux-</_linuxToken>
3131
<_linuxLibcFlavor Condition="$(_targetOS.StartsWith($(_linuxToken)))">$(_targetOS.SubString($(_linuxToken.Length)))</_linuxLibcFlavor>
3232
<_targetOS Condition="$(_targetOS.StartsWith($(_linuxToken)))">linux</_targetOS>
33+
34+
<!-- linux-bionic on ARM uses armel (softfp) ABI -->
35+
<_targetArchitectureWithAbi>$(_targetArchitecture)</_targetArchitectureWithAbi>
36+
<_targetArchitectureWithAbi Condition="'$(_linuxLibcFlavor)' == 'bionic' and '$(_targetArchitecture)' == 'arm'">armel</_targetArchitectureWithAbi>
3337
</PropertyGroup>
3438

3539
<PropertyGroup>

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ The .NET Foundation licenses this file to you under the MIT license.
227227
<IlcArg Include="@(MibcFile->'--mibc:%(Identity)')" />
228228
<IlcArg Condition="$(IlcGenerateMetadataLog) == 'true'" Include="--metadatalog:$(NativeIntermediateOutputPath)%(ManagedBinary.Filename).metadata.csv" />
229229
<IlcArg Condition="$(_targetOS) != ''" Include="--targetos:$(_targetOS)" />
230-
<IlcArg Condition="$(_targetArchitecture) != ''" Include="--targetarch:$(_targetArchitecture)" />
230+
<IlcArg Condition="$(_targetArchitectureWithAbi) != ''" Include="--targetarch:$(_targetArchitectureWithAbi)" />
231231
<IlcArg Condition="$(IlcMultiModule) == 'true'" Include="--multifile" />
232232
<IlcArg Condition="$(IlcMultiModule) != 'true' and '$(IlcDehydrate)' != 'false' and '$(ControlFlowGuard)' != 'Guard'" Include="--dehydrate" />
233233
<IlcArg Condition="$(Optimize) == 'true'" Include="-O" />

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/ElfObjectWriter.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ internal sealed class ElfObjectWriter : UnixObjectWriter
3535
{
3636
private readonly bool _useInlineRelocationAddends;
3737
private readonly ushort _machine;
38+
private readonly bool _useSoftFPAbi;
3839
private readonly List<ElfSectionDefinition> _sections = new();
3940
private readonly List<ElfSymbol> _symbols = new();
4041
private uint _localSymbolCount;
@@ -61,6 +62,7 @@ public ElfObjectWriter(NodeFactory factory, ObjectWritingOptions options)
6162
_ => throw new NotSupportedException("Unsupported architecture")
6263
};
6364
_useInlineRelocationAddends = _machine is EM_386 or EM_ARM;
65+
_useSoftFPAbi = _machine is EM_ARM && factory.Target.Abi == TargetAbi.NativeAotArmel;
6466

6567
// By convention the symbol table starts with empty symbol
6668
_symbols.Add(new ElfSymbol {});
@@ -513,7 +515,7 @@ private protected override void EmitSectionsAndLayout()
513515
attributesBuilder.WriteAttribute(Tag_ABI_FP_number_model, 3); // IEEE 754
514516
attributesBuilder.WriteAttribute(Tag_ABI_align_needed, 1); // 8-byte
515517
attributesBuilder.WriteAttribute(Tag_ABI_align_preserved, 1); // 8-byte
516-
attributesBuilder.WriteAttribute(Tag_ABI_VFP_args, 1); // FP parameters passes in VFP registers
518+
attributesBuilder.WriteAttribute(Tag_ABI_VFP_args, _useSoftFPAbi ? 0ul : 1ul); // FP parameters passes in VFP registers
517519
attributesBuilder.WriteAttribute(Tag_CPU_unaligned_access, 0); // None
518520
attributesBuilder.EndSection();
519521
}

src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ internal sealed class ILCompilerRootCommand : CliRootCommand
148148
public CliOption<bool> RootDefaultAssemblies { get; } =
149149
new("--defaultrooting") { Description = "Root assemblies that are not marked [IsTrimmable]" };
150150
public CliOption<TargetArchitecture> TargetArchitecture { get; } =
151-
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" };
151+
new("--targetarch") { CustomParser = MakeTargetArchitecture, DefaultValueFactory = MakeTargetArchitecture, Description = "Target architecture for cross compilation", HelpName = "arg" };
152152
public CliOption<TargetOS> TargetOS { get; } =
153153
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" };
154154
public CliOption<string> JitPath { get; } =
@@ -170,6 +170,7 @@ internal sealed class ILCompilerRootCommand : CliRootCommand
170170

171171
public OptimizationMode OptimizationMode { get; private set; }
172172
public ParseResult Result;
173+
public static bool IsArmel { get; private set; }
173174

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

377+
private static TargetArchitecture MakeTargetArchitecture(ArgumentResult result)
378+
{
379+
string firstToken = result.Tokens.Count > 0 ? result.Tokens[0].Value : null;
380+
if (firstToken != null && firstToken.Equals("armel", StringComparison.OrdinalIgnoreCase))
381+
{
382+
IsArmel = true;
383+
return Internal.TypeSystem.TargetArchitecture.ARM;
384+
}
385+
386+
return Helpers.GetTargetArchitecture(firstToken);
387+
}
388+
376389
private static int MakeParallelism(ArgumentResult result)
377390
{
378391
if (result.Tokens.Count > 0)

src/coreclr/tools/aot/ILCompiler/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public int Run()
113113
SharedGenericsMode genericsMode = SharedGenericsMode.CanonicalReferenceTypes;
114114

115115
var simdVectorLength = instructionSetSupport.GetVectorTSimdVector();
116-
var targetAbi = TargetAbi.NativeAot;
116+
var targetAbi = ILCompilerRootCommand.IsArmel ? TargetAbi.NativeAotArmel : TargetAbi.NativeAot;
117117
var targetDetails = new TargetDetails(targetArchitecture, targetOS, targetAbi, simdVectorLength);
118118
CompilerTypeSystemContext typeSystemContext =
119119
new CompilerTypeSystemContext(targetDetails, genericsMode, supportsReflection ? DelegateFeature.All : 0,

0 commit comments

Comments
 (0)