RFR: 8289046: Undefined Behaviour in x86 class Assembler [v2]

Andrew Haley aph at openjdk.org
Fri Jun 24 08:05:59 UTC 2022


> All instances of type Register exhibit UB in the form of wild pointer (including null pointer) dereferences. This isn't very hard to fix: we should make Registers pointers to something rather than aliases of small integers. 
> 
> Here's an example of what was happening:
> 
>    ` rax->encoding();`
> 
> Where rax is defined as `(Register *)0`.
> 
> This patch things so that rax is now defined as a pointer to the start of a static array of RegisterImpl.
> 
> 
> typedef const RegisterImpl* Register;
> extern RegisterImpl all_Registers[RegisterImpl::number_of_declared_registers + 1] ;
> inline constexpr Register RegisterImpl::first() { return all_Registers + 1; };
> inline constexpr Register as_Register(int encoding) { return RegisterImpl::first() + encoding; }
> constexpr Register rax = as_register(0);

Andrew Haley has updated the pull request incrementally with two additional commits since the last revision:

 - Update src/hotspot/cpu/x86/register_x86.hpp
   
   Co-authored-by: Aleksey Shipilëv <shade at redhat.com>
 - Update src/hotspot/cpu/x86/register_x86.hpp
   
   Co-authored-by: Aleksey Shipilëv <shade at redhat.com>

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/9261/files
  - new: https://git.openjdk.org/jdk/pull/9261/files/718e210f..36ba30bc

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=9261&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=9261&range=00-01

  Stats: 2 lines in 1 file changed: 0 ins; 0 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/9261.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/9261/head:pull/9261

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


More information about the hotspot-compiler-dev mailing list