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

gcc fails to arch-cross-compile on GNU/Linux in NativeAOT .NET 7 #78559

Closed
WhiteBlackGoose opened this issue Nov 18, 2022 · 16 comments
Closed

gcc fails to arch-cross-compile on GNU/Linux in NativeAOT .NET 7 #78559

WhiteBlackGoose opened this issue Nov 18, 2022 · 16 comments

Comments

@WhiteBlackGoose
Copy link
Contributor

Description

Getting an error

gcc : error : unrecognized command-line option '--target=aarch64-linux-gnu'

When trying to compile my app for ARM64 while being on x86 64bit laptop

Reproduction Steps

  1. dotnet new console -n frog && cd frog
  2. dotnet publish -p:PublishAot=true -p:SelfContained=true -r linux-arm64

Expected behavior

Compiles

Actual behavior

Doesn't compile:

$ dotnet publish -p:PublishAot=true -p:SelfContained=true -r linux-arm64
MSBuild version 17.4.0+18d5aef85 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  frog -> /home/goose/sandbox-1668781319/frog/bin/Debug/net7.0/linux-arm64/frog.dll
  Generating native code
gcc : error : unrecognized command-line option '--target=aarch64-linux-gnu' [/home/goose/sandbox-1668781319/frog/frog.csproj]
/home/goose/programs/dotnet-folder/sdk/7.0.100/Sdks/Microsoft.DotNet.ILCompiler/build/Microsoft.NETCore.Native.targets(346,5): error MSB3073: The command ""gcc" "obj/Debug/net7.0/linux-arm64/native/frog.o" -o "bin/Debug/net7.0/linux-arm64/native/frog" /home/goose/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/7.0.0/sdk/libbootstrapper.a /home/goose/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/7.0.0/sdk/libRuntime.WorkstationGC.a /home/goose/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/7.0.0/framework/libSystem.Native.a /home/goose/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/7.0.0/framework/libSystem.Globalization.Native.a /home/goose/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/7.0.0/framework/libSystem.IO.Compression.Native.a /home/goose/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/7.0.0/framework/libSystem.Net.Security.Native.a /home/goose/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/7.0.0/framework/libSystem.Security.Cryptography.Native.OpenSsl.a --target=aarch64-linux-gnu -g -Wl,-rpath,'$ORIGIN' -Wl,--build-id=sha1 -Wl,--as-needed -pthread -lstdc++ -ldl -lm -lz -lrt -pie -Wl,-z,relro -Wl,-z,now -Wl,--discard-all -Wl,--gc-sections" exited with code 1. [/home/goose/sandbox-1668781319/frog/frog.csproj]

Regression?

No response

Known Workarounds

No response

Configuration

  1. 7.0.100
  2. debian 12 sid bookworm
  3. x86 64-bit
  4. gcc (Debian 12.2.0-9) 12.2.0
  5. aarch64-linux-gnu-gcc (Debian 12.2.0-9) 12.2.0
  6. No clang installed

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 18, 2022
@ghost
Copy link

ghost commented Nov 18, 2022

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Getting an error

gcc : error : unrecognized command-line option '--target=aarch64-linux-gnu'

When trying to compile my app for ARM64 while being on x86 64bit laptop

Reproduction Steps

  1. dotnet new console -n frog && cd frog
  2. dotnet publish -p:PublishAot=true -p:SelfContained=true -r linux-arm64

Expected behavior

Compiles

Actual behavior

Doesn't compile:

$ dotnet publish -p:PublishAot=true -p:SelfContained=true -r linux-arm64
MSBuild version 17.4.0+18d5aef85 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  frog -> /home/goose/sandbox-1668781319/frog/bin/Debug/net7.0/linux-arm64/frog.dll
  Generating native code
gcc : error : unrecognized command-line option '--target=aarch64-linux-gnu' [/home/goose/sandbox-1668781319/frog/frog.csproj]
/home/goose/programs/dotnet-folder/sdk/7.0.100/Sdks/Microsoft.DotNet.ILCompiler/build/Microsoft.NETCore.Native.targets(346,5): error MSB3073: The command ""gcc" "obj/Debug/net7.0/linux-arm64/native/frog.o" -o "bin/Debug/net7.0/linux-arm64/native/frog" /home/goose/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/7.0.0/sdk/libbootstrapper.a /home/goose/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/7.0.0/sdk/libRuntime.WorkstationGC.a /home/goose/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/7.0.0/framework/libSystem.Native.a /home/goose/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/7.0.0/framework/libSystem.Globalization.Native.a /home/goose/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/7.0.0/framework/libSystem.IO.Compression.Native.a /home/goose/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/7.0.0/framework/libSystem.Net.Security.Native.a /home/goose/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/7.0.0/framework/libSystem.Security.Cryptography.Native.OpenSsl.a --target=aarch64-linux-gnu -g -Wl,-rpath,'$ORIGIN' -Wl,--build-id=sha1 -Wl,--as-needed -pthread -lstdc++ -ldl -lm -lz -lrt -pie -Wl,-z,relro -Wl,-z,now -Wl,--discard-all -Wl,--gc-sections" exited with code 1. [/home/goose/sandbox-1668781319/frog/frog.csproj]

Regression?

No response

Known Workarounds

No response

Configuration

  1. 7.0.100
  2. debian 12 sid bookworm
  3. x86 64-bit
  4. gcc (Debian 12.2.0-9) 12.2.0
  5. aarch64-linux-gnu-gcc (Debian 12.2.0-9) 12.2.0
  6. No clang installed

Other information

No response

Author: WhiteBlackGoose
Assignees: -
Labels:

untriaged, area-NativeAOT-coreclr

Milestone: -

@am11
Copy link
Member

am11 commented Nov 18, 2022

We haven't tested cross-compilation with gcc, so this is unsupported. We can add support for it. However, there are few things to consider:

  • clang has multi targets support (and hence -target/--target options are supported), but gcc only has one main target for which it was built for. We don't check the compiler flavor when setting this option (which is a bug).
  • user will need to install target specific gcc toolchain to be able to use gcc for cross compilation.

You can install clang (or use a docker image) for the cross-compilation in the meantime.

@jkotas
Copy link
Member

jkotas commented Nov 18, 2022

Cross-compilation instructions are at https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/compiling.md#cross-architecture-compilation . Cross-compilation on Linux requires rootfs and target architecture native toolchain to be present.

@am11
Copy link
Member

am11 commented Nov 18, 2022

Yup, those instructions apply only to clang, because this argument is not supported on gcc:

<LinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetOS)' != 'OSX' and '$(TargetTriple)' != ''" />

@WhiteBlackGoose
Copy link
Contributor Author

I see.
While we're at it, is there anything for OS X that has to be referenced? (I see only windows and linux mentioned in the instruction)

@am11
Copy link
Member

am11 commented Nov 18, 2022

macOS is not supported in .NET 7. It is only available in the daily builds of .NET 8. We can update the document. Basically only cross-architecture is supported on OSX (not linux to osx). For example on M1 machine (osx-arm64), we can use:

$ dotnet8 publish -p:PublishAot=true --arch x64

to cross-compile x64 binary.

@WhiteBlackGoose
Copy link
Contributor Author

macOS is not supported in .NET 7

Without cross-compilation it works though 🤔

@am11
Copy link
Member

am11 commented Nov 18, 2022

Without cross-compilation it works though 🤔

Yes, for osx-x64 but osx-arm64 is only supported in .NET 8.

@WhiteBlackGoose
Copy link
Contributor Author

Got it. Any reason why btw? It requires additional work or something else?

@WhiteBlackGoose
Copy link
Contributor Author

Also, is arch-cross-compilation only available in .NET 8?

@am11
Copy link
Member

am11 commented Nov 18, 2022

osx-arm64 support was implemented in #75264 (merged three days before the 7.0 RC1 release), and number of fixes went in main branch after that. Normally new platform support PRs are not backported, when there was no time spent on testing during the development cycle.

Also, is arch-cross-compilation only available in .NET 8?

Yes, because for OSX we only support cross-architecture compilation (and not cross-OS compilation), so it was not necessary when only one architecture was supported.

@WhiteBlackGoose
Copy link
Contributor Author

I mean, what about other OS? Is there arch-cross-compilation for linux on .NET 7?

@am11
Copy link
Member

am11 commented Nov 18, 2022

Yes. On linux, cross-compilation is supported with clang only. Normal compilation is supported with both clang and gcc.

@WhiteBlackGoose
Copy link
Contributor Author

Thanks, is there any specific instruction or should work out of the box? (trying to get through an issue issue right now with it)

@agocke
Copy link
Member

agocke commented Nov 18, 2022

Instructions are here https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/compiling.md#cross-architecture-compilation. They do require a "sysroot" that contains the arm64 toolchain, esp. glibc. I did have some success getting this to work on Ubuntu by pulling in arm64 packages, but I haven't written anything up yet.

@agocke agocke added this to the 8.0.0 milestone Nov 21, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Nov 21, 2022
@agocke
Copy link
Member

agocke commented Jun 21, 2023

Closing as answered

@agocke agocke closed this as not planned Won't fix, can't repro, duplicate, stale Jun 21, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jul 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

4 participants