dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.25k stars 4.73k forks source link

[armel] Assembler syntax error with gcc, but working with clang #75519

Open Z4rc opened 2 years ago

Z4rc commented 2 years ago

Description

Hi,

I am currently trying to get the dotnet runtime v6.0.8 cross compiled for our armel target. My build host is x86_64. It is working great using the clang v12.0.0 compiler, but I get a build error in an assembler part when using gcc v10.3.0:

This is the error message:

[ 95%] Building ASM object vm/wks/CMakeFiles/cee_wks_core.dir//arm/asmhelpers.S.o [ 95%] Building ASM object vm/wks/CMakeFiles/cee_wks_core.dir//arm/ehhelpers.S.o [ 95%] Building ASM object vm/wks/CMakeFiles/cee_wks_core.dir//arm/patchedcode.S.o [ 95%] Building ASM object vm/wks/CMakeFiles/cee_wks_core.dir//arm/pinvokestubs.S.o /tmp/runtime/src/coreclr/vm/arm/asmhelpers.S: Assembler messages: /tmp/runtime/src/coreclr/vm/arm/asmhelpers.S:987: Error: syntax error -- `ldr r2,=JIT_WriteBarrier_Loc-(1f+4)' make[2]: [vm/wks/CMakeFiles/cee_wks_core.dir/__/arm/asmhelpers.S.o] Error 1 make[2]: Waiting for unfinished jobs.... /tmp/runtime/src/coreclr/vm/arm/pinvokestubs.S: Assembler messages: /tmp/runtime/src/coreclr/vm/arm/pinvokestubs.S:86: Error: syntax error -- `ldr r1,=s_gsCookie-(1f+4)' /tmp/runtime/src/coreclr/vm/arm/pinvokestubs.S:96: Error: syntax error -- `ldr r1,=_ZTV16InlinedCallFrame+8-(2f+4)' /tmp/runtime/src/coreclr/vm/arm/pinvokestubs.S:148: Error: syntax error -- `ldr r2,=g_TrapReturningThreads-(1f+4)' make[2]: [vm/wks/CMakeFiles/cee_wks_core.dir/__/arm/pinvokestubs.S.o] Error 1 make[1]: [vm/wks/CMakeFiles/cee_wks_core.dir/all] Error 2 make: *** [all] Error 2 /tmp/runtime/src/coreclr Failed to build "CoreCLR component".

Unfortunately I have no assembler knowledge, but the lines that are causing the errors look very similiar. What suprises me is that I have no issues when using the clang compiler. Is this a missing feature of gcc? Is there a way to adapt the code in a way that gcc understands what to do?

Thanks in advance!

Reproduction Steps

./build.sh --subset clr --arch armel --cross --gcc /p:TargetArchitecture=armel -c Release

Expected behavior

build succeeds, no syntax errors

Actual behavior

Build errors:

/tmp/runtime/src/coreclr/vm/arm/asmhelpers.S: Assembler messages: /tmp/runtime/src/coreclr/vm/arm/asmhelpers.S:987: Error: syntax error -- `ldr r2,=JIT_WriteBarrier_Loc-(1f+4)' /tmp/runtime/src/coreclr/vm/arm/pinvokestubs.S: Assembler messages: /tmp/runtime/src/coreclr/vm/arm/pinvokestubs.S:86: Error: syntax error -- `ldr r1,=s_gsCookie-(1f+4)' /tmp/runtime/src/coreclr/vm/arm/pinvokestubs.S:96: Error: syntax error -- `ldr r1,=_ZTV16InlinedCallFrame+8-(2f+4)' /tmp/runtime/src/coreclr/vm/arm/pinvokestubs.S:148: Error: syntax error -- `ldr r2,=g_TrapReturningThreads-(1f+4)'

Regression?

No response

Known Workarounds

Use clang compiler instead of gcc

Configuration

No response

Other information

No response

ghost commented 2 years ago

Tagging subscribers to this area: @hoyosjs See info in area-owners.md if you want to be subscribed.

Issue Details
### Description Hi, I am currently trying to get the dotnet runtime v6.0.8 cross compiled for our armel target. My build host is x86_64. It is working great using the clang v12.0.0 compiler, but I get a build error in an assembler part when using gcc v10.3.0: This is the error message: [ 95%] Building ASM object vm/wks/CMakeFiles/cee_wks_core.dir/__/arm/asmhelpers.S.o [ 95%] Building ASM object vm/wks/CMakeFiles/cee_wks_core.dir/__/arm/ehhelpers.S.o [ 95%] Building ASM object vm/wks/CMakeFiles/cee_wks_core.dir/__/arm/patchedcode.S.o [ 95%] Building ASM object vm/wks/CMakeFiles/cee_wks_core.dir/__/arm/pinvokestubs.S.o /tmp/runtime/src/coreclr/vm/arm/asmhelpers.S: Assembler messages: /tmp/runtime/src/coreclr/vm/arm/asmhelpers.S:987: Error: syntax error -- \`ldr r2,=JIT_WriteBarrier_Loc-(1f+4)' make[2]: *** [vm/wks/CMakeFiles/cee_wks_core.dir/__/arm/asmhelpers.S.o] Error 1 make[2]: *** Waiting for unfinished jobs.... /tmp/runtime/src/coreclr/vm/arm/pinvokestubs.S: Assembler messages: /tmp/runtime/src/coreclr/vm/arm/pinvokestubs.S:86: Error: syntax error -- \`ldr r1,=s_gsCookie-(1f+4)' /tmp/runtime/src/coreclr/vm/arm/pinvokestubs.S:96: Error: syntax error -- \`ldr r1,=_ZTV16InlinedCallFrame+8-(2f+4)' /tmp/runtime/src/coreclr/vm/arm/pinvokestubs.S:148: Error: syntax error -- \`ldr r2,=g_TrapReturningThreads-(1f+4)' make[2]: *** [vm/wks/CMakeFiles/cee_wks_core.dir/__/arm/pinvokestubs.S.o] Error 1 make[1]: *** [vm/wks/CMakeFiles/cee_wks_core.dir/all] Error 2 make: *** [all] Error 2 /tmp/runtime/src/coreclr Failed to build "CoreCLR component". Unfortunately I have no assembler knowledge, but the lines that are causing the errors look very similiar. What suprises me is that I have no issues when using the clang compiler. Is this a missing feature of gcc? Is there a way to adapt the code in a way that gcc understands what to do? Thanks in advance! ### Reproduction Steps `./build.sh --subset clr --arch armel --cross --gcc /p:TargetArchitecture=armel -c Release` ### Expected behavior build succeeds, no syntax errors ### Actual behavior Build errors: /tmp/runtime/src/coreclr/vm/arm/asmhelpers.S: Assembler messages: /tmp/runtime/src/coreclr/vm/arm/asmhelpers.S:987: Error: syntax error -- \`ldr r2,=JIT_WriteBarrier_Loc-(1f+4)' /tmp/runtime/src/coreclr/vm/arm/pinvokestubs.S: Assembler messages: /tmp/runtime/src/coreclr/vm/arm/pinvokestubs.S:86: Error: syntax error -- \`ldr r1,=s_gsCookie-(1f+4)' /tmp/runtime/src/coreclr/vm/arm/pinvokestubs.S:96: Error: syntax error -- \`ldr r1,=_ZTV16InlinedCallFrame+8-(2f+4)' /tmp/runtime/src/coreclr/vm/arm/pinvokestubs.S:148: Error: syntax error -- \`ldr r2,=g_TrapReturningThreads-(1f+4)' ### Regression? _No response_ ### Known Workarounds Use clang compiler instead of gcc ### Configuration _No response_ ### Other information _No response_
Author: Z4rc
Assignees: -
Labels: `area-Infrastructure-coreclr`
Milestone: -
jkotas commented 2 years ago

cc @am11

am11 commented 2 years ago

./build.sh --subset clr --arch armel --cross --gcc /p:TargetArchitecture=armel -c Release

@Z4rc, are you running this command in a docker container? If so, can you share the Dockerfile with gcc-10 and ROOTFS_DIR setup?

With -cross, the build uses toolchain.cmake file which is only tested against clang and gnueabihf binutils on linux-armel. It is possible to add gcc support if you need it. I will reproduce it locally with your setup first.

Z4rc commented 2 years ago

Thank you for your fast response!

Unfortunately no, I am not using a docker container. And I'm probably not allowed to share our company's ROOTFS_DIR :( I got it building and running by reverting the error-causing lines from https://github.com/dotnet/runtime/commit/39803d4d3cbf818641437afb7402da15fa076bec

for example:

diff --git a/src/coreclr/vm/arm/asmhelpers.S b/src/coreclr/vm/arm/asmhelpers.S
index 2780f95912f..f098901bb63 100644
--- a/src/coreclr/vm/arm/asmhelpers.S
+++ b/src/coreclr/vm/arm/asmhelpers.S
@@ -984,9 +984,7 @@ g_rgWriteBarrierDescriptors:
     LEAF_ENTRY JIT_WriteBarrier_Callable

     // Branch to the write barrier
-    ldr     r2, =JIT_WriteBarrier_Loc-(1f+4) // or R3? See targetarm.h
-1:
-    add     r2, pc
+    ldr     r2, =JIT_WriteBarrier_Loc // or R3? See targetarm.h
     ldr     pc, [r2]

     LEAF_END JIT_WriteBarrier_Callable

But as I said before, I don't really know what I'm doing here. Therefore I would highly appreciate if gcc support would be added for the -cross option.

Z4rc commented 2 years ago

Have to correct myself: My workaround does not really work. It builds and can be used to run HelloWorld, but more complex applications are crashing. And gdb is pointing to src/coreclr/vm/arm/asmhelpers.S

Z4rc commented 1 year ago

Hi,

I reproduced the build errors with an open source ROOTFS_DIR and created a docker image: https://hub.docker.com/r/z4rc/build-dotnet-armel

The ROOTFS_DIR is a Debian 10 (buster) which was created with the script from the repository: eng/common/cross/build-rootfs.sh armel buster The gcc is taken from developer.arm.com but only version 8.3.0 since I could not find something newer on their website for the armel architecture. Nevertheless I get the same build errors for the assembler files as with gcc-10.

Would be great if someone could have a look - thanks in advance!

cc @am11