Skip to content

Commit

Permalink
NativeAOT for FreeBSD (#80323)
Browse files Browse the repository at this point in the history
* add inotify for FreeBSD during linking

* remove FreeBSD for now

* netstandard does not understand FreeBSD

* add FreeBSD platform to HostModel Tests

* add inotify for FreeBSD during linking

* remove FreeBSD for now

* netstandard does not understand FreeBSD

* add FreeBSD platform to HostModel Tests

* Use Clang12, update LinkerArg

* WIP FreeBSD NativeAOT

* add inotify for FreeBSD during linking

* remove FreeBSD for now

* netstandard does not understand FreeBSD

* add FreeBSD platform to HostModel Tests

* WIP FreeBSD NativeAOT

* remove FreeBSD for now

* add FreeBSD platform to HostModel Tests

* Use Clang12, update LinkerArg

* Update JITTools and ObjWriter for FreeBSD-x64

* fixes for tests

* fixes for tests

* add TargetTriple for FreeBSD

* Some changes from feedback, remove out of scope

* HostModel back to netstandard2.0

* Update src/coreclr/CMakeLists.txt

* Publish crossgen2 as single-file on cross-os

* pass NativeAotSupported to MSBuild crossgen2 tasks

* Can't use NativeAOT in source build yet

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

* Update private string HostFxr and HostPolicy

* Fix private string HostPolicy

* Apply suggestions from code review

Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Robin Sue <robinsue@live.de>
  • Loading branch information
5 people authored Jan 19, 2023
1 parent ad9efe8 commit 70e1072
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@

<PropertyGroup>
<!-- CLR NativeAot only builds in a subset of the matrix -->
<NativeAotSupported Condition="('$(TargetOS)' == 'windows' or '$(TargetOS)' == 'linux' or '$(TargetOS)' == 'osx') and ('$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'arm64')">true</NativeAotSupported>
<NativeAotSupported Condition="('$(TargetOS)' == 'windows' or '$(TargetOS)' == 'linux' or '$(TargetOS)' == 'osx' or '$(TargetOS)' == 'freebsd') and ('$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'arm64')">true</NativeAotSupported>

<!-- If we're building clr.nativeaotlibs and not building the CLR runtime, compile libraries against NativeAOT CoreLib -->
<UseNativeAotCoreLib Condition="$(_subset.Contains('+clr.nativeaotlibs+')) and !$(_subset.Contains('+clr.native+')) and !$(_subset.Contains('+clr.runtime+'))">true</UseNativeAotCoreLib>
Expand Down
2 changes: 2 additions & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<runtimewinx64MicrosoftNETCoreRuntimeObjWriterVersion>1.0.0-alpha.1.23059.1</runtimewinx64MicrosoftNETCoreRuntimeObjWriterVersion>
<runtimeosx110arm64MicrosoftNETCoreRuntimeObjWriterVersion>1.0.0-alpha.1.23059.1</runtimeosx110arm64MicrosoftNETCoreRuntimeObjWriterVersion>
<runtimeosx1012x64MicrosoftNETCoreRuntimeObjWriterVersion>1.0.0-alpha.1.23059.1</runtimeosx1012x64MicrosoftNETCoreRuntimeObjWriterVersion>
<runtimefreebsdx64MicrosoftNETCoreRuntimeObjWriterVersion>1.0.0-alpha.1.23059.1</runtimefreebsdx64MicrosoftNETCoreRuntimeObjWriterVersion>
<!-- Libraries dependencies -->
<MicrosoftBclAsyncInterfacesVersion>6.0.0</MicrosoftBclAsyncInterfacesVersion>
<MicrosoftBclHashCodeVersion>1.1.1</MicrosoftBclHashCodeVersion>
Expand Down Expand Up @@ -248,5 +249,6 @@
<runtimewinx64MicrosoftNETCoreRuntimeJITToolsVersion>1.0.0-alpha.1.23059.1</runtimewinx64MicrosoftNETCoreRuntimeJITToolsVersion>
<runtimeosx110arm64MicrosoftNETCoreRuntimeJITToolsVersion>1.0.0-alpha.1.23059.1</runtimeosx110arm64MicrosoftNETCoreRuntimeJITToolsVersion>
<runtimeosx1012x64MicrosoftNETCoreRuntimeJITToolsVersion>1.0.0-alpha.1.23059.1</runtimeosx1012x64MicrosoftNETCoreRuntimeJITToolsVersion>
<runtimefreebsdx64MicrosoftNETCoreRuntimeJITToolsVersion>1.0.0-alpha.1.23059.1</runtimefreebsdx64MicrosoftNETCoreRuntimeJITToolsVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ add_subdirectory(tools/aot/jitinterface)

if(NOT CLR_CROSS_COMPONENTS_BUILD)
# NativeAOT only buildable for a subset of CoreCLR-supported configurations
if((CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_WIN32) AND (CLR_CMAKE_HOST_ARCH_ARM64 OR CLR_CMAKE_HOST_ARCH_AMD64))
if(CLR_CMAKE_HOST_ARCH_ARM64 OR CLR_CMAKE_HOST_ARCH_AMD64)
add_subdirectory(nativeaot)
endif()
endif(NOT CLR_CROSS_COMPONENTS_BUILD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<!-- Define the name of the runtime specific compiler package to import -->
<OSIdentifier Condition="$(RuntimeIdentifier.StartsWith('win'))">win</OSIdentifier>
<OSIdentifier Condition="$(RuntimeIdentifier.StartsWith('osx'))">osx</OSIdentifier>
<OSIdentifier Condition="$(RuntimeIdentifier.StartsWith('freebsd'))">freebsd</OSIdentifier>
<OSIdentifier Condition="$(RuntimeIdentifier.StartsWith('linux-musl')) OR $(RuntimeIdentifier.StartsWith('alpine'))">linux-musl</OSIdentifier>
<OSIdentifier Condition="'$(OSIdentifier)' == ''">linux</OSIdentifier>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<TargetTriple />
<TargetTriple Condition="'$(CrossCompileArch)' != ''">$(CrossCompileArch)-linux-gnu</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('linux-musl')) or $(CrossCompileRid.StartsWith('alpine')))">$(CrossCompileArch)-alpine-linux-musl</TargetTriple>
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('freebsd')))">$(CrossCompileArch)-unknown-freebsd12</TargetTriple>

<IlcRPath Condition="'$(IlcRPath)' == '' and '$(TargetOS)' != 'osx'">$ORIGIN</IlcRPath>
<IlcRPath Condition="'$(IlcRPath)' == '' and '$(TargetOS)' == 'osx'">@executable_path</IlcRPath>
Expand Down Expand Up @@ -141,8 +142,12 @@ The .NET Foundation licenses this file to you under the MIT license.
<LinkerArg Include="-Wl,-z,relro" Condition="'$(TargetOS)' != 'osx'" />
<!-- binskim warning BA3011 The BIND_NOW flag is missing -->
<LinkerArg Include="-Wl,-z,now" Condition="'$(TargetOS)' != 'osx'" />
<LinkerArg Include="-Wl,-u,_NativeAOT_StaticInitialization" Condition="'$(TargetOS)' == 'osx' and '$(NativeLib)' == 'Shared'" />
<LinkerArg Include="-Wl,--require-defined,NativeAOT_StaticInitialization" Condition="'$(TargetOS)' != 'osx' and '$(NativeLib)' == 'Shared'" />
<LinkerArg Include="-Wl,-u,_NativeAOT_StaticInitialization" Condition="('$(TargetOS)' == 'osx' or '$(TargetOS)' == 'freebsd') and '$(NativeLib)' == 'Shared'" />
<LinkerArg Include="-Wl,--require-defined,NativeAOT_StaticInitialization" Condition="('$(TargetOS)' == 'linux') and '$(NativeLib)' == 'Shared'" />
<!-- FreeBSD has two versions of the GSSAPI it can use, but we only use the ports version (MIT version) here -->
<LinkerArg Include="-L/usr/local/lib -lgssapi_krb5" Condition="'$(TargetOS)' == 'freebsd'" />
<!-- FreeBSD's inotify is an installed package and not found in default libraries -->
<LinkerArg Include="-L/usr/local/lib -linotify" Condition="'$(TargetOS)' == 'freebsd'" />

<LinkerArg Include="@(NativeFramework->'-framework %(Identity)')" Condition="'$(TargetOS)' == 'osx'" />
</ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/tools/aot/ILCompiler/ILCompiler.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<ObjWriterRidWithoutPlatform>$(RuntimeIdentifier.Substring(0, $(_objWriterRidPlatformIndex)))</ObjWriterRidWithoutPlatform>
<ObjWriterRidPlatform>$(RuntimeIdentifier.Substring($(_objWriterRidPlatformIndex)).TrimStart('-'))</ObjWriterRidPlatform>

<!-- If it's not win/osx/linux-musl, it's a non-portable Linux. Treat as Linux. -->
<ObjWriterRidWithoutPlatform Condition="'$(ObjWriterRidWithoutPlatform)' != 'win' and '$(ObjWriterRidWithoutPlatform)' != 'osx' and '$(ObjWriterRidWithoutPlatform)' != 'linux-musl'">linux</ObjWriterRidWithoutPlatform>
<!-- If it's not win/osx/freebsd/linux-musl, it's a non-portable Linux. Treat as Linux. -->
<ObjWriterRidWithoutPlatform Condition="'$(ObjWriterRidWithoutPlatform)' != 'win' and '$(ObjWriterRidWithoutPlatform)' != 'osx' and '$(ObjWriterRidWithoutPlatform)' != 'linux-musl' and '$(ObjWriterRidWithoutPlatform)' != 'freebsd'">linux</ObjWriterRidWithoutPlatform>

<!-- OSX builds have a version -->
<ObjWriterRidWithoutPlatform Condition="'$(ObjWriterRidWithoutPlatform)' == 'osx' and '$(ObjWriterRidPlatform)' == 'x64'">osx.10.12</ObjWriterRidWithoutPlatform>
Expand All @@ -45,6 +45,7 @@
<ObjWriterVersion Condition="'$(ObjWriterVersion)' == '' and '$(ObjWriterRid)' == 'win-x64'">$(runtimewinx64MicrosoftNETCoreRuntimeObjWriterVersion)</ObjWriterVersion>
<ObjWriterVersion Condition="'$(ObjWriterVersion)' == '' and '$(ObjWriterRid)' == 'osx.11.0-arm64'">$(runtimeosx110arm64MicrosoftNETCoreRuntimeObjWriterVersion)</ObjWriterVersion>
<ObjWriterVersion Condition="'$(ObjWriterVersion)' == '' and '$(ObjWriterRid)' == 'osx.10.12-x64'">$(runtimeosx1012x64MicrosoftNETCoreRuntimeObjWriterVersion)</ObjWriterVersion>
<ObjWriterVersion Condition="'$(ObjWriterVersion)' == '' and '$(ObjWriterRid)' == 'freebsd-x64'">$(runtimefreebsdx64MicrosoftNETCoreRuntimeObjWriterVersion)</ObjWriterVersion>

<!-- CoreDisTools are used in debugging visualizers. -->
<IncludeCoreDisTools Condition="'$(Configuration)' != 'Release' and '$(CrossHostArch)' == ''">true</IncludeCoreDisTools>
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public static IEnumerable<Action<HelpContext>> GetExtendedHelp(HelpContext _)
"considered to be input files. If no input files begin with '--' then this option is not necessary.\n");
string[] ValidArchitectures = new string[] { "arm", "arm64", "x86", "x64" };
string[] ValidOS = new string[] { "windows", "linux", "osx" };
string[] ValidOS = new string[] { "windows", "linux", "osx", "freebsd" };
Console.WriteLine("Valid switches for {0} are: '{1}'. The default value is '{2}'\n", "--targetos", string.Join("', '", ValidOS), Helpers.GetTargetOS(null).ToString().ToLowerInvariant());
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/aot/ILCompiler/repro/repro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<RuntimeIdentifiers>linux-x64;win-x64;osx-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>linux-x64;win-x64;osx-x64;freebsd-x64</RuntimeIdentifiers>
<Configurations>Debug;Release;Checked</Configurations>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public TargetInfo(OSPlatform? os, Architecture? arch, Version targetFrameworkVer
Arch = arch ?? RuntimeInformation.OSArchitecture;
FrameworkVersion = targetFrameworkVersion ?? Environment.Version;

Debug.Assert(IsLinux || IsOSX || IsWindows);

if (FrameworkVersion.Major >= 6)
{
BundleMajorVersion = 6u;
Expand Down Expand Up @@ -79,7 +77,7 @@ public TargetInfo(OSPlatform? os, Architecture? arch, Version targetFrameworkVer

public bool IsNativeBinary(string filePath)
{
return IsLinux ? ElfUtils.IsElfImage(filePath) : IsOSX ? MachOUtils.IsMachOImage(filePath) : PEUtils.IsPEImage(filePath);
return IsWindows ? PEUtils.IsPEImage(filePath) : IsOSX ? MachOUtils.IsMachOImage(filePath) : ElfUtils.IsElfImage(filePath);
}

public string GetAssemblyName(string hostName)
Expand All @@ -91,15 +89,16 @@ public string GetAssemblyName(string hostName)

public override string ToString()
{
string os = IsWindows ? "win" : IsLinux ? "linux" : "osx";
string os = IsWindows ? "win" : OS.ToString().ToLowerInvariant();
string arch = Arch.ToString().ToLowerInvariant();
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 : OSPlatform.Windows;
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? OSPlatform.OSX : RuntimeInformation.IsOSPlatform(s_freebsdOSPlatform) ? s_freebsdOSPlatform : OSPlatform.Windows;

public bool IsLinux => OS.Equals(OSPlatform.Linux);
public bool IsOSX => OS.Equals(OSPlatform.OSX);
public bool IsWindows => OS.Equals(OSPlatform.Windows);

Expand All @@ -116,7 +115,7 @@ public override string ToString()
public bool ShouldExclude(string relativePath) =>
(FrameworkVersion.Major != 3) && (relativePath.Equals(HostFxr) || relativePath.Equals(HostPolicy));

private string HostFxr => IsWindows ? "hostfxr.dll" : IsLinux ? "libhostfxr.so" : "libhostfxr.dylib";
private string HostPolicy => IsWindows ? "hostpolicy.dll" : IsLinux ? "libhostpolicy.so" : "libhostpolicy.dylib";
private string HostFxr => IsWindows ? "hostfxr.dll" : IsOSX ? "libhostfxr.dylib" : "libhostfxr.so";
private string HostPolicy => IsWindows ? "hostpolicy.dll" : IsOSX ? "libhostpolicy.dylib" : "libhostpolicy.so";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
<OfficialBuildRID Include="osx-x64" Platform="x64" />
<OfficialBuildRID Include="win-arm64" Platform="arm64" />
<OfficialBuildRID Include="win-x64" Platform="x64" />
<OfficialBUildRID Include="freebsd-x64" Platform="x64" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<PermitDllAndExeFilesLackingFileVersion>true</PermitDllAndExeFilesLackingFileVersion>
<!-- Publishing as single-file or NativeAOT means we can't examine the interior DLLs -->
<ShouldVerifyClosure>false</ShouldVerifyClosure>
<!-- Publish crossgen2 as a single-file app on cross-OS builds. Cross-OS NativeAOT compilation is not supported yet -->
<NativeAotSupported Condition="'$(CrossBuild)' == 'true' and '$(TargetOS)' != '$(HostOS)'">false</NativeAotSupported>
<!-- Can't use NativeAOT in source build yet https://github.com/dotnet/runtime/issues/66859 -->
<NativeAotSupported Condition="'$(DotNetBuildFromSource)' == 'true'">false</NativeAotSupported>
</PropertyGroup>

<Target Name="PublishCrossgen"
Expand All @@ -34,13 +38,15 @@
Properties="MSBuildRestoreSessionId=$([System.Guid]::NewGuid())
;_IsPublishing=true
;RuntimeIdentifier=$(PackageRID)
;NativeAotSupported=$(NativeAotSupported)
;CoreCLRArtifactsPath=$(CoreCLRArtifactsPath)
;R2ROverridePath=$(MSBuildThisFileDirectory)ReadyToRun.targets" />

<MSBuild Projects="$(RepoRoot)src/coreclr/tools/aot/crossgen2/crossgen2.csproj"
Targets="Publish;PublishItemsOutputGroup"
Properties="_IsPublishing=true
;RuntimeIdentifier=$(PackageRID)
;NativeAotSupported=$(NativeAotSupported)
;CoreCLRArtifactsPath=$(CoreCLRArtifactsPath)
;R2ROverridePath=$(MSBuildThisFileDirectory)ReadyToRun.targets">
<Output TaskParameter="TargetOutputs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public static OSPlatform GetTargetOS(string runtimeIdentifier)
"win" => OSPlatform.Windows,
"osx" => OSPlatform.OSX,
"linux" => OSPlatform.Linux,
"freebsd" => OSPlatform.FreeBSD,
_ => throw new ArgumentException(nameof(runtimeIdentifier))
};
}
Expand Down

0 comments on commit 70e1072

Please sign in to comment.