Index: binutils/gas/config/tc-i386.c |
diff --git a/binutils/gas/config/tc-i386.c b/binutils/gas/config/tc-i386.c |
index b728748de53d71030f8626a5c61de1c74df1ddd6..6cc6b72394015c8c26e567a5dc119dc865a17320 100644 |
--- a/binutils/gas/config/tc-i386.c |
+++ b/binutils/gas/config/tc-i386.c |
@@ -5795,7 +5795,8 @@ insert_sp_adjust_sandbox_code (offsetT insn_start_off) |
static void |
insert_xp_sandbox_code(unsigned int regN, unsigned int cmd_2reg, |
- unsigned int cmd_imm, offsetT insn_start_off) |
+ unsigned int cmd_imm, offsetT insn_start_off, |
+ int gen_imm_prefix) |
{ |
char *p; |
unsigned int need_rex = !!(i.rex & (REX_B | REX_X)); |
@@ -5850,12 +5851,20 @@ insert_xp_sandbox_code(unsigned int regN, unsigned int cmd_2reg, |
} |
else |
{ |
- p = frag_more (2); |
- if (imm_size (0) == 1) |
- p[0] = 0x83; // CMD imm8, %regN(ExP) |
+ if (gen_imm_prefix) |
+ { |
+ p = frag_more (2); |
+ if (imm_size (0) == 1) |
+ p[0] = 0x83; // CMD imm8, %regN(ExP) |
+ else |
+ p[0] = 0x81; // CMD imm32, %regX(ExP) |
+ p[1] = cmd_imm; |
+ } |
else |
- p[0] = 0x81; // CMD imm32, %regX(ExP) |
- p[1] = cmd_imm; |
+ { |
+ p = frag_more (1); |
+ p[0] = cmd_imm; |
+ } |
output_imm (frag_now, insn_start_off); |
// Second operand is regN(ExP) |
i.rm.regmem = regN/*ExP*/; |
@@ -5973,26 +5982,26 @@ check_prefix: |
if (!strcmp(i.tm.name, "naclasp")) |
/* esp add add |
reg imm */ |
- insert_xp_sandbox_code (4, 0x01, 0xc4, insn_start_off); |
+ insert_xp_sandbox_code (4, 0x01, 0xc4, insn_start_off, 1); |
else if (!strcmp(i.tm.name, "naclssp")) |
/* esp sub sub |
reg imm */ |
- insert_xp_sandbox_code (4, 0x29, 0xec, insn_start_off); |
+ insert_xp_sandbox_code (4, 0x29, 0xec, insn_start_off, 1); |
else if (!strcmp(i.tm.name, "naclspadj")) |
insert_sp_adjust_sandbox_code (insn_start_off); |
else if (!strcmp(i.tm.name, "naclrestbp")) |
/* ebp mov mov |
reg imm */ |
- insert_xp_sandbox_code (5, 0x89, 0xbc, insn_start_off); |
+ insert_xp_sandbox_code (5, 0x89, 0xbd, insn_start_off, 0); |
else if (!strcmp(i.tm.name, "naclrestsp")) |
/* esp mov mov |
reg imm */ |
- insert_xp_sandbox_code (4, 0x89, 0xbc, insn_start_off); |
+ insert_xp_sandbox_code (4, 0x89, 0xbc, insn_start_off, 0); |
else if (!strcmp(i.tm.name, "naclrestsp_noflags")) { |
/* esp mov mov |
reg imm */ |
// Generate the mov from src into esp first. |
- insert_xp_sandbox_code (4, 0x89, 0xbc, insn_start_off); |
+ insert_xp_sandbox_code (4, 0x89, 0xbc, insn_start_off, 0); |
// Now set it up to restore rsp with lea (%rsp,%r15,1), %rsp -- |
// overriding the add instruction that insert_xp_sandbox_code |
// set up to restore rsp. |