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

Martin Doerr mdoerr at openjdk.org
Tue May 28 13:40:02 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.

An idea to fix it is to avoid pointer arithmetic. E.g.

diff --git a/src/hotspot/share/code/relocInfo.cpp b/src/hotspot/share/code/relocInfo.cpp
index d0f732edac4..b6e1517aefd 100644
--- a/src/hotspot/share/code/relocInfo.cpp
+++ b/src/hotspot/share/code/relocInfo.cpp
@@ -152,7 +152,7 @@ RelocIterator::RelocIterator(CodeSection* cs, address begin, address limit) {
   initialize_misc();
   assert(((cs->locs_start() != nullptr) && (cs->locs_end() != nullptr)) ||
          ((cs->locs_start() == nullptr) && (cs->locs_end() == nullptr)), "valid start and end pointer");
-  _current = cs->locs_start()-1;
+  _current = (relocInfo*)((uintptr_t)cs->locs_start() - sizeof(relocInfo));
   _end     = cs->locs_end();
   _addr    = cs->start();
   _code    = nullptr; // Not cb->blob();
diff --git a/src/hotspot/share/code/relocInfo.hpp b/src/hotspot/share/code/relocInfo.hpp
index 6d0907d97de..1774c8ac62a 100644
--- a/src/hotspot/share/code/relocInfo.hpp
+++ b/src/hotspot/share/code/relocInfo.hpp
@@ -603,7 +603,7 @@ class RelocIterator : public StackObj {
 
   // get next reloc info, return !eos
   bool next() {
-    _current++;
+    _current = (relocInfo*)((uintptr_t)_current + sizeof(relocInfo));
     assert(_current <= _end, "must not overrun relocInfo");
     if (_current == _end) {
       set_has_current(false);

Doesn't look very nice, but should work.

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

PR Review: https://git.openjdk.org/jdk/pull/19424#pullrequestreview-2082821428


More information about the hotspot-compiler-dev mailing list