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

Vladimir Kozlov kvn at openjdk.org
Mon Mar 24 18:22:09 UTC 2025


On Mon, 24 Mar 2025 13:18:25 GMT, Afshin Zafari <azafari at openjdk.org> wrote:

> 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.

Please update bug report and PR's description with error output you see. The offset can't be big number since internal_word relocation is referencing address in the same nmethod.  Unless there is bug.
Offset can be negative. Why it is UB for signed left shift for negative value?

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

PR Comment: https://git.openjdk.org/jdk/pull/24196#issuecomment-2749033445


More information about the hotspot-compiler-dev mailing list