Repository navigation
Description
Description
I am seeing variants of this error on Fedora ELN and CentOS Stream 10, with .NET 8 and .NET 9.
With .NET 8, I see this when building the VMR:
ILCompiler.Diagnostics -> dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/ILCompiler.Diagnostics/x64/Release/ILCompiler.Diagnostics.dll
ILCompiler.ReadyToRun -> dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/ILCompiler.ReadyToRun/x64/Release/ILCompiler.ReadyToRun.dll
crossgen2_publish -> dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/crossgen2.dll
Optimizing assemblies for size. This process might take a while.
crossgen2_publish -> dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/
Microsoft.NETCore.App.Crossgen2 ->
Failed to locate managed application [dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2]
dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Crossgen2.sfxproj(67,5): error MSB3073: The command "dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/crossgen2 dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/coreclr/linux.x64.Release/IL/System.Private.CoreLib.dll --out dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/obj/Microsoft.NETCore.App.Crossgen2/Release/net8.0/fedora.42-x64/S.P.C.tmp" exited with code 146.
Trying to trace this shows:
COREHOST_TRACE=1 dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/crossgen2 dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/coreclr/linux.x64.Release/IL/System.Private.CoreLib.dll --out dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/obj/Microsoft.NETCore.App.Crossgen2/Release/net8.0/fedora.42-x64/S.P.C.tmp
Tracing enabled @ Thu Nov 7 13:41:40 2024 GMT
--- Invoked apphost [version: 8.0.10 @Commit: 81cabf2857a01351e5ab578947c7403a5b128ad1] main = {
dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/crossgen2
dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/coreclr/linux.x64.Release/IL/System.Private.CoreLib.dll
--out
dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/obj/Microsoft.NETCore.App.Crossgen2/Release/net8.0/fedora.42-x64/S.P.C.tmp
}
The managed DLL bound to this executable is: 'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2'
Detected Single-File app bundle
Using internal fxr
Invoking fx resolver [dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/] hostfxr_main_bundle_startupinfo
Host path: [dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/crossgen2]
Dotnet path: [dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/]
App path: [dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2]
Bundle Header Offset: [99398693]
--- Invoked hostfxr_main_bundle_startupinfo [version: 8.0.10 @Commit: 81cabf2857a01351e5ab578947c7403a5b128ad1]
Mapped application bundle
Unmapped application bundle
Single-File bundle details:
DepsJson Offset:[5ec8f80] Size[24a5]
RuntimeConfigJson Offset:[4f4f5a8] Size[5b4]
.net core 3 compatibility mode: [No]
--- Executing in a native executable mode...
Using dotnet root path [dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/]
App runtimeconfig.json from [dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2]
Runtime config is cfg=dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2.runtimeconfig.json dev=dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2.runtimeconfig.dev.json
Attempting to read dev runtime config: dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2.runtimeconfig.dev.json
Attempting to read runtime config: dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2.runtimeconfig.json
Mapped bundle for [dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2.runtimeconfig.json]
Unmapped application bundle
Runtime config [dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2.runtimeconfig.json] is valid=[1]
Executing as a self-contained app as per config file [dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2.runtimeconfig.json]
Using internal hostpolicy
Reading from host interface version: [0x16041101:248] to initialize policy version: [0x16041101:248]
Mapped application bundle
Unmapped application bundle
--- Invoked hostpolicy [version: 8.0.10 @Commit: 81cabf2857a01351e5ab578947c7403a5b128ad1] corehost_main = {
dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/crossgen2
dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/coreclr/linux.x64.Release/IL/System.Private.CoreLib.dll
--out
dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/obj/Microsoft.NETCore.App.Crossgen2/Release/net8.0/fedora.42-x64/S.P.C.tmp
}
Mode: apphost
Deps file:
Managed application [c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2] not found in single-file bundle
Failed to locate managed application [otnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/bin/crossgen2_publish/x64/Release/fedora.42-x64/publish/c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2]
On CentOS Stream 10, the VMR is built successfully, but the produced SDK fails to run with similar symptoms.
Reproduction Steps
On Fedora:
$ fedpkg clone -a dotnet8.0
$ cd dotnet8.0
$ fedpkg --namespace rpms --name dotnet8.0 --release eln mockbuild --no-cleanup-after
Expected behavior
.NET builds
Actual behavior
VMR fails to build, or the generated SDK is broken.
Regression?
Yes.
I don't see this behaviour on Fedora 41, or CentOS Stream 8 or 9.
Known Workarounds
No response
Configuration
$ clang --version
clang version 19.1.0 (Fedora 19.1.0-1.eln143)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Configuration file: /etc/clang/x86_64-redhat-linux-gnu-clang.cfg
Other information
I had to port #109198 first, to build against clang 19. But clang 19 is also used on Fedora 41, and that doesn't show the same issue.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsNo status
Activity
dotnet-policy-service commentedon Nov 7, 2024
Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov
See info in area-owners.md if you want to be subscribed.
elinor-fung commentedon Nov 11, 2024
That is the placeholder that should get replaced by the SDK during build:
runtime/src/native/corehost/corehost.cpp
Lines 39 to 40 in 075b42d
runtime/src/installer/managed/Microsoft.NET.HostModel/AppHost/HostWriter.cs
Lines 90 to 91 in 075b42d
We do explicitly check whether the placeholder value is the same though, so I am confused as to why we don't hit this check:
runtime/src/native/corehost/corehost.cpp
Lines 71 to 82 in 075b42d
It seems like on those platforms, the
crossgen2executable is somehow (reported as) successfully produced, but without actually updating the placeholder? Do you have a binlog for the build/publish ofcrossgen2itself?omajid commentedon Nov 20, 2024
Yes, I think so. This is a VMR build, so looking for the placeholder value shows
apphostandsinglefilehost(which are expected), and alsocrossgen2(unexpected). There's also/builddir/build/BUILD/dotnet8.0-8.0.110-build/dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/obj/coreclr/crossgen2_publish/x64/Release/singlefilehostwhich, if I am reading the binlog right, is the intermediate (?) apphost for crossgen2.Here's the binlog of the VMR. The VMR produces this broken crossgen2 that then fails to run: https://people.redhat.com/~omajid/scratch/crossgen2-placeholder-sourcebuild.binlog
This was built using a source-built SDK itself. That SDK can produce an
mkdir foobar && cd foobar && dotnet new console && dotnet run && bin/Debug/net8.0/foobarwithout problems.elinor-fung commentedon Nov 21, 2024
I can't open that binlog for some reason. I get
System.IO.InvalidDataException: Found invalid data while decodingwhen trying to open it in the latest MSBuild log viewer.Yes, that is the intermediate apphost for crossgen2. That is what should have the app name instead of the placeholder in the binary (it just gets copied to the output directory). In the correct/working case, we should have already updated the bytes in our memory mapped view of the original apphost before writing it to that obj/ location:
runtime/src/installer/managed/Microsoft.NET.HostModel/AppHost/HostWriter.cs
Lines 87 to 91 in 9cb3b72
I would expect for there to be some failure / exception thrown if we failed to find/update the placeholder in the memory mapped view though.
Is there anything different with access/permissions for the crossgen2 intermediate output (./build/BUILD/dotnet8.0-8.0.110-build/dotnet-8.0.10/src/runtime/artifacts/source-build/self/src/artifacts/obj/coreclr/crossgen2_publish/x64/Release/) versus other folders?
Does the source-built SDK itself produce a self-contained single-file
dotnet publish --sc /p:PublishSelfContained=truethat runs fine?I wonder if there's something different with memory mapping files that what we are doing isn't working properly with. That's the part of the sequence of 'memory map the original, search/replace in private memory mapped view, then write to output' that seems like it might be affected by an OS upgrade.
omajid commentedon Nov 25, 2024
Sorry about that. That server seems to mess with file compression in http response and since binlogs are compressed files, the uncompression breaks the binlog.
Can you try this version: https://people.redhat.com/~omajid/scratch/crossgen2-placeholder-sourcebuild.binlog.tar.gz ? It should extract to a
sourcebuild.binlogwith sha256sum of00ae8439efa285a6edfc93bfb007947b3562691137214f5d9cfe6185356062faYes:
I was able to narrow it to something to do with the singlefile host itself. In a
dotnet new console, I could make this change to reproduce the problem:Building this with the apphost from the current build of the VMR produces a broken application:
But using the one from the SDK itself produces a working archive:
elinor-fung commentedon Nov 25, 2024
Thanks - I am able to open it now.
Oh, that is definitely interesting (also confusing). So same
Microsoft.NET.Build.Tasks.dll(andMicrosoft.NET.HostModel.dll) from the SDK itself, but the current VMRsinglefilehostversus the SDKsinglefilehostis the difference.From the binlog,
crossgen2is the only one using the current VMRsinglefilehost(ilcuses the previously build SDK -/builddir/build/BUILD/dotnet8.0-8.0.110-build/dotnet-8.0.10/previously-built-dotnet/packs/Microsoft.NETCore.App.Host.fedora.42-x64/8.0.8/runtimes/fedora.42-x64/native/singlefilehost), so it is the only one affected here.Would you be able to share the broken/working
singlefilehosts from the current VMR build/previously source-built SDK?I did also try to get myself a repro. I am admittedly completely unfamiliar with fedpkg/mockbuild - where are the outputs after doing the build? After running
fedpkg --namespace rpms --name dotnet8.0 --release eln mockbuild --no-cleanup-after(I am on WSL Ubuntu 22.04 running Fedora in a docker container), I'm not sure where the artifacts are. I assumed the --no-cleanup-after flag meant I would still have the intermediate build artifacts after the failure - I have an empty dotnet8.0-8.0.111-build folder and a results_dotnet8.0 folder that just has *.log files.omajid commentedon Nov 26, 2024
https://people.redhat.com/~omajid/scratch/hosts.tar.gz
Sorry about the lack of guidance on this earlier.
mockis essentially a docker container, invented before containers were formalized. Mock uses a single container instance for each os/release/arch combination with a name computed based on that. In our case, it'sfedora-eln-x86_64.I use
mock --shellto get into the "container" used to run the build. I also enable networking so I can restore packages and rundotnet. So that would look like this:mock --enable-network -r fedora-eln-x86_64 --shell.When I need additional tools, I run
mock -r fedora-eln-x86_64 --install strace(and replace strace with the package name of the tool I want). That will install the tool into the container.There is a
mock --copyinandmock --copyoutcommand to get files into and out of the container. I generally skip that and append the path inside the container to the well-known path of the container. In this case, the prefix is/var/lib/mock/fedora-eln-x86_64/root. We can join it to a path like/usr/bin/echoinside the container, which makes it/var/lib/mock/fedora-eln-x86_64/root/usr/bin/echoon the host (outside the container).Many
mockcommands will wipe the "container", so I try and be a bit careful, and use the--no-cleanupflag as much as possible.omajid commentedon Nov 26, 2024
I added some instrumentation to
BinaryUtils.csand then extracted it to a standalone tool to run.In the working scenario:
KMPSearchfinds apositionof11067888KMPSearchfinds apositionof-1In the broken scenario:
KMPSearchfinds apositionof8756096KMPSearchfinds apositionof11092256Now I am wondering: did the compiler embed multiple copies of the pattern in the
singlefilehostbinary? Does theHostWriterreplace the wrong one?Edit: Yeah:
elinor-fung commentedon Nov 26, 2024
Having the placeholder in there twice would definitely break assumptions made when creating the apphost.
I can see that the second occurrence at 11092256 / 0xa94120 maps to the symbol we expect, but I don't know where the first one at 8756096 / 859b80 is coming from:
One thing that also stood out to me is just how much bigger the broken
singlefilehostis - 11 MB vs 81 MB.9 remaining items
omajid commentedon Dec 2, 2024
My C++-fu is pretty bad.
Neither of these seem to be helping in my case:
jkotas commentedon Dec 2, 2024
Hmm, suppressing optimizations for memcmp looks tricky. We may need a local implementation of memcmp that uses volatile reads to suppress the memcmp optimizations reliably. Something like this: https://godbolt.org/z/Mz9jcT3Pf
omajid commentedon Dec 6, 2024
Thanks, replacing
binding.compare()with a custom memcp implementation seems to do the trick!Though I am totally lost how you figured that out. Any chance you can teach me?
jkotas commentedon Dec 7, 2024
I opened https://godbolt.org and checked the optimized code generated for volatile data passed into memcmp. I wanted to see a call to memcmp. I did not want to see memcmp recognized as an intrinsic and inlined. It made me realize that the volatile modifier has to be cast away when the data pointer is passed into memcmp, and thus volatile won't prevent memcmp from being recognized as an intrinsic and inlined. It means that we need to have our memcmp that the compiler won't optimize. Alternative solution would be to disable compiler optimizations around the memcmp call using pragma.
omajid commentedon Dec 9, 2024
Thank you!
Avoid all compiler optimization on embedded apphost hash
Avoid all compiler optimization on embedded apphost hash
Avoid all compiler optimization on embedded apphost hash
Avoid all compiler optimization on embedded apphost hash
Avoid all compiler optimization on embedded apphost hash
Avoid all compiler optimization on embedded apphost hash
Avoid all compiler optimization on embedded apphost hash