RFR: 8366062: [ubsan] add non-zero offset to nullptr in cds/archiveBuilder.cpp

David Holmes dholmes at openjdk.org
Mon Sep 8 06:05:13 UTC 2025


On Thu, 28 Aug 2025 10:15:47 GMT, Afshin Zafari <azafari at openjdk.org> wrote:

> It is acceptable that the `SharedBaseAddress` option gets `0` at command line. The corresponding pointer arithmetic with `0` (`nullptr`) in archiveBuilder is UB.
> Specific casts are used to avoid UBSAN error.
> 
> Tests:
> linux-x64-debug: tier1 passed

Approach of using integer arithmetic seems reasonable to me. Some suggestions on the way it is commented.

Thanks

src/hotspot/share/cds/archiveBuilder.cpp line 374:

> 372: 
> 373:     // At run time, we will mmap the dynamic archive at my_archive_requested_bottom
> 374:     // Zero is acceptable for _requested_static_archive_bottom. Using casts to avoid UBSAN complain of nullptr arithmetic.

Suggestion:

    // As zero is allowed for _requested_static_archive_bottom, use integer arithmetic to avoid UB pointer arithmetic.

And similarly for other comments.

-------------

PR Review: https://git.openjdk.org/jdk/pull/26983#pullrequestreview-3195058563
PR Review Comment: https://git.openjdk.org/jdk/pull/26983#discussion_r2329210001


More information about the hotspot-runtime-dev mailing list