RFR: 8352141: UBSAN: fix the left shift of negative value in relocInfo.cpp, internal_word_Relocation::pack_data_to()

Afshin Zafari azafari at openjdk.org
Mon Mar 24 13:33:49 UTC 2025


The `offset` variable used in left-shift op can be a large number with its sign-bit set. This makes a negative value which is UB for left-shift. Using `java_left_shif()` function is the workaround to avoid UB. This function uses reinterpret_cast to cast from signed to unsigned and back.

Tests:
linux-x64-debug tier1 on a UBSAN enabled build.

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

Commit messages:
 - 8352141: UBSAN: fix the left shift of negative value in relocInfo.cpp, internal_word_Relocation::pack_data_to()

Changes: https://git.openjdk.org/jdk/pull/24196/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=24196&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8352141
  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/24196.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/24196/head:pull/24196

PR: https://git.openjdk.org/jdk/pull/24196


More information about the hotspot-compiler-dev mailing list