Skip to content
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

NativeAOT for FreeBSD #80323

Merged
merged 51 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
6b7f9eb
WIP FreeBSD NativeAOT
Thefrank Oct 21, 2022
8159e6a
Merge branch 'dotnet:main' into fbsdaot
Thefrank Oct 21, 2022
f5ec5ff
add inotify for FreeBSD during linking
Thefrank Oct 21, 2022
c963dcf
remove FreeBSD for now
Thefrank Oct 21, 2022
cb52a2c
netstandard does not understand FreeBSD
Thefrank Oct 21, 2022
74b5546
add FreeBSD platform to HostModel Tests
Thefrank Oct 21, 2022
1ae7828
Merge branch 'dotnet:main' into fbsdaot
Thefrank Oct 31, 2022
1be1473
WIP FreeBSD NativeAOT
Thefrank Oct 21, 2022
3415075
add inotify for FreeBSD during linking
Thefrank Oct 21, 2022
685ceab
remove FreeBSD for now
Thefrank Oct 21, 2022
845330a
netstandard does not understand FreeBSD
Thefrank Oct 21, 2022
0f59e51
add FreeBSD platform to HostModel Tests
Thefrank Oct 21, 2022
6c3a9fa
rebase
Thefrank Nov 28, 2022
5f15564
Merge branch 'dotnet:main' into fbsdaot
Thefrank Nov 28, 2022
61ea763
Use Clang12, update LinkerArg
Thefrank Nov 29, 2022
552c64e
Merge branch 'dotnet:main' into fbsdaot
Thefrank Nov 29, 2022
b7eb024
Merge branch 'dotnet:main' into fbsdaot
Thefrank Nov 29, 2022
7e7e7fb
Merge branch 'dotnet:main' into fbsdaot
Thefrank Dec 4, 2022
d304557
WIP FreeBSD NativeAOT
Thefrank Oct 21, 2022
016c837
add inotify for FreeBSD during linking
Thefrank Oct 21, 2022
2b39b09
remove FreeBSD for now
Thefrank Oct 21, 2022
fbfe287
netstandard does not understand FreeBSD
Thefrank Oct 21, 2022
23d0107
add FreeBSD platform to HostModel Tests
Thefrank Oct 21, 2022
84b3ed4
WIP FreeBSD NativeAOT
Thefrank Oct 21, 2022
09789ab
remove FreeBSD for now
Thefrank Oct 21, 2022
2b3ccf9
add FreeBSD platform to HostModel Tests
Thefrank Oct 21, 2022
cd7bb03
Use Clang12, update LinkerArg
Thefrank Nov 29, 2022
e20c878
Merge branch 'fbsdaot' of https://github.com/Thefrank/runtime into fb…
Thefrank Dec 13, 2022
b9967f2
Update JITTools and ObjWriter for FreeBSD-x64
Thefrank Dec 13, 2022
e1eb2b9
fixes for tests
Thefrank Dec 28, 2022
c6264e4
fixes for tests
Thefrank Dec 28, 2022
21c461a
fixes for tests
Thefrank Jan 6, 2023
4f34a55
merge from upstream
Thefrank Jan 6, 2023
ae4a139
add TargetTriple for FreeBSD
Thefrank Jan 7, 2023
e3b95f8
Merge branch 'dotnet:main' into fbsdaot
Thefrank Jan 7, 2023
ef4fdab
Changes from upstream
Thefrank Jan 10, 2023
725fae5
Some changes from feedback, remove out of scope
Thefrank Jan 10, 2023
c5bafd7
Apply suggestions from code review
Thefrank Jan 10, 2023
40d15dd
HostModel back to netstandard2.0
Thefrank Jan 10, 2023
1f07f85
Update src/coreclr/CMakeLists.txt
Thefrank Jan 11, 2023
d149795
Resolve conflicts
Thefrank Jan 12, 2023
53f0fae
Publish crossgen2 as single-file on cross-os
Thefrank Jan 13, 2023
cc05935
pass NativeAotSupported to MSBuild crossgen2 tasks
Thefrank Jan 14, 2023
f4bed42
Can't use NativeAOT in source build yet
Thefrank Jan 14, 2023
201633d
Update src/installer/managed/Microsoft.NET.HostModel/Bundle/TargetInf…
jkotas Jan 16, 2023
c6e375b
Apply suggestions from code review
Thefrank Jan 16, 2023
4629b16
Apply suggestions from code review
Thefrank Jan 17, 2023
1f4ae43
Update private string HostFxr and HostPolicy
Thefrank Jan 17, 2023
7908312
Fix private string HostPolicy
Thefrank Jan 17, 2023
c41fd0a
Apply suggestions from code review
jkotas Jan 17, 2023
a51e7f5
Update src/installer/managed/Microsoft.NET.HostModel/Bundle/TargetInf…
jkotas Jan 18, 2023
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
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 @@ -119,8 +120,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,17 +89,20 @@ 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}";
}

Thefrank marked this conversation as resolved.
Show resolved Hide resolved
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);
public bool IsFreeBSD => OS.Equals(s_freebsdOSPlatform);
jkotas marked this conversation as resolved.
Show resolved Hide resolved

jkotas marked this conversation as resolved.
Show resolved Hide resolved
// The .net core 3 apphost doesn't care about semantics of FileType -- all files are extracted at startup.
// However, the apphost checks that the FileType value is within expected bounds, so set it to the first enumeration.
Expand All @@ -116,7 +117,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>
Thefrank marked this conversation as resolved.
Show resolved Hide resolved
<!-- Can't use NativeAOT in source build yet https://github.com/dotnet/runtime/issues/66859 -->
<NativeAotSupported Condition="'$(DotNetBuildFromSource)' == 'true'">false</NativeAotSupported>
</PropertyGroup>
Thefrank marked this conversation as resolved.
Show resolved Hide resolved

<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