Skip to content
New issue

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

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

Already on GitHub? # to your account

[RISC-V] Optimizing assemblies for size failed #96978

Closed
dkurt opened this issue Jan 15, 2024 · 17 comments · Fixed by #101038
Closed

[RISC-V] Optimizing assemblies for size failed #96978

dkurt opened this issue Jan 15, 2024 · 17 comments · Fixed by #101038
Labels
arch-riscv Related to the RISC-V architecture area-crossgen2-coreclr in-pr There is an active PR which will close this issue when it is merged

Comments

@dkurt
Copy link
Contributor

dkurt commented Jan 15, 2024

Description

On 8.0 release runtime can be built with the following command without any issues:

cd runtime
./build.sh --ci -c Release --cross --arch riscv64

However there is an error on the upcoming 9.x:

error NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false. [/__w/dotnet_riscv/dotnet_riscv/runtime/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj]

@ashaurtaev, I'm not totally sure that this is related to #95188 but I were able to pass building process by using Mono by default. Sorry, not an expect of Dotnet and I don't know the relationship between Mono and Crossgen2, but this might be a kind of regression.

Reproduction Steps

./build.sh --ci -c Release --cross --arch riscv64

Expected behavior

successful build process

Actual behavior

error NETSDK1144

Regression?

No response

Known Workarounds

workaround by patching eng/Subsets.props, but that doesn’t seem correct.

--- a/eng/Subsets.props
+++ b/eng/Subsets.props
@@ -29,6 +29,7 @@
     <DefaultPrimaryRuntimeFlavor>CoreCLR</DefaultPrimaryRuntimeFlavor>
     <DefaultPrimaryRuntimeFlavor Condition="'$(TargetArchitecture)' == 'armv6'">Mono</DefaultPrimaryRuntimeFlavor>
     <DefaultPrimaryRuntimeFlavor Condition="'$(TargetArchitecture)' == 'ppc64le'">Mono</DefaultPrimaryRuntimeFlavor>
+    <DefaultPrimaryRuntimeFlavor Condition="'$(TargetArchitecture)' == 'riscv64'">Mono</DefaultPrimaryRuntimeFlavor>
     <DefaultPrimaryRuntimeFlavor Condition="'$(TargetArchitecture)' == 's390x'">Mono</DefaultPrimaryRuntimeFlavor>
     <DefaultPrimaryRuntimeFlavor Condition="'$(TargetsLinuxBionic)' == 'true'">Mono</DefaultPrimaryRuntimeFlavor>
     <DefaultPrimaryRuntimeFlavor Condition="'$(TargetsMobile)' == 'true'">Mono</DefaultPrimaryRuntimeFlavor>

Configuration

Docker image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-22.04-cross-riscv64
export ROOTFS_DIR=/crossrootfs/riscv64

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 15, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jan 15, 2024
@jkotas jkotas added arch-riscv Related to the RISC-V architecture area-crossgen2-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jan 15, 2024
@dkurt
Copy link
Contributor Author

dkurt commented Jan 17, 2024

git bisect blames #92677

04d38d8e7becb912494d097133f8124928d5dbbb is the first bad commit
commit 04d38d8e7becb912494d097133f8124928d5dbbb
Author: Jeremy Koritzinsky <jekoritz@microsoft.com>
Date:   Fri Sep 29 10:15:29 2023 -0700

    Use a different crossgen2 when running crossgen2 during our build than the crossgen2 that we are shipping (#92677)

 eng/Subsets.props                                  |   2 +-
 eng/targetingpacks.targets                         |   6 +-
 src/coreclr/crossgen-corelib.proj                  |   3 +-
 src/coreclr/tools/aot/crossgen2/crossgen2.csproj   | 119 ++-------------------
 src/coreclr/tools/aot/crossgen2/crossgen2.props    |   1 -
 .../tools/aot/crossgen2/crossgen2_crossarch.csproj |   8 --
 .../tools/aot/crossgen2/crossgen2_inbuild.csproj   |   9 ++
 .../tools/aot/crossgen2/crossgen2_publish.csproj   | 105 ++++++++++++++++++
 .../Microsoft.NETCore.App.Crossgen2.sfxproj        |  42 +++-----
 .../sfx/Microsoft.NETCore.App/ReadyToRun.targets   |   4 +-
 10 files changed, 146 insertions(+), 153 deletions(-)
 delete mode 100644 src/coreclr/tools/aot/crossgen2/crossgen2_crossarch.csproj
 create mode 100644 src/coreclr/tools/aot/crossgen2/crossgen2_inbuild.csproj
 create mode 100644 src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj

/cc @jkoritzinsky

@ashaurtaev
Copy link
Contributor

ashaurtaev commented Jan 17, 2024

@dkurt Crossgen2 for RiscV64 is under development, it is currently disabled and should not be used in the build.

cc @gbalykov @clamp03

@dkurt
Copy link
Contributor Author

dkurt commented Jan 17, 2024

@ashaurtaev, seems like it applied during the build. Which option disables crossgen2?

@ashaurtaev
Copy link
Contributor

@dkurt I tried to build runtime with your options(./build.sh --ci -c Release --cross --arch riscv64) in the state before my commit, on commit 7957edc, the result is the same, the error occurred earlier, it is necessary to investigate the problem.
The error:

/home/runtime/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets(138,5): error MSB6006: "dotnet" exited with code 134. [/home/runtime/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj]
/home/runtime/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets(91,5): error NETSDK1144: Optimizing assemblies for size failed. Optimization can be disabled by setting the PublishTrimmed property to false. [/home/runtime/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj]

@dkurt
Copy link
Contributor Author

dkurt commented Jan 22, 2024

@ashaurtaev, The latest good commit is 571df3e, so the problem is not related to #95188, sorry for misleading.

@dkurt dkurt closed this as completed Mar 14, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Mar 14, 2024
@dkurt dkurt reopened this Mar 22, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Mar 22, 2024
@dkurt
Copy link
Contributor Author

dkurt commented Mar 22, 2024

Unfortunately, issue still reproduced

@clamp03
Copy link
Member

clamp03 commented Mar 25, 2024

@jbevain Hi, IMO, the issue is related to that Mono.Cecil doesn't have RiscV64 in TargetArchitecture.
https://github.com/jbevain/cecil/blob/56d4409b8a0165830565c6e3f96f41bead2c418b/Mono.Cecil/ModuleKind.cs#L28-L35
Could you check and give any guide to fix this issue?

Error message what I saw is (@dkurt Could you check the error message is different of yours?)

  Successfully created package '/home/clamp/Work/dotnet/riscv/runtime3/artifacts/packages/Release/Shipping/Microsoft.NETCore.App.Host.linux-riscv64.9.0.0-ci.nupkg'.
  Successfully created package '/home/clamp/Work/dotnet/riscv/runtime3/artifacts/packages/Release/Shipping/Microsoft.NETCore.App.Host.linux-riscv64.9.0.0-ci.symbols.nupkg'.
  crossgen2_publish -> /home/clamp/Work/dotnet/riscv/runtime3/artifacts/bin/crossgen2_publish/riscv64/Release/crossgen2.dll
  Optimizing assemblies for size. This process might take a while.
ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink [/home/clamp/Work/dotnet/riscv/runtime3/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj]
##vso[task.logissue type=error;sourcepath=ILLink;linenumber=0;columnnumber=0;code=IL1012;](NETCORE_ENGINEERING_TELEMETRY=Build) IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink
  Fatal error in IL Linker
  Unhandled exception. System.BadImageFormatException: unrecognized module attributes
     at Mono.Linker.Steps.OutputStep.CalculateArchitecture(TargetArchitecture readyToRunArch) in /_/src/tools/illink/src/linker/Linker.Steps/OutputStep.cs:line 80
     at Mono.Linker.Steps.OutputStep.WriteAssembly(AssemblyDefinition assembly, String directory, WriterParameters writerParameters) in /_/src/tools/illink/src/linker/Linker.Steps/OutputStep.cs:line 129
     at Mono.Linker.Steps.OutputStep.WriteAssembly(AssemblyDefinition assembly, String directory) in /_/src/tools/illink/src/linker/Linker.Steps/OutputStep.cs:line 119
     at Mono.Linker.Steps.OutputStep.OutputAssembly(AssemblyDefinition assembly) in /_/src/tools/illink/src/linker/Linker.Steps/OutputStep.cs:line 155
     at Mono.Linker.Steps.OutputStep.ProcessAssembly(AssemblyDefinition assembly) in /_/src/tools/illink/src/linker/Linker.Steps/OutputStep.cs:line 114
     at Mono.Linker.Steps.BaseStep.Process(LinkContext context) in /_/src/tools/illink/src/linker/Linker.Steps/BaseStep.cs:line 70
     at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step) in /_/src/tools/illink/src/linker/Linker/Pipeline.cs:line 178
     at Mono.Linker.Pipeline.Process(LinkContext context) in /_/src/tools/illink/src/linker/Linker/Pipeline.cs:line 167
     at Mono.Linker.Driver.Run(ILogger customLogger) in /_/src/tools/illink/src/linker/Linker/Driver.cs:line 818
     at Mono.Linker.Driver.Main(String[] args) in /_/src/tools/illink/src/linker/Linker/Driver.cs:line 68
/home/clamp/Work/dotnet/riscv/runtime3/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets(91,5): error NETSDK1144: Optimizing assemblies for size failed. [/home/clamp/Work/dotnet/riscv/runtime3/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj]
##vso[task.logissue type=error;sourcepath=/home/clamp/Work/dotnet/riscv/runtime3/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets;linenumber=91;columnnumber=5;code=NETSDK1144;](NETCORE_ENGINEERING_TELEMETRY=Build) Optimizing assemblies for size failed.

Build FAILED.

ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink [/home/clamp/Work/dotnet/riscv/runtime3/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj]
/home/clamp/Work/dotnet/riscv/runtime3/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets(91,5): error NETSDK1144: Optimizing assemblies for size failed. [/home/clamp/Work/dotnet/riscv/runtime3/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj]
    0 Warning(s)
    2 Error(s)

@dkurt
Copy link
Contributor Author

dkurt commented Mar 25, 2024

@clamp03, the error message and related file are the same:

  crossgen2_publish -> /__w/dotnet_riscv/dotnet_riscv/runtime/artifacts/bin/crossgen2_publish/riscv64/Release/crossgen2.dll
  Optimizing assemblies for size. This process might take a while.
ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink [/__w/dotnet_riscv/dotnet_riscv/runtime/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj]
##vso[task.logissue type=error;sourcepath=ILLink;linenumber=0;columnnumber=0;code=IL1012;](NETCORE_ENGINEERING_TELEMETRY=Build) IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink
  Fatal error in IL Linker
  Unhandled exception. System.BadImageFormatException: unrecognized module attributes
     at Mono.Linker.Steps.OutputStep.CalculateArchitecture(TargetArchitecture readyToRunArch) in /_/src/tools/illink/src/linker/Linker.Steps/OutputStep.cs:line 79
     at Mono.Linker.Steps.OutputStep.WriteAssembly(AssemblyDefinition assembly, String directory, WriterParameters writerParameters) in /_/src/tools/illink/src/linker/Linker.Steps/OutputStep.cs:line 128
     at Mono.Linker.Steps.OutputStep.WriteAssembly(AssemblyDefinition assembly, String directory) in /_/src/tools/illink/src/linker/Linker.Steps/OutputStep.cs:line 118
     at Mono.Linker.Steps.OutputStep.OutputAssembly(AssemblyDefinition assembly) in /_/src/tools/illink/src/linker/Linker.Steps/OutputStep.cs:line 154
     at Mono.Linker.Steps.OutputStep.ProcessAssembly(AssemblyDefinition assembly) in /_/src/tools/illink/src/linker/Linker.Steps/OutputStep.cs:line 113
     at Mono.Linker.Steps.BaseStep.Process(LinkContext context) in /_/src/tools/illink/src/linker/Linker.Steps/BaseStep.cs:line 70
     at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step) in /_/src/tools/illink/src/linker/Linker/Pipeline.cs:line 178
     at Mono.Linker.Pipeline.Process(LinkContext context) in /_/src/tools/illink/src/linker/Linker/Pipeline.cs:line 167
     at Mono.Linker.Driver.Run(ILogger customLogger) in /_/src/tools/illink/src/linker/Linker/Driver.cs:line 818
     at Mono.Linker.Driver.Main(String[] args) in /_/src/tools/illink/src/linker/Linker/Driver.cs:line 68
/__w/dotnet_riscv/dotnet_riscv/runtime/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets(91,5): error NETSDK1144: Optimizing assemblies for size failed. [/__w/dotnet_riscv/dotnet_riscv/runtime/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj]
##vso[task.logissue type=error;sourcepath=/__w/dotnet_riscv/dotnet_riscv/runtime/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets;linenumber=91;columnnumber=5;code=NETSDK1144;](NETCORE_ENGINEERING_TELEMETRY=Build) Optimizing assemblies for size failed.

Build FAILED.

ILLink : error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink [/__w/dotnet_riscv/dotnet_riscv/runtime/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj]
/__w/dotnet_riscv/dotnet_riscv/runtime/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets(91,5): error NETSDK1144: Optimizing assemblies for size failed. [/__w/dotnet_riscv/dotnet_riscv/runtime/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj]
    0 Warning(s)
    2 Error(s)

@clamp03
Copy link
Member

clamp03 commented Mar 25, 2024

@dkurt This is a workaround what I think until cecil supports RiscV64. It just disables trim for RiscV64.

diff --git a/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj b/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj
index 657ac23590a..06fc4c983c6 100644
--- a/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj
+++ b/src/coreclr/tools/aot/crossgen2/crossgen2_publish.csproj
@@ -12,7 +12,7 @@
     <NativeAotSupported Condition="$(OutputRID.EndsWith('-x86')) == 'true'">false</NativeAotSupported>
     <!-- Publish crossgen2 as a single-file app on native-OS builds. Cross-OS NativeAOT compilation is not supported yet -->
     <NativeAotSupported Condition="'$(CrossBuild)' == 'true' and '$(TargetOS)' != '$(HostOS)'">false</NativeAotSupported>
-    <PublishTrimmed>true</PublishTrimmed>
+    <PublishTrimmed Condition="'$(TargetArchitecture)' != 'riscv64'">true</PublishTrimmed>
     <RuntimeIdentifier>$(PackageRID)</RuntimeIdentifier>
     <SelfContained>true</SelfContained>
     <TargetFramework>$(NetCoreAppCurrent)</TargetFramework>

Thank you.

@dkurt
Copy link
Contributor Author

dkurt commented Mar 25, 2024

@clamp03, this workaround seems working for me, thanks.

@clamp03
Copy link
Member

clamp03 commented Mar 25, 2024

Pushed cecil PR jbevain/cecil#940
cc @dotnet/samsung

@clamp03
Copy link
Member

clamp03 commented Apr 4, 2024

@jkotas I made a PR on https://github.com/jbevain/cecil. I found forked repo in dotnet/cecil. Should I make a PR for https://github.com/dotnet/cecil? Thank you.

@jkotas
Copy link
Member

jkotas commented Apr 4, 2024

Pushed cecil PR jbevain/cecil#940

@dotnet/illink How would you prefer this change to be handled?

@clamp03
Copy link
Member

clamp03 commented Apr 9, 2024

Pushed cecil PR jbevain/cecil#940

@dotnet/illink How would you prefer this change to be handled?

@dotnet/illink Could you please give any comment? Thank you!

@vitek-karas
Copy link
Member

@sbomer @agocke for better visibility maybe.

@sbomer
Copy link
Member

sbomer commented Apr 9, 2024

@clamp03, yes, please also make a PR in the https://github.com/dotnet/cecil fork. We can take changes there, but also want to make sure they get upstreamed (so please keep jbevain/cecil#940 open).

@clamp03
Copy link
Member

clamp03 commented Apr 9, 2024

@sbomer Thank you. I made a PR. dotnet/cecil#171

@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Apr 15, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Apr 15, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 16, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
arch-riscv Related to the RISC-V architecture area-crossgen2-coreclr in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants