-
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
[ARM32] CompareExchange working wrong in debug build with clang3.9 #9285
Comments
@dotnet/arm32-contrib please take a look. |
If I cross comple next c++ program with clang3.9
With next command:
__sync_val_compare_and_swap() working wrong:
And if I build it with clang4.0 - I get the correct result:
|
Dump for 3.9: 00010444 <main>:
10444: e92d4830 push {r4, r5, fp, lr}
10448: e24dd020 sub sp, sp, dotnet/coreclr#32
1044c: e3a00000 mov r0, #0
10450: e58d001c str r0, [sp, dotnet/runtime#3860]
10454: e58d0014 str r0, [sp, dotnet/coreclr#20]
10458: e3a01042 mov r1, dotnet/coreclr#66 ; 0x42
1045c: e3811c01 orr r1, r1, dotnet/coreclr#256 ; 0x100
10460: e58d1010 str r1, [sp, dotnet/coreclr#16]
10464: ee070fba mcr 15, 0, r0, cr7, cr10, {5}
10468: e1a02000 mov r2, r0
1046c: e1a03000 mov r3, r0
10470: e28d1010 add r1, sp, dotnet/coreclr#16
10474: e1b14f9f ldrexd r4, [r1]
10478: e1540002 cmp r4, r2
1047c: e0d5c003 sbcs ip, r5, r3
10480: 1a000002 bne 10490 <main+0x4c>
10484: e1a1cf92 strexd ip, r2, [r1]
10488: e35c0000 cmp ip, #0
1048c: 1afffff8 bne 10474 <main+0x30>
10490: ee070fba mcr 15, 0, r0, cr7, cr10, {5}
10494: e59d0010 ldr r0, [sp, dotnet/coreclr#16]
10498: e58dc00c str ip, [sp, dotnet/coreclr#12]
1049c: e1cd40f0 strd r4, [sp]
104a0: e28dd020 add sp, sp, dotnet/coreclr#32
104a4: e8bd8830 pop {r4, r5, fp, pc} for 4.0: 00010444 <main>:
10444: e92d4830 push {r4, r5, fp, lr}
10448: e28db008 add fp, sp, dotnet/coreclr#8
1044c: e24dd020 sub sp, sp, dotnet/coreclr#32
10450: e3a00000 mov r0, #0
10454: e50b000c str r0, [fp, #-12]
10458: e58d0014 str r0, [sp, dotnet/coreclr#20]
1045c: e3a01042 mov r1, dotnet/coreclr#66 ; 0x42
10460: e3811c01 orr r1, r1, dotnet/coreclr#256 ; 0x100
10464: e58d1010 str r1, [sp, dotnet/coreclr#16]
10468: ee070fba mcr 15, 0, r0, cr7, cr10, {5}
1046c: e1a02000 mov r2, r0
10470: e1a03000 mov r3, r0
10474: e28d1010 add r1, sp, dotnet/coreclr#16
10478: e1b14f9f ldrexd r4, [r1]
1047c: e1540002 cmp r4, r2
10480: 01550003 cmpeq r5, r3
10484: 1a000002 bne 10494 <main+0x50>
10488: e1a1cf92 strexd ip, r2, [r1]
1048c: e35c0000 cmp ip, #0
10490: 1afffff8 bne 10478 <main+0x34>
10494: ee070fba mcr 15, 0, r0, cr7, cr10, {5}
10498: e59d0010 ldr r0, [sp, dotnet/coreclr#16]
1049c: e58dc00c str ip, [sp, dotnet/coreclr#12]
104a0: e1cd40f0 strd r4, [sp]
104a4: e24bd008 sub sp, fp, dotnet/coreclr#8
104a8: e8bd8830 pop {r4, r5, fp, pc} Difference in one command: ; in 3.9
1047c: e0d5c003 sbcs ip, r5, r3
; in 4.0:
10480: 01550003 cmpeq r5, r3 |
@alpencolt the code generated by 3.9 is clearly wrong. But it is really strange that our tests on arm would not be crashing left and right with such a bug. What is the exact version of clang - is it 3.9 or 3.9.1? |
@janvorli I use 3.9.1:
3.8.1 works well as 3.9.1 with @Buyduck could you check your version? |
@alpencolt I use 3.9.1 too:
I've installed it with:
|
@alpencolt Thank you for confirming the versions and also mentioning again that it only happens with |
@janvorli Thanks a lot!
Also, I can currently cross build CoreCLR for arm only with 'skiptests' key, otherwise I got next error, while compiling hfa_native.cpp:
cc: @alpencolt |
Nice :-(. Looks like yet another bug in clang. Maybe you can just disable this test for your purpose by adding it to tests/testsFailingOutsideWindows.txt and comment out the contents of the tests/src/JIT/jit64/hfa/main/dll/CMakeLists.txt (I hope that's enough). |
There is nothing we can do about it since it is a compiler bug and LLVM said they will not backfix it in 3.9.1. So we can only recommend people to build with clang 4.0 for arm32. Our official builds are fine since they are release builds and this issue happens only for debug builds. Even checked builds are ok. |
@janvorli Should we add documentation to https://github.com/dotnet/coreclr/blob/master/Documentation/building/linux-instructions.md indicating that Debug builds for ARM must use clang4.0 or later? Should we change build.sh to emit a warning (or error) if building arm debug without this? Should we try to get the official tools used to build ARM updated to 4.0 or later? This problem is going to cause many Debug CI jobs for ARM Ubuntu to fail, as described in dotnet/coreclr#16995. |
@BruceForstall yes, such a comment in the doc would be great. It seems we should migrate our builds to clang 4.0 then. Other option, if we really wanted to make it work with the 3.9 for some reason too, is to implement the workaround I've mentioned. Detect that the compiler produces faulty synchronization intrinsics at build time and add inline assembler implementation of our interlocked functions in that case. |
With next C# code:
While cross building debug version CoreCLR for ARM32 with clang3.9 got next result:
And, while building with clang4.0 - everything is ok:
With Release version everything is ok. Seems, like in pal.h __sync_val_compare_and_swap() for some reason working wrong:
@alpencolt
The text was updated successfully, but these errors were encountered: