Skip to content

[LoongArch64] Improve the functionality of LoongArch64 R2R #114666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 22, 2025
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
33 changes: 29 additions & 4 deletions src/installer/managed/Microsoft.NET.HostModel/Bundle/TargetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public TargetInfo(OSPlatform? os, Architecture? arch, Version targetFrameworkVer
// This is only necessary for R2R assemblies, but we do it for all assemblies for simplicity.
AssemblyAlignment = 4096;
}
else if (Arch == Architecture.LoongArch64)
{
// We align assemblies in the bundle at 16K so that we can use mmap on Unix without changing the page alignment of LOONGARCH64 R2R code.
// This is only necessary for R2R assemblies, but we do it for all assemblies for simplicity.
AssemblyAlignment = 16384;
}
else if (Arch == Architecture.Arm64)
{
// We align assemblies in the bundle at 4K so that we can use mmap on Unix without changing the page alignment of ARM64 R2R code.
Expand Down Expand Up @@ -95,10 +101,11 @@ public override string ToString()
return $"OS: {os} Arch: {arch} FrameworkVersion: {FrameworkVersion}";
}

private static readonly OSPlatform s_freebsdOSPlatform = OSPlatform.Create("FREEBSD");

private static OSPlatform HostOS => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? OSPlatform.Linux :
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? OSPlatform.OSX : RuntimeInformation.IsOSPlatform(s_freebsdOSPlatform) ? s_freebsdOSPlatform : OSPlatform.Windows;
private static OSPlatform? _hostOS;
private static OSPlatform HostOS => _hostOS ??= RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? OSPlatform.Linux :
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? OSPlatform.OSX :
RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD) ? OSPlatform.FreeBSD :
RuntimeInformation.IsOSPlatform(OSPlatform.Illumos) ? OSPlatform.Illumos : OSPlatform.Windows;

public bool IsOSX => OS.Equals(OSPlatform.OSX);
public bool IsWindows => OS.Equals(OSPlatform.Windows);
Expand All @@ -119,4 +126,22 @@ public bool ShouldExclude(string relativePath) =>
private string HostFxr => IsWindows ? "hostfxr.dll" : IsOSX ? "libhostfxr.dylib" : "libhostfxr.so";
private string HostPolicy => IsWindows ? "hostpolicy.dll" : IsOSX ? "libhostpolicy.dylib" : "libhostpolicy.so";
}

file static class PlatformExtensions
{
extension(OSPlatform)
{
#if NETFRAMEWORK
public static OSPlatform FreeBSD => OSPlatform.Create("FREEBSD");
#endif
public static OSPlatform Illumos => OSPlatform.Create("ILLUMOS");
}

#if NETFRAMEWORK
extension(Architecture)
{
public static Architecture LoongArch64 => (Architecture)6;
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<!-- Set the RID when building on a platform where we support self-contained + apphost -->
<_SupportedPlatform Condition="'$(TargetsLinux)' == 'true' or '$(TargetsOSX)' == 'true' or '$(TargetsWindows)' == 'true'">true</_SupportedPlatform>
<_SupportedArchitecture Condition="'$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'x86' or '$(TargetArchitecture)' == 'arm' or'$(TargetArchitecture)' == 'arm64'">true</_SupportedArchitecture>
<_SupportedArchitecture Condition="'$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'x86' or '$(TargetArchitecture)' == 'arm' or '$(TargetArchitecture)' == 'arm64' or '$(TargetArchitecture)' == 'loongarch64'">true</_SupportedArchitecture>
<RuntimeIdentifier Condition="'$(_SupportedPlatform)' == 'true' and '$(_SupportedArchitecture)' == 'true'">$(OutputRID)</RuntimeIdentifier>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public void AssemblyAlignment()
Bundler bundler = CreateBundlerInstance();
bundler.GenerateBundle(fileSpecs);

var alignment = OperatingSystem.IsLinux() && RuntimeInformation.OSArchitecture == Architecture.Arm64 ? 4096 : 16;
var alignment = OperatingSystem.IsLinux() && RuntimeInformation.OSArchitecture == Architecture.Arm64 ? 4096 : (OperatingSystem.IsLinux() && RuntimeInformation.OSArchitecture == Architecture.LoongArch64 ? 16384 : 16);
bundler.BundleManifest.Files.ForEach(file =>
Assert.True((file.Type != FileType.Assembly) || (file.Offset % alignment == 0)));
}
Expand Down