-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Cross built ILCompiler NuGet contains HostOS (Linux) ELFs not TargetOS (FreeBSD) ELFs #104497
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
This was refactored in #103508 . Does the problem still exist in current main? |
Ok, here is the problem: The regular build uses "last known good" toolchain (the one that comes from https://github.com/dotnet/runtime/blob/main/global.json#L3) for aot compilation of most managed tools and components. The one exception is crossgen2 that uses live built aot toolchain that leads to interesting problems every once in a while. When cross-compiling from Linux to FreeBSD, there is no "last known good" aot toolchain that is able to cross-compile from Linux to FreeBSD. We end up doing Linux->Linux publish instead due to some incorrect build logic and produce binaries for wrong architecture as you have observed. I can think about two options for addressing this:
|
Would disabling AOT for managed items still give FreeBSD (TargetOS) ELF's on components like ILCompiler? The multi-stage build sounds like the best solution for this issue. But, unless there is something I am missing, this issue seems limited to a niche case of cross compiling from Linux to FreeBSD/Illumos/Haiku/Other. If it helps other build scenarios for officially supported platforms then there is a better case for this but I am not familiar enough with intricacies here. |
I think having the recipe for how to use live-built AOT compilers would be generally useful. We keep having long discussions about whether it is better to use live-built AOT compiler or last-known-good AOT compiler. So having both options and use the one that's more appropriate for given situation would be best.
It would require some extra build logic. Nothing impossible. |
As there is no way currently to build an ILCompiler on Linux for FreeBSD is there anyway to build the ILCompiler without needing a prior version of it natively? I tried poking around the various |
Yes, that's correct. The ILCompiler is AOT-compiled using prior version ("last known good" version in my comment above). The potential ways to break this cycle is either disable AOT compilation of the ILCompiler; or do the multi-stage build thing. |
Just noticed that targetInfo wasn't correctly set for FreeBSD, opened dotnet/sdk#42144. (i.e. 70e1072 was overwritten as "Linux" by the SDK) Whether or not it fix this particular issue, I think it's good to let runtime control platform resolution in one place. |
@jkotas When doing a native build, turning off AOT for ILC (and other items?) via
The segmentation fault is I will create another Issue for when I figure out what is going on. |
You can try turning off PublishSingleFile / PublishReadyToRun / PublishTrimmed in https://github.com/dotnet/runtime/blob/main/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj and see whether it fixes the crash. |
A simple app builds and runs OK. Steps if I missed something:
same results with combinations of However
|
PublishSingleFile alone and PublishReadyToRun alone also run? Note that you will need to delete obj/ dir in between or pass |
Yes
|
@am11 yep! That allows crossbuild on Linux to output a FreeBSD ELF for ILCompiler. I will open another issue to address the output from ILC |
Just my few cents on that one, running on arm64 hardware :) I've applied both #105587 and #105004, did the cross build of preview.7 and tried to native build using that as bootstrap.
@am11 Should I try to recompile runtime (and/or whole SDK) with edit: turns out that edit 2: with ilc from cross nuget, runtime repo builds natively, that's something at least :) |
Which FreeBSD version and which LLVM/Clang version? |
13.3-RELEASE-p3 and llvm18 (had the same with llvm15). Tried to native build runtime with
edit: hm, looks like ilc is build without symbol exported from #105587 when doing native build, will look into that. |
|
The size of working ones are different - native one is 72480 bytes and the one from cross nuget is 16606596. the other two, that don't work don't have symbols exported that added them on crossbuild - have build running with symbol export added without edit: it sill segfault and there's no progname and environ symbol exported
@am11 maybe you could point in right direction, why those symbol exports could be missing when doing native build of ILC? |
@sec, I haven't tested it with freebsd-arm64, but if all things being equal (to x64) it should work the same way. I think the first run of the target is getting targetOS == linux for some reason in your environment. |
I have changed those conditions to |
Have you changed it in all |
Hm, based on your PR, you only added those to I tried to look where
|
Ah I meant find ~/.nuget -name '*Native.targets'. I'll create a VM on osx arm64 and try to debug it on the weekend. |
Ok, I think I've found the issue, indeed I had some old nuget's cached - will confirm that in few minutes. edit: yes, I had old full build of runtime/aspnet/sdk was completed under freebsd-arm64 :) |
One of those |
Overview:
When cross compiling runtime, the ILCompiler (and NuGet) that is produced contains HostOS (Linux) and not TargetOS (FreeBSD) ELFs.
Reproduction:
Using a docker container on Linux pulled from: https://raw.githubusercontent.com/dotnet/versions/master/build-info/docker/image-info.dotnet-dotnet-buildtools-prereqs-docker-main.json containing a FreeBSD ROOTFS and the most recent net9 preview tag from runtime:
v9.0.0-preview.5.24306.7
Expected behavior:
ELFs should be like other items generated for TargetOS:
Actual behavior:
The resulting
runtime.freebsd-x64.Microsoft.DotNet.ILCompiler.9.0.0-preview.5.24306.7.nupkg
contains Linux ELFs and FreeBSD libs.Regression:
To the best of my knowledge, it has always been this way. This was uncaught until recently when I tried to use a cross built package to bootstrap a native build.
Known Workarounds:
None?
Other info:
TargetOS=linux
only appears three places in the .binlog for the build that are after Evaluation. All three are from ILCompiler.cspoj : The first seems to come as a return from ResolveReadyToRunCompilers and the other two (_PrepareForReadyToRunCompilation) and (_CreateR2RImages) use it.NativeAotSupported
is reassigned here:runtime/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj
Line 17 in a5cc707
ilc
binary and the process does not error fromruntime/src/tasks/Crossgen2Tasks/ResolveReadyToRunCompilers.cs
Lines 116 to 120 in a5cc707
There is no "Property reassignment" note in the binlog when ResolveReadyToRunCompilers changes(?) the
TargetOS=freebsd
tolinux
.binlog is not an allowed attachment type so hopefully a screenshot from the MSBuild Structured Log Viewer is enough to help explain what I am seeing.
The Crossgen2 project seems to avoid the ReadyToRun part during packaging:
runtime/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Crossgen2.sfxproj
Lines 52 to 53 in a5cc707
The text was updated successfully, but these errors were encountered: