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

8345569: [ubsan] adjustments to filemap.cpp and virtualspace.cpp for macOS aarch64 #22603

Closed
wants to merge 4 commits into from

Conversation

MBaesken
Copy link
Member

@MBaesken MBaesken commented Dec 6, 2024

This fixes the build when building on macOS aarch64 with ubsan enabled.

Seems there is an undefined addition to a nullptr in filemap.cpp :

jdk/src/hotspot/share/cds/filemap.cpp:2215:47: runtime error: applying non-zero offset 34358689792 to null pointer
#0 0x107b70c78 in FileMapInfo::heap_region_requested_address() filemap.cpp:2215
#1 0x107b71960 in FileMapInfo::map_heap_region_impl() filemap.cpp:2260
#2 0x107b70e04 in FileMapInfo::map_or_load_heap_region() filemap.cpp:2081
#3 0x1082976ec in MetaspaceShared::map_archives(FileMapInfo*, FileMapInfo*, bool) metaspaceShared.cpp:1344
#4 0x10829699c in MetaspaceShared::initialize_runtime_shared_and_meta_spaces() metaspaceShared.cpp:1098
#5 0x108289530 in Metaspace::global_initialize() metaspace.cpp:736
#6 0x108819da8 in universe_init() universe.cpp:887
#7 0x107d8b4ec in init_globals() init.cpp:133
#8 0x1087e43d8 in Threads::create_vm(JavaVMInitArgs*, bool*) threads.cpp:574
#9 0x107eca96c in JNI_CreateJavaVM jni.cpp:3681
#10 0x102e6e770 in JavaMain java.c:494
#11 0x102e7579c in ThreadJavaMain java_md_macosx.m:679
#12 0x19d38ef90 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x6f90)
#13 0x19d389d30 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1d30)

coding in filemap.cpp is (and CompressedOops::base() seems to return nullptr on this macoS aarch64 machine)

return /*runtime*/ CompressedOops::base() + r->mapping_offset();
This was seen in the OpenJDK build on macOS aarch64 when building with ubsan enabled.

There is also another very recent issue showing up in the ubsan enabled build on macOS aarch64 since today.
jdk/src/hotspot/share/memory/virtualspace.cpp:462:18: runtime error: applying non-zero offset to non-null pointer 0x000080000000 produced null pointer
#0 0x10a6a2df0 in ReservedHeapSpace::try_reserve_range(char*, char*, unsigned long, char*, char*, unsigned long, unsigned long, unsigned long) virtualspace.cpp:462
#1 0x10a6a3684 in ReservedHeapSpace::initialize_compressed_heap(unsigned long, unsigned long, unsigned long) virtualspace.cpp:569
#2 0x10a6a39cc in ReservedHeapSpace::ReservedHeapSpace(unsigned long, unsigned long, unsigned long, char const*) virtualspace.cpp:647
#3 0x10a6a3bd0 in ReservedHeapSpace::ReservedHeapSpace(unsigned long, unsigned long, unsigned long, char const*) virtualspace.cpp:622
#4 0x10a625d5c in Universe::reserve_heap(unsigned long, unsigned long) universe.cpp:959
#5 0x1099d4580 in G1CollectedHeap::initialize() g1CollectedHeap.cpp:1286
#6 0x10a6255e8 in universe_init() universe.cpp:880
#7 0x109b95dec in init_globals() init.cpp:133
#8 0x10a5efd98 in Threads::create_vm(JavaVMInitArgs*, bool*) threads.cpp:574
#9 0x109cd53b4 in JNI_CreateJavaVM jni.cpp:3680
#10 0x104d26770 in JavaMain java.c:494
#11 0x104d2d79c in ThreadJavaMain java_md_macosx.m:679
#12 0x19d38ef90 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x6f90)
#13 0x19d389d30 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1d30)
... (rest of output omitted)

For now I exclude this method from ubsan checking.
After these changes, the build on macOS aarch64 with ubsan enabled works .


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8345569: [ubsan] adjustments to filemap.cpp and virtualspace.cpp for macOS aarch64 (Bug - P3)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22603/head:pull/22603
$ git checkout pull/22603

Update a local copy of the PR:
$ git checkout pull/22603
$ git pull https://git.openjdk.org/jdk.git pull/22603/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 22603

View PR using the GUI difftool:
$ git pr show -t 22603

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22603.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 6, 2024

👋 Welcome back mbaesken! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Dec 6, 2024

@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:

8345569: [ubsan] adjustments to filemap.cpp and virtualspace.cpp for macOS aarch64

Reviewed-by: mdoerr, lucy, dholmes

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 97 new commits pushed to the master branch:

  • 367c304: 8346059: [ASAN] awt_LoadLibrary.c reported compile warning ignoring return value of function by clang17
  • 31ceec7: 8346055: javax/swing/text/StyledEditorKit/4506788/bug4506788.java fails in ubuntu22.04
  • 09c29d1: 8346069: Add missing Classpath exception statements
  • 28e49e9: 8345505: Fix -Wzero-as-null-pointer-constant warnings in zero code
  • db9eab3: 8311542: Consolidate the native stack printing code
  • 18e0b34: 8344137: Update XML Security for Java to 3.0.5
  • e9ad27f: 8339313: 32-bit build broken
  • ff85865: 8346008: Fix recent NULL usage backsliding in Shenandoah
  • 11cd639: 8345573: Module dependencies not resolved from run-time image when --limit-module is being used
  • 22845a7: 8337995: ZUtils::fill uses std::fill_n
  • ... and 87 more: https://git.openjdk.org/jdk/compare/2286fae300b37f4b69ed817d3edea6fe7fa2f52d...master

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 master branch, type /integrate in a new comment.

@openjdk openjdk bot changed the title JDK-8345569: [ubsan] filemap.cpp:2215:47: runtime error: applying non-zero offset 34358689792 to null pointer 8345569: [ubsan] filemap.cpp:2215:47: runtime error: applying non-zero offset 34358689792 to null pointer Dec 6, 2024
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 6, 2024
@openjdk
Copy link

openjdk bot commented Dec 6, 2024

@MBaesken The following label will be automatically applied to this pull request:

  • hotspot-runtime

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot-runtime hotspot-runtime-dev@openjdk.org label Dec 6, 2024
@mlbridge
Copy link

mlbridge bot commented Dec 6, 2024

Webrevs

@@ -2245,7 +2245,7 @@ address FileMapInfo::heap_region_requested_address() {
// Runtime base = 0x4000 and shift is also 0. If we map this region at 0x5000, then
// the value P can remain 0x1200. The decoded address = (0x4000 + (0x1200 << 0)) = 0x5200,
// which is the runtime location of the referenced object.
return /*runtime*/ CompressedOops::base() + r->mapping_offset();
return /*runtime*/ (address)((uintptr_t)CompressedOops::base() + r->mapping_offset());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If base() can return 0 (nullptr) then how does the casting help with the warning?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the addition on uintptr_t is defined in C++ while the addition on nullptr is not.
That's why the ubsan warning/error goes away.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I misread the placement of the parentheses.

@dholmes-ora
Copy link
Member

error: applying non-zero offset to non-null pointer 0x000080000000 produced null pointer

So that sounds like signed arithmetic is being performed instead of unsigned.

@MBaesken
Copy link
Member Author

MBaesken commented Dec 9, 2024

error: applying non-zero offset to non-null pointer 0x000080000000 produced null pointer

So that sounds like signed arithmetic is being performed instead of unsigned.

I think the virtualspace.cpp related issue came in just recently . Earlier last week I did not see this issue.

@MBaesken
Copy link
Member Author

MBaesken commented Dec 9, 2024

There is another addition to nullptr in FileMapInfo::heap_region_dumptime_address , shown when running jtreg test jdk/jfr/event/gc/configuration/TestGCConfigurationEvent on macOS aarch64 .

Warning/error is
src/hotspot/share/cds/filemap.cpp:2222:43: runtime error: applying non-zero offset 34357641216 to null pointer

We should address this here as well because it is in the same file and similar to the other code location.

@MBaesken
Copy link
Member Author

MBaesken commented Dec 12, 2024

Should I adjust the title of the PR + JBS issue ? It does not match well any more what is done.
Maybe something generic like '[ubsan] adjustments to filemap.cpp and virtualspace.cpp for macOS aarch64' ?

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine to me.

Feel free to update the JBS/PR title if you choose.

Thanks

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 13, 2024
@MBaesken MBaesken changed the title 8345569: [ubsan] filemap.cpp:2215:47: runtime error: applying non-zero offset 34358689792 to null pointer 8345569: [ubsan] adjustments to filemap.cpp and virtualspace.cpp for macOS aarch64 Dec 13, 2024
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Dec 13, 2024
@MBaesken
Copy link
Member Author

Hi David, thanks for the review !
I adjusted the title.
GHA issues seem to be unrelated.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 13, 2024
Copy link
Contributor

@TheRealMDoerr TheRealMDoerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor nit. Otherwise, LGTM. Thanks for fixing it.

src/hotspot/share/memory/virtualspace.cpp Outdated Show resolved Hide resolved
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Dec 13, 2024
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 13, 2024
Copy link
Contributor

@RealLucy RealLucy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@MBaesken
Copy link
Member Author

failing GHA for linux-x64 has

make/RunTests.gmk:458: *** Cannot continue.  Stop.
Unknown test selection: 'test/hotspot/jtreg/:tier1_compiler_not_xcomp'

so that's most likely unrelated.

@MBaesken
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Dec 13, 2024

Going to push as commit 1d2ccae.
Since your change was applied there have been 98 commits pushed to the master branch:

  • a9a5f7c: 8345323: Parallel GC does not handle UseLargePages and UseNUMA gracefully
  • 367c304: 8346059: [ASAN] awt_LoadLibrary.c reported compile warning ignoring return value of function by clang17
  • 31ceec7: 8346055: javax/swing/text/StyledEditorKit/4506788/bug4506788.java fails in ubuntu22.04
  • 09c29d1: 8346069: Add missing Classpath exception statements
  • 28e49e9: 8345505: Fix -Wzero-as-null-pointer-constant warnings in zero code
  • db9eab3: 8311542: Consolidate the native stack printing code
  • 18e0b34: 8344137: Update XML Security for Java to 3.0.5
  • e9ad27f: 8339313: 32-bit build broken
  • ff85865: 8346008: Fix recent NULL usage backsliding in Shenandoah
  • 11cd639: 8345573: Module dependencies not resolved from run-time image when --limit-module is being used
  • ... and 88 more: https://git.openjdk.org/jdk/compare/2286fae300b37f4b69ed817d3edea6fe7fa2f52d...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 13, 2024
@openjdk openjdk bot closed this Dec 13, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Dec 13, 2024
@openjdk
Copy link

openjdk bot commented Dec 13, 2024

@MBaesken Pushed as commit 1d2ccae.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants