-
Notifications
You must be signed in to change notification settings - Fork 5.8k
JDK-8288719: [arm32] SafeFetch32 thumb interleaving causes random crashes #9213
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
Conversation
👋 Welcome back stuefe! A progress list of the required criteria for merging this PR into |
/solves JDK-8284997 |
@tstuefe |
/label aarch32-port |
@tstuefe
|
/label remove hotspot_runtime |
@tstuefe
|
@tstuefe |
Now I remember jdk8 aarch32 port marks assembly functions specially to handle thumb interworking. AFAIK the bug can be reproduced with overridden C(XX)FLAGS=-mthumb even with crossbuilds. |
Thank you, Sergey! I tried to reproduce this with -mthumb with a crossbuild, but was not able to pass --with-extra-cflags to a devkit crossbuild. I opened https://bugs.openjdk.org/browse/JDK-8288797 to track that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take a look at linux_arm directory. All functions come in pair(.global and .type function). so it's reasonable. LGTM. I am not a reviewer. we still need other reviewer to approve it.
@@ -26,6 +26,7 @@ | |||
.globl SafeFetch32_impl | |||
.globl _SafeFetch32_fault | |||
.globl _SafeFetch32_continuation | |||
.type SafeFetch32_impl, %function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By adding this .type directive, the compiler knows that SafeFetch32_impl is a function.
When static linker resolves it, it will update the correct branch instruction according to its target. In this case, it will use BX on Ubuntu18.04.
Is my understanding correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By adding this .type directive, the compiler knows that SafeFetch32_impl is a function. When static linker resolves it, it will update the correct branch instruction according to its target. In this case, it will use BX on Ubuntu18.04.
Is my understanding correct?
Correct.
Thank you, Xin! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@tstuefe This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 57 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Thanks @snazarkin, @navyxliu and @RealLucy ! /integrate |
Going to push as commit 26c03c1.
Your commit was automatically rebased without conflicts. |
After JDK-8284997 delivered just a bandaid, this is hopefully the real fix.
JDK-8283326 re-implemented SafeFetch as static assembler functions. This broke arm: the VM would crash at random points, usually in Atomic::add(), usually right at startup. In most cases the VM could not even be built correctly, see JDK-8284997.
This was only reproducible if the VM was built natively, on a Raspberry Pi, inside an Ubuntu18-derived container. Buiding natively on Raspberry Pi OS was fine. Cross-building was fine too. The difference is the default instruction set the toolchain uses. We don't explicitly specify
-mthumb
or-marm
, so we use the toolchain's default. That default seems to depend on how GCC itself was built. Ubuntu ships a GCC that has been built in thumb mode, thus defaulting to-mthumb
, whereas Raspberry Pi OS and Fedora ship GCCs that default to-marm
.So, the VM proper is compiled either to arm or thumb code. The
SafeFetch32
assembly function itself uses arm code always. Why this is I don't know for sure, I assume if I wanted thumb I need to specify.thumb_func
in the assembly.If the VM uses thumb, it needs to call SafeFetch32 with a switching branch instruction (BX). But the compiler-generated BL. The instruction set was not switched upon entering SafeFetch32 and garbage thumb code was executed. VM crashes soon after.
This seems to be a common problem when writing arm assembly by hand, the solution is specify
.type function
. See also [1]: "As of GCC 4.7, the .type directive is pretty much required for functions. Or, rather, it is required if you want ARM and Thumb interworking to work."A remaining question is whether we should specify the instruction set explicitly when building on arm32, to prevent surprises like this. Preferably with a configure option.
Testing:
Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/9213/head:pull/9213
$ git checkout pull/9213
Update a local copy of the PR:
$ git checkout pull/9213
$ git pull https://git.openjdk.org/jdk pull/9213/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 9213
View PR using the GUI difftool:
$ git pr show -t 9213
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/9213.diff