return ginsn;
}
+static ginsnS *
+x86_ginsn_indirect_branch (const symbolS *insn_end_sym)
+{
+ ginsnS *ginsn = NULL;
+ const reg_entry *mem_reg;
+ unsigned int dw2_regnum;
+
+ ginsnS * (*ginsn_func) (const symbolS *sym, bool real_p,
+ enum ginsn_src_type src_type, unsigned int src_reg,
+ const symbolS *src_ginsn_sym);
+
+ /* Other cases are not expected. */
+ gas_assert (i.tm.extension_opcode == 4 || i.tm.extension_opcode == 2);
+
+ if (i.tm.extension_opcode == 4)
+ /* 0xFF /4 (jmp r/m). */
+ ginsn_func = ginsn_new_jump;
+ else if (i.tm.extension_opcode == 2)
+ /* 0xFF /2 (call r/m). */
+ ginsn_func = ginsn_new_call;
+
+ if (i.reg_operands)
+ {
+ dw2_regnum = ginsn_dw2_regnum (i.op[0].regs);
+ ginsn = ginsn_func (insn_end_sym, true,
+ GINSN_SRC_REG, dw2_regnum, NULL);
+ ginsn_set_where (ginsn);
+ }
+ else if (i.mem_operands)
+ {
+ /* Handle jump/call near, absolute indirect, address.
+ E.g., jmp/call *imm(%rN), jmp/call *sym(,%rN,imm)
+ or jmp/call *sym(%rN) etc. */
+ mem_reg = i.base_reg ? i.base_reg : i.index_reg;
+ /* Generate a ginsn, even if it is with TBD_GINSN_INFO_LOSS. Otherwise,
+ the user gets the impression of missing functionality due to this
+ being a COFI and alerted for via the x86_ginsn_unhandled () workflow
+ as unhandled operation (which can be misleading for users).
+
+ Indirect branches make the code block ineligible for SCFI; Hence, an
+ approximate ginsn will not affect SCFI correctness:
+ - Use dummy register if no base or index
+ - Skip symbol information, if any.
+ Note this case of TBD_GINSN_GEN_NOT_SCFI. */
+ dw2_regnum = (mem_reg
+ ? ginsn_dw2_regnum (mem_reg)
+ : GINSN_DW2_REGNUM_RSI_DUMMY);
+ ginsn = ginsn_func (insn_end_sym, true,
+ GINSN_SRC_REG, dw2_regnum, NULL);
+ ginsn_set_where (ginsn);
+ }
+
+ return ginsn;
+}
+
static ginsnS *
x86_ginsn_enter (const symbolS *insn_end_sym)
{
ginsn_set_where (ginsn_next);
gas_assert (!ginsn_link_next (ginsn, ginsn_next));
}
- else if (i.tm.extension_opcode == 4)
- {
- /* jmp r/m. E.g., notrack jmp *%rax. */
- if (i.reg_operands)
- {
- dw2_regnum = ginsn_dw2_regnum (i.op[0].regs);
- ginsn = ginsn_new_jump (insn_end_sym, true,
- GINSN_SRC_REG, dw2_regnum, NULL);
- ginsn_set_where (ginsn);
- }
- else if (i.mem_operands && i.index_reg)
- {
- /* jmp *0x0(,%rax,8). */
- dw2_regnum = ginsn_dw2_regnum (i.index_reg);
- ginsn = ginsn_new_jump (insn_end_sym, true,
- GINSN_SRC_REG, dw2_regnum, NULL);
- ginsn_set_where (ginsn);
- }
- else if (i.mem_operands && i.base_reg)
- {
- dw2_regnum = ginsn_dw2_regnum (i.base_reg);
- ginsn = ginsn_new_jump (insn_end_sym, true,
- GINSN_SRC_REG, dw2_regnum, NULL);
- ginsn_set_where (ginsn);
- }
- }
- else if (i.tm.extension_opcode == 2)
- {
- /* 0xFF /2 (call). */
- if (i.reg_operands)
- {
- dw2_regnum = ginsn_dw2_regnum (i.op[0].regs);
- ginsn = ginsn_new_call (insn_end_sym, true,
- GINSN_SRC_REG, dw2_regnum, NULL);
- ginsn_set_where (ginsn);
- }
- else if (i.mem_operands && i.base_reg)
- {
- dw2_regnum = ginsn_dw2_regnum (i.base_reg);
- ginsn = ginsn_new_call (insn_end_sym, true,
- GINSN_SRC_REG, dw2_regnum, NULL);
- ginsn_set_where (ginsn);
- }
- }
+ else if (i.tm.extension_opcode == 4 || i.tm.extension_opcode == 2)
+ ginsn = x86_ginsn_indirect_branch (insn_end_sym);
break;
case 0xc2: /* ret imm16. */
.*: Assembler messages:
-.*:20: Error: untraceable control flow for func 'foo'
+.*:26: Error: untraceable control flow for func 'foo'
GAS LISTING .*
-
1 # Testcase with a variety of "change of flow instructions"
2 #
3 # This test does not have much going on wrt synthesis of CFI;
12 ginsn: JMP %r0,
13 \?\?\?\? 41FFD0 call \*%r8
13 ginsn: CALL
- 14 \?\?\?\? 67E305 jecxz .L179
- 14 ginsn: JCC
- 15 \?\?\?\? FF6730 jmp \*48\(%rdi\)
- 15 ginsn: JMP %r5,
- 16 \?\?\?\? 7000 jo .L179
- 16 ginsn: JCC
- 17 .L179:
- 17 ginsn: SYM .L179
- 18 \?\?\?\? C3 ret
- 18 ginsn: RET
- 19 .LFE0:
- 19 ginsn: SYM .LFE0
- 20 .size foo, .-foo
- 20 ginsn: SYM FUNC_END
+ 14 \?\?\?\? FF14C500 call \*cost_arr\(,%rax,8\)
+ 14 000000
+ 14 ginsn: CALL
+ 15 \?\?\?\? FF149500 call \*\(,%rdx, 4\)
+ 15 000000
+ 15 ginsn: CALL
+ 16 \?\?\?\? FF142500 call \*symbol\+1
+ 16 000000
+ 16 ginsn: CALL
+ 17 \?\?\?\? 67E316 jecxz .L179
+ 17 ginsn: JCC
+ 18 \?\?\?\? 41FFE0 jmp \*%r8
+ 18 ginsn: JMP %r8,
+ 19 \?\?\?\? FF6730 jmp \*48\(%rdi\)
+ 19 ginsn: JMP %r5,
+ 20 \?\?\?\? FF24C500 jmp \*cost_arr\(,%rax,8\)
+ 20 000000
+ 20 ginsn: JMP %r0,
+ 21 \?\?\?\? FF242500 jmp \*symbol\+1
+ 21 000000
+ 21 ginsn: JMP %r4,
+ 22 \?\?\?\? 7000 jo .L179
+ 22 ginsn: JCC
+ 23 .L179:
+ 23 ginsn: SYM .L179
+ 24 \?\?\?\? C3 ret
+ 24 ginsn: RET
+ 25 .LFE0:
+ 25 ginsn: SYM .LFE0
+ 26 .size foo, .-foo
+ 26 ginsn: SYM FUNC_END