From 09812f0835e077bbe643d6909745eea3c6ef4228 Mon Sep 17 00:00:00 2001 From: Indu Bhagat Date: Thu, 1 Feb 2024 14:48:18 -0800 Subject: gas: x86: ginsn: adjust ginsns for certain lea ops A review comment on the SCFI V4 series was to handle ginsn creation for certain lea opcodes more precisely. Specifically, we should preferably handle the following two cases of lea opcodes similarly: - #1 lea with "index register and scale factor of 1, but no base register", - #2 lea with "no index register, but base register present". Currently, a ginsn of type GINSN_TYPE_OTHER is generated for the case of #1 above. For #2, however, the lea insn is translated to either a GINSN_TYPE_ADD or GINSN_TYPE_MOV depending on whether the immediate for displacement is non-zero or not respectively. Change the handling in x86_ginsn_lea so that both of the above lea manifestations are handled similarly. While at it, remove the code paths creating GINSN_TYPE_OTHER altogether from the function. It makes sense to piggy back on the x86_ginsn_unhandled code path to create GINSN_TYPE_OTHER if the destination register is interesting. This was also suggested in one of the previous review rounds; the other functions already follow that model, so this keeps functions symmetrical looking. gas/ * gas/config/tc-i386.c (x86_ginsn_lea): Handle select lea ops with no base register similar to the case of no index register. Remove creation of GINSN_TYPE_OTHER from the function. gas/testsuite/ * gas/scfi/x86_64/ginsn-lea-1.l: New test. * gas/scfi/x86_64/ginsn-lea-1.s: Likewise. * gas/scfi/x86_64/scfi-x86-64.exp: Add new test. --- gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.l | 54 +++++++++++++++++++++++++++ gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.s | 22 +++++++++++ gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp | 1 + 3 files changed, 77 insertions(+) create mode 100644 gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.l create mode 100644 gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.s (limited to 'gas/testsuite') diff --git a/gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.l b/gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.l new file mode 100644 index 0000000..f787660 --- /dev/null +++ b/gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.l @@ -0,0 +1,54 @@ +.*: Assembler messages: +.*: Warning: scale factor of 4 without an index register +GAS LISTING .* + + + 1 ## Testcase with a variety of lea. + 2 .text + 3 .globl foo + 4 .type foo, @function + 4 ginsn: SYM FUNC_BEGIN + 5 foo: + 5 ginsn: SYM foo + 6 0000 488D2C25 lea symbol, %rbp + 6 00000000 + 6 ginsn: OTH 0, 0, %r6 + 7 0008 488D2C25 lea 0x9090, %rbp + 7 90900000 + 7 ginsn: OTH 0, 0, %r6 + 8 0010 488D05FE lea -0x2\(%rip\), %rax + 8 FFFFFF + 8 ginsn: ADD %r4, -2, %r0 + 9 0017 678D6C18 lea -0x1\(%eax,%ebx\), %ebp + 9 FF + 9 ginsn: OTH 0, 0, %r6 + 10 001c 678D6C58 lea 0x55\(%eax,%ebx,2\), %ebp + 10 55 + 10 ginsn: OTH 0, 0, %r6 + 11 0021 678D0C1D lea -0x3\(,%ebx,1\), %ecx + 11 FDFFFFFF + 11 ginsn: ADD %r3, -3, %r2 + 12 0029 678D0C1D lea -0x3\(,%ebx,\), %ecx + 12 FDFFFFFF + 12 ginsn: ADD %r3, -3, %r2 + 13 0031 678D0C5D lea -0x3\(,%ebx,2\), %ecx + 13 FDFFFFFF + 14 + 15 .allow_index_reg + 16 0039 488D2C20 lea \(%rax,%riz\),%rbp + 16 ginsn: MOV %r0, %r6 + 17 003d 488D28 lea \(%rax,4\),%rbp +\*\*\*\* Warning: scale factor of 4 without an index register + 17 ginsn: MOV %r0, %r6 + 18 0040 488D2CA0 lea \(%rax,%riz,4\),%rbp + 18 ginsn: MOV %r0, %r6 + 19 0044 488D2C25 lea sym\(,%riz\), %rbp + 19 00000000 + 19 ginsn: OTH 0, 0, %r6 + 20 004c 488D2C25 lea \(,%riz\), %rbp + 20 00000000 + 20 ginsn: OTH 0, 0, %r6 + 21 .LFE0: + 21 ginsn: SYM .LFE0 + 22 .size foo, .-foo + 22 ginsn: SYM FUNC_END diff --git a/gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.s b/gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.s new file mode 100644 index 0000000..aa2e8fd --- /dev/null +++ b/gas/testsuite/gas/scfi/x86_64/ginsn-lea-1.s @@ -0,0 +1,22 @@ +## Testcase with a variety of lea. + .text + .globl foo + .type foo, @function +foo: + lea symbol, %rbp + lea 0x9090, %rbp + lea -0x2(%rip), %rax + lea -0x1(%eax,%ebx), %ebp + lea 0x55(%eax,%ebx,2), %ebp + lea -0x3(,%ebx,1), %ecx + lea -0x3(,%ebx,), %ecx + lea -0x3(,%ebx,2), %ecx + + .allow_index_reg + lea (%rax,%riz),%rbp + lea (%rax,4),%rbp + lea (%rax,%riz,4),%rbp + lea sym(,%riz), %rbp + lea (,%riz), %rbp +.LFE0: + .size foo, .-foo diff --git a/gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp b/gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp index 9005c47..9c76974 100644 --- a/gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp +++ b/gas/testsuite/gas/scfi/x86_64/scfi-x86-64.exp @@ -26,6 +26,7 @@ if { ([istarget "x86_64-*-*"] && ![istarget "x86_64-*-linux*-gnux32"]) } then { run_list_test "ginsn-dw2-regnum-1" "--scfi=experimental -ali" run_list_test "ginsn-add-1" "--scfi=experimental -ali" + run_list_test "ginsn-lea-1" "--scfi=experimental -ali" run_list_test "ginsn-pop-1" "--scfi=experimental -ali" run_list_test "ginsn-push-1" "--scfi=experimental -ali" run_list_test "ginsn-cofi-1" "--scfi=experimental -ali -W" -- cgit v1.1