Skip to content

Commit

Permalink
fail with GraalError if jmpb used with offset that cannot be encoded …
Browse files Browse the repository at this point in the history
…into a byte
  • Loading branch information
dougxc committed Apr 12, 2019
1 parent 1fa8eff commit 8eb34f4
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
import org.graalvm.compiler.asm.Label;
import org.graalvm.compiler.asm.amd64.AMD64Address.Scale;
import org.graalvm.compiler.asm.amd64.AVXKind.AVXSize;
import org.graalvm.compiler.core.common.NumUtil;
import org.graalvm.compiler.core.common.calc.Condition;
import org.graalvm.compiler.debug.GraalError;

Expand Down Expand Up @@ -1950,11 +1949,11 @@ public final void jmp(AMD64Address adr) {
public final void jmpb(Label l) {
if (l.isBound()) {
int shortSize = 2;
int entry = l.position();
assert isByte((entry - position()) + shortSize) : "Dispacement too large for a short jmp";
long offs = entry - position();
// Displacement is relative to byte just after jmpb instruction
int displacement = l.position() - position() - shortSize;
GraalError.guarantee(isByte(displacement), "Displacement too large to be encoded as a byte: %d", displacement);
emitByte(0xEB);
emitByte((int) ((offs - shortSize) & 0xFF));
emitByte(displacement & 0xFF);
} else {
l.addPatchAt(position(), this);
emitByte(0xEB);
Expand Down Expand Up @@ -3396,9 +3395,7 @@ protected final void patchJumpTarget(int branch, int branchTarget) {
* 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("Displacement too large to be encoded as a byte: " + imm8);
}
GraalError.guarantee(isByte(imm8), "Displacement too large to be encoded as a byte: %d", imm8);
emitByte(imm8, branch + 1);

} else {
Expand Down

0 comments on commit 8eb34f4

Please sign in to comment.