-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8332894: ubsan: vmError.cpp:2090:26: runtime error: division by zero #19394
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 mbaesken! A progress list of the required criteria for merging this PR into |
|
@MBaesken 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 26 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 |
Webrevs
|
|
I'm wondering if we shouldn't follow the pattern of creating another header file in |
| #endif | ||
| static void ALWAYSINLINE crash_with_sigfpe() { | ||
|
|
||
| // generate a native synchronous SIGFPE where possible; |
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.
Maybe simpler would be to change the definition to only use the divide-by-zero
approach for _WIN32 and always use the currently conditional fallback to
pthread_kill on non-_WIN32. Especially in light of the fact that the
divide-by-zero approach doesn't work on some platforms.
I also wonder if the comment about OSX incorrectly implementing raise is
correct? Maybe that's been fixed? Or maybe it's not a bug, but a BSD-ism?
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 do not know about the OSX specific issues, maybe someone else can comment?
Regarding the handling on UNIX, Thomas commented and I think the coding should better stay.
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.
macOS raise raises the signal to the process not the thread (per Posix requirements).
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.
Hi David, so the comment
// OSX implements raise(sig) incorrectly so we need to
// explicitly target the current thread
seems to be not correct, should we change it e.g. to your comment
// macOS raise raises the signal to the process not the thread (per Posix requirements)
// so we need to explicitly target the current thread
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.
The comment says raise is broken, it just doesn't say exactly how, though it is implied by the "we need to explicitly target the current thread".
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.
It's not "broken". OSX/darwin is BSD-derived, and does not always follow POSIX.
https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/raise.3.html
"The raise() function sends the signal sig to the current process."
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.
Would've used the C++14 attribute syntax for this, but oh well
|
When this was written, the point was to raise a "real" SIGFPE. That matters because the behavior is subtly different from a real signal compared to one faked with raise (asynchronous vs synchronous). Among other things, this SIGFPE is used for regression testing https://bugs.openjdk.org/browse/JDK-8065895. JDK-8065895 described a situation where we accidentally blocked all but the currently processed signal in the signal handler. That meant if we process a synchronous signal (e.g. SIGSEGV) and another, different, synchronous signal happens (e.g. SIGILL), the VM won't handle it in the secondary handler. Instead, depending on the OS, the process either dies immediately without core or it hangs in the kernel. To regression-test the fix, we need to be able to trigger two different synchronous signals. I believe I used SIGILL and SIGSEGV in my original patch in the closed-source SAP JVM. Both are easy to trigger. But then I got resistance against triggering SIGILL, though, and therefore OpenJDK triggers SIGFPE instead of SIGILL. With the unfortunate effect that the test won't work as expected on all platforms. Apart from JDK-8065895, it was also used to check hs-err printing in general. But I guess for that we could use a raised signal. Replacing the triggering with raise will make the regression test for JDK-8065895 toothless. We may just as well remove it then. I remember it being a pain to investigate (no core, no hs-err file), so we should come up with a replacement. We could replace it with an explicit check that tests that the signal handler masks inside error reporting are set up correctly. That is not the same as the real thing, but I guess it would be the next best thing. If we keep it, we need a comment in controlled_crash, because this discussion re-occurs at regular intervals. |
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.
As Thomas notes we intentionally want to test a synchronous signal if possible, so doing the minimum we can to "fix" ubsan is fine by me.
Thanks.
You can put it on the list, why C++ 14 is desired (at some point in future sooner or later we will go anyway to some more current version of the standard). |
|
I adjusted the comment a bit. |
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.
+1
|
Thanks for the reviews ! /integrate |
|
Going to push as commit 1b8dea4.
Your commit was automatically rebased without conflicts. |
Thanks for the background info. In light of that, I think the approach of using an attribute to suppress the |
When running with ubsan enabled on Linux x86_64, I get in the HS :tier1 tests this error :
runtime/ErrorHandling/TestDwarf_dontCheckDecoder.jtr
/jdk/src/hotspot/share/utilities/vmError.cpp:2090:26: runtime error: division by zero
#0 0x7f16bc531f32 in crash_with_sigfpe /jdk/src/hotspot/share/utilities/vmError.cpp:2090
#1 0x7f16bc531f32 in VMError::controlled_crash(int) /jdk/src/hotspot/share/utilities/vmError.cpp:2137
#2 0x7f16bea2d8fd in JNI_CreateJavaVM_inner /jdk/src/hotspot/share/prims/jni.cpp:3621
#3 0x7f16bea2d8fd in JNI_CreateJavaVM /jdk/src/hotspot/share/prims/jni.cpp:3672
#4 0x7f16c5dbd0e5 in InitializeJVM /jdk/src/java.base/share/native/libjli/java.c:1550
#5 0x7f16c5dbd0e5 in JavaMain /jdk/src/java.base/share/native/libjli/java.c:491
#6 0x7f16c5dc6748 in ThreadJavaMain /jdk/src/java.base/unix/native/libjli/java_md.c:642
#7 0x7f16c5d756e9 in start_thread (/lib64/libpthread.so.0+0xa6e9) (BuildId: 2f8d3c2d0f4d7888c2598d2ff6356537f5708a73)
#8 0x7f16c531550e in clone (/lib64/libc.so.6+0x11850e) (BuildId: f732026552f6adff988b338e92d466bc81a01c37)
Reason is that we do a float division by zero to get a signal . This is desired by us so not really an error but ubsan cannot know this.
So add an attribute to this function that it has undefined behavior.
See https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html (division by zero) . "Floating point division by zero. This is undefined per the C and C++ standards"
Progress
Warning
8332894: ubsan: vmError.cpp:2090:26: runtime error: division by zeroIssue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19394/head:pull/19394$ git checkout pull/19394Update a local copy of the PR:
$ git checkout pull/19394$ git pull https://git.openjdk.org/jdk.git pull/19394/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 19394View PR using the GUI difftool:
$ git pr show -t 19394Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19394.diff
Webrev
Link to Webrev Comment