RFR: 8331731: ubsan: relocInfo.cpp:155:30: runtime error: applying non-zero offset 18446744073709551614 to null pointer

Matthias Baesken mbaesken at openjdk.org
Wed May 29 06:52:01 UTC 2024


On Tue, 28 May 2024 12:36:40 GMT, Matthias Baesken <mbaesken at openjdk.org> wrote:

> When running on macOS with ubsan enabled, we see some issues in relocInfo  (hpp and cpp); those already occur in the build quite early.
> 
> /jdk/src/hotspot/share/code/relocInfo.cpp:155:30: runtime error: applying non-zero offset 18446744073709551614 to null pointer
> 
> Similar happens when we add to the _current pointer
>     _current++;
> this gives :
> relocInfo.hpp:606:13: runtime error: applying non-zero offset to non-null pointer 0xfffffffffffffffe produced null pointer
> 
> Seems the pointer subtraction/addition worked so far, so it might be an option to disable ubsan for those 2 functions.

What you think about using some helper templates or macros like this, doing what Martin suggested ?

// helper templates to avoid undefined addition/subtraction from nullptr
template<typename T>
T* add_to_ptr(T* ptr, int val) {
  return (T*)((uintptr_t)ptr + val * sizeof(T));
}

template<typename T>
T* sub_from_ptr(T* ptr, int val) {
  return (T*)((uintptr_t)ptr - val * sizeof(T));
}

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

PR Comment: https://git.openjdk.org/jdk/pull/19424#issuecomment-2136662735


More information about the hotspot-compiler-dev mailing list