Mercurial > hg > graal-compiler
changeset 13586:7737fbb055b0
check branch displacement when patching short branches
author | twisti |
---|---|
date | Thu, 09 Jan 2014 20:04:55 -0800 |
parents | f4f0a8a01ce0 |
children | 40e81cba9e08 |
files | graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64Assembler.java |
diffstat | 1 files changed, 8 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64Assembler.java Thu Jan 09 16:18:29 2014 +0100 +++ b/graal/com.oracle.graal.asm.amd64/src/com/oracle/graal/asm/amd64/AMD64Assembler.java Thu Jan 09 20:04:55 2014 -0800 @@ -2437,7 +2437,14 @@ } else if (op == 0xEB || (op & 0xF0) == 0x70) { // short offset operators (jmp and jcc) - int imm8 = branchTarget - (branch + 2); + final int imm8 = branchTarget - (branch + 2); + /* + * Since a wrongly patched short branch can potentially lead to working but really bad + * behaving code we should always fail with an exception instead of having an assert. + */ + if (!NumUtil.isByte(imm8)) { + throw new InternalError("branch displacement out of range: " + imm8); + } codeBuffer.emitByte(imm8, branch + 1); } else {