]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: aarch64: testsuite: add new tests for SCFI
authorIndu Bhagat <indu.bhagat@oracle.com>
Fri, 19 Jul 2024 03:24:44 +0000 (20:24 -0700)
committerIndu Bhagat <indu.bhagat@oracle.com>
Fri, 19 Jul 2024 03:54:14 +0000 (20:54 -0700)
Similar to the x86_64 testcases, some .s files contain the corresponding
CFI directives.  This helps in validating the synthesized CFI by running
those tests with and without the --scfi=experimental command line
option.

GAS issues some diagnostics, enabled by default, with
--scfi=experimental.  The diagnostics have been added with an intent to
help user correct inadvertent errors in their hand-written asm.  An
error is issued when GAS finds that input asm is not amenable to
accurate CFI synthesis.  The existing scfi-diag-*.s tests in the
gas/testsuite/gas/scfi/x86_64 directory test some SCFI diagnostics
already:

      - (#1) "Warning: SCFI: Asymetrical register restore"
      - (#2) "Error: SCFI: usage of REG_FP as scratch not supported"
      - (#3) "Error: SCFI: unsupported stack manipulation pattern"
      - (#4) "Error: untraceable control flow for func 'XXX'"

In the newly added aarch64 testsuite, further tests for additional
diagnostics have been added:
 - scfi-diag-1.s in this patch highlights an aarch64-specific diagnostic:
   (#5) "Warning: SCFI: ignored probable save/restore op with reg offset"

Additionally, some testcases are added to showcase the (currently)
unsupported patterns, e.g., scfi-unsupported-1.s
        mov     x16, 4384
        sub     sp, sp, x16

gas/testsuite/:
* gas/scfi/README: Update comment to include aarch64.
* gas/scfi/aarch64/scfi-aarch64.exp: New file.
* gas/scfi/aarch64/ginsn-arith-1.l: New test.
* gas/scfi/aarch64/ginsn-arith-1.s: New test.
* gas/scfi/aarch64/ginsn-cofi-1.l: New test.
* gas/scfi/aarch64/ginsn-cofi-1.s: New test.
* gas/scfi/aarch64/ginsn-ldst-1.l: New test.
* gas/scfi/aarch64/ginsn-ldst-1.s: New test.
* gas/scfi/aarch64/scfi-callee-saved-fp-1.d: New test.
* gas/scfi/aarch64/scfi-callee-saved-fp-1.l: New test.
* gas/scfi/aarch64/scfi-callee-saved-fp-1.s: New test.
* gas/scfi/aarch64/scfi-callee-saved-fp-2.d: New test.
* gas/scfi/aarch64/scfi-callee-saved-fp-2.l: New test.
* gas/scfi/aarch64/scfi-callee-saved-fp-2.s: New test.
* gas/scfi/aarch64/scfi-cb-1.d: New test.
* gas/scfi/aarch64/scfi-cb-1.l: New test.
* gas/scfi/aarch64/scfi-cb-1.s: New test.
* gas/scfi/aarch64/scfi-cfg-1.d: New test.
* gas/scfi/aarch64/scfi-cfg-1.l: New test.
* gas/scfi/aarch64/scfi-cfg-1.s: New test.
* gas/scfi/aarch64/scfi-cfg-2.d: New test.
* gas/scfi/aarch64/scfi-cfg-2.l: New test.
* gas/scfi/aarch64/scfi-cfg-2.s: New test.
* gas/scfi/aarch64/scfi-cfg-3.d: New test.
* gas/scfi/aarch64/scfi-cfg-3.l: New test.
* gas/scfi/aarch64/scfi-cfg-3.s: New test.
* gas/scfi/aarch64/scfi-cfg-4.l: New test.
* gas/scfi/aarch64/scfi-cfg-4.s: New test.
* gas/scfi/aarch64/scfi-cond-br-1.d: New test.
* gas/scfi/aarch64/scfi-cond-br-1.l: New test.
* gas/scfi/aarch64/scfi-cond-br-1.s: New test.
* gas/scfi/aarch64/scfi-diag-1.l: New test.
* gas/scfi/aarch64/scfi-diag-1.s: New test.
* gas/scfi/aarch64/scfi-diag-2.l: New test.
* gas/scfi/aarch64/scfi-diag-2.s: New test.
* gas/scfi/aarch64/scfi-diag-3.l: New test.
* gas/scfi/aarch64/scfi-diag-3.s: New test.
* gas/scfi/aarch64/scfi-ldrp-1.d: New test.
* gas/scfi/aarch64/scfi-ldrp-1.l: New test.
* gas/scfi/aarch64/scfi-ldrp-1.s: New test.
* gas/scfi/aarch64/scfi-ldrp-2.d: New test.
* gas/scfi/aarch64/scfi-ldrp-2.l: New test.
* gas/scfi/aarch64/scfi-ldrp-2.s: New test.
* gas/scfi/aarch64/scfi-ldstnap-1.d: New test.
* gas/scfi/aarch64/scfi-ldstnap-1.l: New test.
* gas/scfi/aarch64/scfi-ldstnap-1.s: New test.
* gas/scfi/aarch64/scfi-strp-1.d: New test.
* gas/scfi/aarch64/scfi-strp-1.l: New test.
* gas/scfi/aarch64/scfi-strp-1.s: New test.
* gas/scfi/aarch64/scfi-strp-2.d: New test.
* gas/scfi/aarch64/scfi-strp-2.l: New test.
* gas/scfi/aarch64/scfi-strp-2.s: New test.
* gas/scfi/aarch64/scfi-unsupported-1.l: New test.
* gas/scfi/aarch64/scfi-unsupported-1.s: New test.
* gas/scfi/aarch64/scfi-unsupported-2.l: New test.
* gas/scfi/aarch64/scfi-unsupported-2.s: New test.

59 files changed:
gas/testsuite/gas/scfi/README
gas/testsuite/gas/scfi/aarch64/ginsn-arith-1.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/ginsn-arith-1.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/ginsn-ldst-1.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/ginsn-ldst-1.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/ginsn-misc-1.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/ginsn-misc-1.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-aarch64.exp [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-1.d [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-1.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-1.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-2.d [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-2.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-2.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cb-1.d [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cb-1.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cb-1.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cfg-1.d [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cfg-1.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cfg-1.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cfg-2.d [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cfg-2.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cfg-2.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cfg-3.d [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cfg-3.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cfg-3.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cfg-4.d [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cfg-4.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cfg-4.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cond-br-1.d [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cond-br-1.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-cond-br-1.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-diag-1.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-diag-1.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-diag-2.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-diag-2.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-diag-3.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-diag-3.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-ldrp-1.d [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-ldrp-1.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-ldrp-1.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-ldrp-2.d [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-ldrp-2.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-ldrp-2.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-ldstnap-1.d [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-ldstnap-1.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-ldstnap-1.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-strp-1.d [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-strp-1.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-strp-1.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-strp-2.d [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-strp-2.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-strp-2.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-unsupported-1.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-unsupported-1.s [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-unsupported-2.l [new file with mode: 0644]
gas/testsuite/gas/scfi/aarch64/scfi-unsupported-2.s [new file with mode: 0644]

index ddb8a3d1320d765a7cd453a2b41f2159703b6e3e..c1d6d9d0a3e5527d1f559ca0497c18786552693a 100644 (file)
@@ -1,6 +1,6 @@
 Notes on the SCFI testsuite in GAS:
 
-* At this time, SCFI machinery is only supported for x86_64.
+* At this time, SCFI machinery is only supported for x86_64 and aarch64.
 
 * When adding more core SCFI tests (scfi-* tests), please keep CFI
   annotations updated in the .s files.  Ideally the test should be run with and
diff --git a/gas/testsuite/gas/scfi/aarch64/ginsn-arith-1.l b/gas/testsuite/gas/scfi/aarch64/ginsn-arith-1.l
new file mode 100644 (file)
index 0000000..de1fb2a
--- /dev/null
@@ -0,0 +1,40 @@
+.*: Assembler messages:
+.*:13: Error: SCFI: unsupported stack manipulation pattern
+.*:19: Error: SCFI: forward pass failed for func 'foo'
+
+AARCH64 GAS  .*
+
+
+   1                   # Testcase for a variety of arith instructions
+   2                           .text
+   3                           .align  2
+   4                           .global foo
+   5                           .type   foo, %function
+   5                   ginsn: SYM FUNC_BEGIN
+   6                   foo:
+   6                   ginsn: SYM foo
+   7 \?\?\?\? FF830091                 add     sp, sp, 32
+   7                   ginsn: ADD %r31, 32, %r31
+   8 \?\?\?\? FD5B21B1                 adds    x29, sp, 2134
+   8                   ginsn: ADD %r31, 2134, %r29
+   9 \?\?\?\? FF8300D1                 sub     sp, sp, 32
+   9                   ginsn: SUB %r31, 32, %r31
+  10 \?\?\?\? FD5B21F1                 subs    x29, sp, 2134
+  10                   ginsn: SUB %r31, 2134, %r29
+  11 \?\?\?\? FD63228B                 add     x29, sp, x2
+  11                   ginsn: ADD %r31, %r2, %r29
+  12 \?\?\?\? FD6323CB                 sub     x29, sp, x3
+  12                   ginsn: SUB %r31, %r3, %r29
+  13 \?\?\?\? BF63238B                 add     sp, x29, x3
+  13                   ginsn: ADD %r29, %r3, %r31
+  14 \?\?\?\? BF6322CB                 sub     sp, x29, x2
+  14                   ginsn: SUB %r29, %r2, %r31
+  15 \?\?\?\? 1F48220B                 add     wsp, w0, w2, lsl 2
+  15                   ginsn: OTH 0, 0, %r31
+  16 \?\?\?\? A4C0228B                 add     x4, x5, x2, sxtw
+  17 \?\?\?\? BFC0228B                 add     sp, x5, x2, sxtw
+  17                   ginsn: OTH 0, 0, %r31
+  18 \?\?\?\? C0035FD6                 ret
+  18                   ginsn: RET
+  19                           .size   foo, .-foo
+  19                   ginsn: SYM FUNC_END
diff --git a/gas/testsuite/gas/scfi/aarch64/ginsn-arith-1.s b/gas/testsuite/gas/scfi/aarch64/ginsn-arith-1.s
new file mode 100644 (file)
index 0000000..503196e
--- /dev/null
@@ -0,0 +1,19 @@
+# Testcase for a variety of arith instructions
+       .text
+       .align  2
+       .global foo
+       .type   foo, %function
+foo:
+       add     sp, sp, 32
+       adds    x29, sp, 2134
+       sub     sp, sp, 32
+       subs    x29, sp, 2134
+       add     x29, sp, x2
+       sub     x29, sp, x3
+       add     sp, x29, x3
+       sub     sp, x29, x2
+       add     wsp, w0, w2, lsl 2
+       add     x4, x5, x2, sxtw
+       add     sp, x5, x2, sxtw
+       ret
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.l b/gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.l
new file mode 100644 (file)
index 0000000..d05e19d
--- /dev/null
@@ -0,0 +1,30 @@
+.*: Assembler messages:
+.*:16: Error: untraceable control flow for func 'foo'
+
+AARCH64 GAS  .*
+
+   1                   # Testcase for a variety of change of flow instructions
+   2                   # Because some of these are indirect branches, SCFI will bail out
+   3                   # with an error.  This test merely checks that the ginsn creation
+   4                   # process can handle these insns gracefully.
+   5                           .text
+   6                           .align  2
+   7                           .global foo
+   8                           .type   foo, %function
+   8                   ginsn: SYM FUNC_BEGIN
+   9                   foo:
+   9                   ginsn: SYM foo
+  10 \?\?\?\? 00000094                 bl      dump_bt
+  10                   ginsn: CALL
+  11 \?\?\?\? 02000014                 b       .L3
+  11                   ginsn: JMP 
+  12 \?\?\?\? 20021FD6                 br      x17
+  12                   ginsn: JMP %r17, 
+  13                   .L3:
+  13                   ginsn: SYM .L3
+  14 \?\?\?\? 60003FD6                 blr     x3
+  14                   ginsn: CALL
+  15 \?\?\?\? C0035FD6                 ret
+  15                   ginsn: RET
+  16                           .size   foo, .-foo
+  16                   ginsn: SYM FUNC_END
diff --git a/gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.s b/gas/testsuite/gas/scfi/aarch64/ginsn-cofi-1.s
new file mode 100644 (file)
index 0000000..bbcbe4e
--- /dev/null
@@ -0,0 +1,16 @@
+# Testcase for a variety of change of flow instructions
+# Because some of these are indirect branches, SCFI will bail out
+# with an error.  This test merely checks that the ginsn creation
+# process can handle these insns gracefully.
+       .text
+       .align  2
+       .global foo
+       .type   foo, %function
+foo:
+       bl      dump_bt
+       b       .L3
+       br      x17
+.L3:
+       blr     x3
+       ret
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/ginsn-ldst-1.l b/gas/testsuite/gas/scfi/aarch64/ginsn-ldst-1.l
new file mode 100644 (file)
index 0000000..3471347
--- /dev/null
@@ -0,0 +1,101 @@
+AARCH64 GAS  .*
+
+   1                   # Testcase for a variety of ld st instructions.
+   2                   # stg ops must generate the sp update arithmetic insn, when applicable
+   3                   # due to writeback.
+   4                           .text
+   5                           .align  2
+   6                           .global foo
+   7                           .type   foo, %function
+   7                   ginsn: SYM FUNC_BEGIN
+   8                   foo:
+   8                   ginsn: SYM foo
+   9                   # ldstpair_indexed
+  10 0000 FF7F8629             stp     wzr, wzr, \[sp, 48\]!
+  10                   ginsn: ADD %r31, 48, %r31
+  11 0004 E00782A9             stp     x0, x1, \[sp, 32\]!
+  11                   ginsn: ADD %r31, 32, %r31
+  11                   ginsn: STORE %r0, \[%r31\+0\]
+  11                   ginsn: STORE %r1, \[%r31\+8\]
+  12 0008 E827BC6D             stp     d8, d9, \[sp, -64\]!
+  12                   ginsn: ADD %r31, -64, %r31
+  12                   ginsn: STORE %r72, \[%r31\+0\]
+  12                   ginsn: STORE %r73, \[%r31\+8\]
+  13 000c E827C46C             ldp     d8, d9, \[sp\], 64
+  13                   ginsn: LOAD \[%r31\+0\], %r72
+  13                   ginsn: LOAD \[%r31\+8\], %r73
+  13                   ginsn: ADD %r31, 64, %r31
+  14                   # 32-bit FP regs
+  15 0010 E51BB42D             stp     s5, s6, \[sp, -96\]!
+  15                   ginsn: ADD %r31, -96, %r31
+  16 0014 E51BCC2C             ldp     s5, s6, \[sp\], 96
+  16                   ginsn: ADD %r31, 96, %r31
+  17                   # 32-bit INT regs
+  18 0018 E10BB029             stp     w1, w2, \[sp, -128\]!
+  18                   ginsn: ADD %r31, -128, %r31
+  19 001c E10BD028             ldp     w1, w2, \[sp\], 128
+  19                   ginsn: ADD %r31, 128, %r31
+  20                   # ldstpair_off
+  21 0020 E00702AD             stp     q0, q1, \[sp, 64\]
+  21                   ginsn: STORE %r64, \[%r31\+64\]
+  21                   ginsn: STORE %r65, \[%r31\+80\]
+  22 0024 FF7F0629             stp     wzr, wzr, \[sp, 48\]
+  23 0028 1F7840AD             ldp     q31, q30, \[x0\]
+  23                   ginsn: LOAD \[%r0\+0\], %r95
+  23                   ginsn: LOAD \[%r0\+16\], %r94
+  24 002c FF4F01A9             stp     xzr, x19, \[sp, 16\]
+  24                   ginsn: STORE %r19, \[%r31\+24\]
+  25 0030 F37F01A9             stp     x19, xzr, \[sp, 16\]
+  25                   ginsn: STORE %r19, \[%r31\+16\]
+  26                   # ldst_imm9
+  27 0034 E78F4F38             ldrb    w7, \[sp, 248\]!
+  27                   ginsn: ADD %r31, 248, %r31
+  28 0038 FD0FC33C             ldr     q29, \[sp, 48\]!
+  28                   ginsn: ADD %r31, 48, %r31
+  28                   ginsn: LOAD \[%r31\+0\], %r93
+  29 003c FF0F42B8             ldr     wzr, \[sp, 32\]!
+  29                   ginsn: ADD %r31, 32, %r31
+  30 0040 E30742F8             ldr     x3, \[sp\], 32
+  30                   ginsn: LOAD \[%r31\+0\], %r3
+\fAARCH64 GAS  .*
+
+
+  30                   ginsn: ADD %r31, 32, %r31
+  31                   # 32-bit ldr
+  32 0044 E10744BC             ldr     s1, \[sp\], 64
+  32                   ginsn: ADD %r31, 64, %r31
+  33                   # ldst_pos
+  34 0048 FF3340B9             ldr     wzr, \[sp, 48\]
+  35 004c FD1300F9             str     x29, \[sp, 32\]
+  35                   ginsn: STORE %r29, \[%r31\+32\]
+  36 0050 FD1340F9             ldr     x29, \[sp, 32\]
+  36                   ginsn: LOAD \[%r31\+32\], %r29
+  37                   # store tag
+  38 0054 FF2F20D9             stg     sp, \[sp, 32\]!
+  38                   ginsn: ADD %r31, 32, %r31
+  39                   # store tag pair
+  40 0058 FBF38169             stgp    x27, x28, \[sp, 48\]!
+  40                   ginsn: ADD %r31, 48, %r31
+  41                   # ldpsw / ldrsw
+  42 005c F353E069             ldpsw   x19, x20, \[sp, -256\]!
+  42                   ginsn: ADD %r31, -256, %r31
+  43 0060 F50F98B8             ldrsw   x21, \[sp, -128\]!
+  43                   ginsn: ADD %r31, -128, %r31
+  44                   # ldrsb / ldrsh
+  45 0064 F70F9938             ldrsb   x23, \[sp, -112\]!
+  45                   ginsn: ADD %r31, -112, %r31
+  46 0068 F88F9978             ldrsh   x24, \[sp, -104\]!
+  46                   ginsn: ADD %r31, -104, %r31
+  47                   # ldrb / ldrh / strb / strh
+  48 006c F90F5A38             ldrb    w25, \[sp, -96\]!
+  48                   ginsn: ADD %r31, -96, %r31
+  49 0070 FA8F5A78             ldrh    w26, \[sp, -88\]!
+  49                   ginsn: ADD %r31, -88, %r31
+  50 0074 F90F1A38             strb    w25, \[sp, -96\]!
+  50                   ginsn: ADD %r31, -96, %r31
+  51 0078 FA8F1A78             strh    w26, \[sp, -88\]!
+  51                   ginsn: ADD %r31, -88, %r31
+  52 007c C0035FD6             ret
+  52                   ginsn: RET
+  53                           .size   foo, .-foo
+  53                   ginsn: SYM FUNC_END
diff --git a/gas/testsuite/gas/scfi/aarch64/ginsn-ldst-1.s b/gas/testsuite/gas/scfi/aarch64/ginsn-ldst-1.s
new file mode 100644 (file)
index 0000000..98df9c6
--- /dev/null
@@ -0,0 +1,53 @@
+# Testcase for a variety of ld st instructions.
+# stg ops must generate the sp update arithmetic insn, when applicable
+# due to writeback.
+       .text
+       .align  2
+       .global foo
+       .type   foo, %function
+foo:
+# ldstpair_indexed
+       stp     wzr, wzr, [sp, 48]!
+       stp     x0, x1, [sp, 32]!
+       stp     d8, d9, [sp, -64]!
+       ldp     d8, d9, [sp], 64
+# 32-bit FP regs
+       stp     s5, s6, [sp, -96]!
+       ldp     s5, s6, [sp], 96
+# 32-bit INT regs
+       stp     w1, w2, [sp, -128]!
+       ldp     w1, w2, [sp], 128
+# ldstpair_off
+       stp     q0, q1, [sp, 64]
+       stp     wzr, wzr, [sp, 48]
+       ldp     q31, q30, [x0]
+        stp     xzr, x19, [sp, 16]
+        stp     x19, xzr, [sp, 16]
+# ldst_imm9
+       ldrb    w7, [sp, 248]!
+       ldr     q29, [sp, 48]!
+       ldr     wzr, [sp, 32]!
+       ldr     x3, [sp], 32
+# 32-bit ldr
+       ldr     s1, [sp], 64
+# ldst_pos
+       ldr     wzr, [sp, 48]
+       str     x29, [sp, 32]
+       ldr     x29, [sp, 32]
+# store tag
+       stg     sp, [sp, 32]!
+# store tag pair
+       stgp    x27, x28, [sp, 48]!
+# ldpsw / ldrsw
+       ldpsw   x19, x20, [sp, -256]!
+       ldrsw   x21, [sp, -128]!
+# ldrsb / ldrsh
+       ldrsb   x23, [sp, -112]!
+       ldrsh   x24, [sp, -104]!
+# ldrb / ldrh / strb / strh
+       ldrb    w25, [sp, -96]!
+       ldrh    w26, [sp, -88]!
+       strb    w25, [sp, -96]!
+       strh    w26, [sp, -88]!
+       ret
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/ginsn-misc-1.l b/gas/testsuite/gas/scfi/aarch64/ginsn-misc-1.l
new file mode 100644 (file)
index 0000000..7bd70e3
--- /dev/null
@@ -0,0 +1,48 @@
+.*: Assembler messages:
+.*:13: Error: SCFI: unsupported stack manipulation pattern
+.*:33: Error: SCFI: forward pass failed for func 'foo'
+
+AARCH64 GAS  .*
+
+
+   1                   # Testcase for a variety of misc instructions.
+   2                   # Ensure graceful handling, irrespective of ginsn generation.
+   3                   # - ldrsw, ldpsw ops need a mention: they are 32-bit loads from memory
+   4                   #   and cannot be used for reg restore.  For CFI purposes, the width has to be
+   5                   #   8 bytes or more. Expect no memory ginsn ever as ginsn do not track width
+   6                   #   of memory accesses yet.
+   7                   symbol:
+   8 \?\?\?\? 7700                     .string "w"
+   9                   
+  10                           .type   foo, %function
+  10                   ginsn: SYM FUNC_BEGIN
+  11                   foo:
+  11                   ginsn: SYM foo
+  12 \?\?\?\? 00000000                 adrp    x0, symbol
+  12      0090
+  13 \?\?\?\? 1F000091                 add     sp, x0, :lo12:symbol
+  13                   ginsn: OTH 0, 0, %r31
+  14 \?\?\?\? 2000A0F2                 movk    x0, 0x1, lsl 16
+  15 \?\?\?\? E10380F9                 prfm    PLDL1STRM, \[sp\]
+  16 \?\?\?\? E013DF9A                 irg     x0, sp
+  17 \?\?\?\? 000820D9                 stg     x0, \[x0\]
+  18 \?\?\?\? F5DB3C69                 stgp    x21, x22, \[sp, -112\]
+  19 \?\?\?\? E03FBF91                 addg    x0, sp, #0x3f0, #0xf
+  20 \?\?\?\? 1F3CAA91                 addg    sp, x0, #0x2a0, #0xf
+  20                   ginsn: OTH 0, 0, %r31
+  21 \?\?\?\? F4577069                 ldpsw   x20, x21, \[sp, -128\]
+  22 \?\?\?\? F3534069                 ldpsw   x19, x20, \[sp\]
+  23 \?\?\?\? 9B0080B9                 ldrsw   x27, \[x4\]
+  24 \?\?\?\? F4038039                 ldrsb   x20, \[sp\]
+  25 \?\?\?\? F4038079                 ldrsh   x20, \[sp\]
+  26                   # Test a few insn with wzr / xzr
+  27 \?\?\?\? 3F0480D2                 mov     xzr, 33
+  28 \?\?\?\? E0031FAA                 mov     x0, xzr
+  29 \?\?\?\? 1F00018B                 add     xzr, x0, x1
+  30 \?\?\?\? 3F603F8B                 add     sp, x1, xzr
+  30                   ginsn: ADD %r1, %r31, %r31
+  31 \?\?\?\? FF031F8B                 add     xzr, xzr, xzr
+  32 \?\?\?\? C0035FD6                 ret
+  32                   ginsn: RET
+  33                           .size   foo,.-foo
+  33                   ginsn: SYM FUNC_END
diff --git a/gas/testsuite/gas/scfi/aarch64/ginsn-misc-1.s b/gas/testsuite/gas/scfi/aarch64/ginsn-misc-1.s
new file mode 100644 (file)
index 0000000..ddce948
--- /dev/null
@@ -0,0 +1,33 @@
+# Testcase for a variety of misc instructions.
+# Ensure graceful handling, irrespective of ginsn generation.
+# - ldrsw, ldpsw ops need a mention: they are 32-bit loads from memory
+#   and cannot be used for reg restore.  For CFI purposes, the width has to be
+#   8 bytes or more. Expect no memory ginsn ever as ginsn do not track width
+#   of memory accesses yet.
+symbol:
+       .string "w"
+
+       .type   foo, %function
+foo:
+       adrp    x0, symbol
+       add     sp, x0, :lo12:symbol
+       movk    x0, 0x1, lsl 16
+       prfm    PLDL1STRM, [sp]
+       irg     x0, sp
+       stg     x0, [x0]
+       stgp    x21, x22, [sp, -112]
+       addg    x0, sp, #0x3f0, #0xf
+       addg    sp, x0, #0x2a0, #0xf
+       ldpsw   x20, x21, [sp, -128]
+        ldpsw   x19, x20, [sp]
+        ldrsw   x27, [x4]
+       ldrsb   x20, [sp]
+       ldrsh   x20, [sp]
+# Test a few insn with wzr / xzr
+        mov     xzr, 33
+        mov     x0, xzr
+        add     xzr, x0, x1
+        add     sp, x1, xzr
+       add     xzr, xzr, xzr
+       ret
+       .size   foo,.-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-aarch64.exp b/gas/testsuite/gas/scfi/aarch64/scfi-aarch64.exp
new file mode 100644 (file)
index 0000000..9a0b285
--- /dev/null
@@ -0,0 +1,74 @@
+# Copyright (C) 2022-2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+
+if { ![is_elf_format] } then {
+    return
+}
+
+# common tests
+if  { ([istarget "aarch64-*-*"]) } then {
+
+    global ASFLAGS
+    set old_ASFLAGS "$ASFLAGS"
+
+    run_list_test "ginsn-arith-1" "--scfi=experimental -ali --warn"
+    run_list_test "ginsn-cofi-1" "--scfi=experimental -ali --warn"
+    run_list_test "ginsn-ldst-1" "--scfi=experimental -march=armv8-a+memtag -ali --warn"
+    run_list_test "ginsn-misc-1" "--scfi=experimental -march=armv8-a+memtag -ali --warn"
+
+    run_list_test "scfi-diag-1" "--scfi=experimental"
+    run_list_test "scfi-diag-2" "--scfi=experimental"
+    run_list_test "scfi-diag-3" "--scfi=experimental"
+
+    run_list_test "scfi-unsupported-1" "--scfi=experimental"
+    run_list_test "scfi-unsupported-2" "--scfi=experimental"
+
+    run_dump_test "scfi-callee-saved-fp-1"
+    run_list_test "scfi-callee-saved-fp-1" "--scfi=experimental --warn"
+    run_dump_test "scfi-callee-saved-fp-2"
+    run_list_test "scfi-callee-saved-fp-2" "--scfi=experimental --warn"
+
+    run_dump_test "scfi-ldrp-1"
+    run_list_test "scfi-ldrp-1" "--scfi=experimental --warn"
+    run_dump_test "scfi-ldrp-2"
+    run_list_test "scfi-ldrp-2" "--scfi=experimental --warn"
+
+    run_dump_test "scfi-strp-1"
+    run_list_test "scfi-strp-1" "--scfi=experimental --warn"
+    run_dump_test "scfi-strp-2"
+    run_list_test "scfi-strp-2" "--scfi=experimental --warn"
+
+    run_dump_test "scfi-ldstnap-1"
+    run_list_test "scfi-ldstnap-1" "--scfi=experimental --warn"
+
+    run_dump_test "scfi-cb-1"
+    run_list_test "scfi-cb-1" "--scfi=experimental --warn"
+    run_dump_test "scfi-cond-br-1"
+    run_list_test "scfi-cond-br-1" "--scfi=experimental --warn"
+
+    run_dump_test "scfi-cfg-1"
+    run_list_test "scfi-cfg-1" "--scfi=experimental --warn"
+
+    run_dump_test "scfi-cfg-2"
+    run_list_test "scfi-cfg-2" "--scfi=experimental --warn"
+
+    run_dump_test "scfi-cfg-3"
+    run_list_test "scfi-cfg-3" "--scfi=experimental --warn"
+
+    run_dump_test "scfi-cfg-4"
+    run_list_test "scfi-cfg-4" "--scfi=experimental --warn"
+
+}
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-1.d b/gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-1.d
new file mode 100644 (file)
index 0000000..da4b8a0
--- /dev/null
@@ -0,0 +1,57 @@
+#as: --scfi=experimental -W
+#objdump: -Wf
+#name: Synthesize CFI for callee-saved FP regs I
+#...
+Contents of the .eh_frame section:
+
+00000000 0+0010 00000000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 4
+  Data alignment factor: -8
+  Return address column: 30
+  Augmentation data:     1b
+  DW_CFA_def_cfa: r31 \(sp\) ofs 0
+
+00000014 0+[0-9a-f]+ 0+0018 FDE cie=00000000 pc=0+0000..0+0040
+  DW_CFA_advance_loc: 4 to 0+0004
+  DW_CFA_def_cfa_offset: 128
+  DW_CFA_offset: r29 \(x29\) at cfa-128
+  DW_CFA_offset: r30 \(x30\) at cfa-120
+  DW_CFA_advance_loc: 4 to 0+0008
+  DW_CFA_def_cfa_register: r29 \(x29\)
+  DW_CFA_advance_loc: 4 to 0+000c
+  DW_CFA_offset_extended: r72 \(v8\) at cfa-112
+  DW_CFA_advance_loc: 4 to 0+0010
+  DW_CFA_offset_extended: r73 \(v9\) at cfa-104
+  DW_CFA_advance_loc: 4 to 0+0014
+  DW_CFA_offset_extended: r74 \(v10\) at cfa-96
+  DW_CFA_offset_extended: r75 \(v11\) at cfa-88
+  DW_CFA_advance_loc: 4 to 0+0018
+  DW_CFA_offset_extended: r76 \(v12\) at cfa-80
+  DW_CFA_offset_extended: r77 \(v13\) at cfa-72
+  DW_CFA_advance_loc: 4 to 0+001c
+  DW_CFA_offset_extended: r78 \(v14\) at cfa-64
+  DW_CFA_offset_extended: r79 \(v15\) at cfa-56
+  DW_CFA_advance_loc: 8 to 0+0024
+  DW_CFA_def_cfa_register: r31 \(sp\)
+  DW_CFA_advance_loc: 4 to 0+0028
+  DW_CFA_restore_extended: r72 \(v8\)
+  DW_CFA_advance_loc: 4 to 0+002c
+  DW_CFA_restore_extended: r73 \(v9\)
+  DW_CFA_advance_loc: 4 to 0+0030
+  DW_CFA_restore_extended: r74 \(v10\)
+  DW_CFA_restore_extended: r75 \(v11\)
+  DW_CFA_advance_loc: 4 to 0+0034
+  DW_CFA_restore_extended: r76 \(v12\)
+  DW_CFA_restore_extended: r77 \(v13\)
+  DW_CFA_advance_loc: 4 to 0+0038
+  DW_CFA_restore_extended: r78 \(v14\)
+  DW_CFA_restore_extended: r79 \(v15\)
+  DW_CFA_advance_loc: 4 to 0+003c
+  DW_CFA_restore: r29 \(x29\)
+  DW_CFA_restore: r30 \(x30\)
+  DW_CFA_def_cfa_offset: 0
+  DW_CFA_nop
+
+#pass
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-1.l b/gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-1.l
new file mode 100644 (file)
index 0000000..5ff6048
--- /dev/null
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*8: Warning: SCFI ignores most user-specified CFI directives
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-1.s b/gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-1.s
new file mode 100644 (file)
index 0000000..0f7afe2
--- /dev/null
@@ -0,0 +1,50 @@
+# Testcase for callee-saved FP registers.
+# Uses a combination of str/stp and ldr/ldp
+       .text
+       .align  2
+       .global foo
+       .type   foo, %function
+foo:
+       .cfi_startproc
+       stp     x29, x30, [sp, -128]!
+       .cfi_def_cfa_offset 128
+       .cfi_offset 29, -128
+       .cfi_offset 30, -120
+       mov     x29, sp
+       .cfi_def_cfa_register 29
+       str     d8, [sp, 16]
+       .cfi_offset 72, -112
+       str     d9, [sp, 24]
+       .cfi_offset 73, -104
+       stp     d10, d11, [sp, 32]
+       .cfi_offset 74, -96
+       .cfi_offset 75, -88
+       stp     d12, d13, [sp, 48]
+       .cfi_offset 76, -80
+       .cfi_offset 77, -72
+       stp     d14, d15, [sp, 64]
+       .cfi_offset 78, -64
+       .cfi_offset 79, -56
+       mov     w0, 0
+       mov     sp, x29
+       .cfi_def_cfa_register 31
+       ldr     d8, [sp, 16]
+       .cfi_restore 72
+       ldr     d9, [sp, 24]
+       .cfi_restore 73
+       ldp     d10, d11, [sp, 32]
+       .cfi_restore 74
+       .cfi_restore 75
+       ldp     d12, d13, [sp, 48]
+       .cfi_restore 76
+       .cfi_restore 77
+       ldp     d14, d15, [sp, 64]
+       .cfi_restore 78
+       .cfi_restore 79
+       ldp     x29, x30, [sp], 128
+       .cfi_restore 29
+       .cfi_restore 30
+       .cfi_def_cfa_offset 0
+       ret
+       .cfi_endproc
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-2.d b/gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-2.d
new file mode 100644 (file)
index 0000000..0e3de4c
--- /dev/null
@@ -0,0 +1,57 @@
+#as: --scfi=experimental -W -mbig-endian
+#objdump: -Wf
+#name: Synthesize CFI for callee-saved FP regs BE II
+#...
+Contents of the .eh_frame section:
+
+00000000 0+0010 00000000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 4
+  Data alignment factor: -8
+  Return address column: 30
+  Augmentation data:     1b
+  DW_CFA_def_cfa: r31 \(sp\) ofs 0
+
+00000014 0+[0-9a-f]+ 0+0018 FDE cie=00000000 pc=0+0000..0+0040
+  DW_CFA_advance_loc: 4 to 0+0004
+  DW_CFA_def_cfa_offset: 256
+  DW_CFA_offset: r29 \(x29\) at cfa-256
+  DW_CFA_offset: r30 \(x30\) at cfa-248
+  DW_CFA_advance_loc: 4 to 0+0008
+  DW_CFA_def_cfa_register: r29 \(x29\)
+  DW_CFA_advance_loc: 4 to 0+000c
+  DW_CFA_offset_extended: r72 \(v8\) at cfa-232
+  DW_CFA_advance_loc: 4 to 0+0010
+  DW_CFA_offset_extended: r73 \(v9\) at cfa-216
+  DW_CFA_advance_loc: 4 to 0+0014
+  DW_CFA_offset_extended: r74 \(v10\) at cfa-184
+  DW_CFA_offset_extended: r75 \(v11\) at cfa-168
+  DW_CFA_advance_loc: 4 to 0+0018
+  DW_CFA_offset_extended: r76 \(v12\) at cfa-152
+  DW_CFA_offset_extended: r77 \(v13\) at cfa-136
+  DW_CFA_advance_loc: 4 to 0+001c
+  DW_CFA_offset_extended: r78 \(v14\) at cfa-120
+  DW_CFA_offset_extended: r79 \(v15\) at cfa-104
+  DW_CFA_advance_loc: 8 to 0+0024
+  DW_CFA_def_cfa_register: r31 \(sp\)
+  DW_CFA_advance_loc: 4 to 0+0028
+  DW_CFA_restore_extended: r72 \(v8\)
+  DW_CFA_advance_loc: 4 to 0+002c
+  DW_CFA_restore_extended: r73 \(v9\)
+  DW_CFA_advance_loc: 4 to 0+0030
+  DW_CFA_restore_extended: r74 \(v10\)
+  DW_CFA_restore_extended: r75 \(v11\)
+  DW_CFA_advance_loc: 4 to 0+0034
+  DW_CFA_restore_extended: r76 \(v12\)
+  DW_CFA_restore_extended: r77 \(v13\)
+  DW_CFA_advance_loc: 4 to 0+0038
+  DW_CFA_restore_extended: r78 \(v14\)
+  DW_CFA_restore_extended: r79 \(v15\)
+  DW_CFA_advance_loc: 4 to 0+003c
+  DW_CFA_restore: r29 \(x29\)
+  DW_CFA_restore: r30 \(x30\)
+  DW_CFA_def_cfa_offset: 0
+  DW_CFA_nop
+
+#pass
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-2.l b/gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-2.l
new file mode 100644 (file)
index 0000000..5ff6048
--- /dev/null
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*8: Warning: SCFI ignores most user-specified CFI directives
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-2.s b/gas/testsuite/gas/scfi/aarch64/scfi-callee-saved-fp-2.s
new file mode 100644 (file)
index 0000000..4204daf
--- /dev/null
@@ -0,0 +1,50 @@
+# Testcase for callee-saved FP registers.
+# Use Q registers
+       .text
+       .align  2
+       .global foo
+       .type   foo, %function
+foo:
+       .cfi_startproc
+       stp     x29, x30, [sp, -256]!
+       .cfi_def_cfa_offset 256
+       .cfi_offset 29, -256
+       .cfi_offset 30, -248
+       mov     x29, sp
+       .cfi_def_cfa_register 29
+       str     q8, [sp, 16]
+       .cfi_offset 72, -232
+       str     q9, [sp, 32]
+       .cfi_offset 73, -216
+       stp     q10, q11, [sp, 64]
+       .cfi_offset 74, -184
+       .cfi_offset 75, -168
+       stp     q12, q13, [sp, 96]
+       .cfi_offset 76, -152
+       .cfi_offset 77, -136
+       stp     q14, q15, [sp, 128]
+       .cfi_offset 78, -120
+       .cfi_offset 79, -104
+       mov     w0, 0
+       mov     sp, x29
+       .cfi_def_cfa_register 31
+       ldr     q8, [sp, 16]
+       .cfi_restore 72
+       ldr     q9, [sp, 32]
+       .cfi_restore 73
+       ldp     q10, q11, [sp, 64]
+       .cfi_restore 74
+       .cfi_restore 75
+       ldp     q12, q13, [sp, 96]
+       .cfi_restore 76
+       .cfi_restore 77
+       ldp     q14, q15, [sp, 128]
+       .cfi_restore 78
+       .cfi_restore 79
+       ldp     x29, x30, [sp], 256
+       .cfi_restore 29
+       .cfi_restore 30
+       .cfi_def_cfa_offset 0
+       ret
+       .cfi_endproc
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cb-1.d b/gas/testsuite/gas/scfi/aarch64/scfi-cb-1.d
new file mode 100644 (file)
index 0000000..87583c5
--- /dev/null
@@ -0,0 +1,20 @@
+#as: --scfi=experimental -W
+#objdump: -Wf
+#name: Synthesize CFI for comp branch 1
+#...
+Contents of the .eh_frame section:
+
+
+0+0000 0+0010 0+0000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 4
+  Data alignment factor: -8
+  Return address column: 30
+  Augmentation data:     1b
+  DW_CFA_def_cfa: r31 \(sp\) ofs 0
+
+0+0014 0+0010 00000018 FDE cie=00000000 pc=0+0000..0+0014
+  DW_CFA_nop
+
+#pass
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cb-1.l b/gas/testsuite/gas/scfi/aarch64/scfi-cb-1.l
new file mode 100644 (file)
index 0000000..abca835
--- /dev/null
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*5: Warning: SCFI ignores most user-specified CFI directives
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cb-1.s b/gas/testsuite/gas/scfi/aarch64/scfi-cb-1.s
new file mode 100644 (file)
index 0000000..1fa7de7
--- /dev/null
@@ -0,0 +1,14 @@
+       .text
+       .global foo
+       .type  foo, %function
+foo:
+       .cfi_startproc
+.L7:
+       add     w4, w3, w1
+       cbnz    w4, .L7
+       cbz     w4, .L10
+       tbnz    w0, #31, .L7
+.L10:
+       ret
+       .cfi_endproc
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cfg-1.d b/gas/testsuite/gas/scfi/aarch64/scfi-cfg-1.d
new file mode 100644 (file)
index 0000000..9dca6ef
--- /dev/null
@@ -0,0 +1,31 @@
+#as: --scfi=experimental -W
+#objdump: -Wf
+#name: Synthesize CFI for cfg 1
+#...
+Contents of the .eh_frame section:
+
+
+0+0000 0+0010 0+0000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 4
+  Data alignment factor: -8
+  Return address column: 30
+  Augmentation data:     1b
+  DW_CFA_def_cfa: r31 \(sp\) ofs 0
+
+0+0014 0+0020 0+0018 FDE cie=00000000 pc=0+0000..0+0068
+  DW_CFA_advance_loc: 4 to 0+0004
+  DW_CFA_def_cfa_offset: 48
+  DW_CFA_offset: r29 \(x29\) at cfa-48
+  DW_CFA_offset: r30 \(x30\) at cfa-40
+  DW_CFA_advance_loc: 4 to 0+0008
+  DW_CFA_def_cfa_register: r29 \(x29\)
+  DW_CFA_advance_loc: 92 to 0+0064
+  DW_CFA_def_cfa_register: r31 \(sp\)
+  DW_CFA_restore: r29 \(x29\)
+  DW_CFA_restore: r30 \(x30\)
+  DW_CFA_def_cfa_offset: 0
+  DW_CFA_nop
+
+#pass
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cfg-1.l b/gas/testsuite/gas/scfi/aarch64/scfi-cfg-1.l
new file mode 100644 (file)
index 0000000..bcf3095
--- /dev/null
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*6: Warning: SCFI ignores most user-specified CFI directives
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cfg-1.s b/gas/testsuite/gas/scfi/aarch64/scfi-cfg-1.s
new file mode 100644 (file)
index 0000000..6925a8f
--- /dev/null
@@ -0,0 +1,46 @@
+# Testcase for forward flow of SCFI information
+# and CFG creation as well.  This testcase has two backward edges
+# (one of which is a loop) and one exit path.
+       .type   foo, %function
+foo:
+       .cfi_startproc
+       stp    x29, x30, [sp, -48]!
+       .cfi_def_cfa_offset 48
+       .cfi_offset 29, -48
+       .cfi_offset 30, -40
+       mov     x29, sp
+       .cfi_def_cfa_register 29
+       str     x0, [sp, 24]
+       adrp    x0, :got:xyz
+       str     x0, [sp, 40]
+       b       .L7
+.L10:
+       ldr     x0, [sp, 40]
+       ldr     x0, [x0]
+       mov     x1, x0
+       ldr     x0, [sp, 24]
+       bl      strcmp
+       cmp     w0, 0
+       bne     .L8
+       ldr     x0, [sp, 40]
+       ldr     w0, [x0, 8]
+       b       .L9
+.L8:
+       ldr     x0, [sp, 40]
+       add     x0, x0, 24
+       str     x0, [sp, 40]
+.L7:
+       ldr     x0, [sp, 40]
+       ldr     w0, [x0, 8]
+       cmp     w0, 0
+       bne     .L10
+       mov     w0, 0
+.L9:
+       ldp     x29, x30, [sp], 48
+       .cfi_def_cfa_register 31
+       .cfi_restore 30
+       .cfi_restore 29
+       .cfi_def_cfa_offset 0
+       ret
+       .cfi_endproc
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cfg-2.d b/gas/testsuite/gas/scfi/aarch64/scfi-cfg-2.d
new file mode 100644 (file)
index 0000000..af21fc1
--- /dev/null
@@ -0,0 +1,40 @@
+#as: --scfi=experimental -W
+#objdump: -Wf
+#name: Synthesize CFI for cfg 2
+#...
+Contents of the .eh_frame section:
+
+
+0+0000 0+0010 0+0000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 4
+  Data alignment factor: -8
+  Return address column: 30
+  Augmentation data:     1b
+  DW_CFA_def_cfa: r31 \(sp\) ofs 0
+
+0+0014 0+[0-9a-f]+ 0+0018 FDE cie=00000000 pc=0+0000..0+0028
+  DW_CFA_advance_loc: 4 to 0+0004
+  DW_CFA_def_cfa_offset: 48
+  DW_CFA_offset: r29 \(x29\) at cfa-48
+  DW_CFA_offset: r30 \(x30\) at cfa-40
+  DW_CFA_advance_loc: 4 to 0+0008
+  DW_CFA_def_cfa_register: r29 \(x29\)
+  DW_CFA_advance_loc: 8 to 0+0010
+  DW_CFA_remember_state
+  DW_CFA_advance_loc: 8 to 0+0018
+  DW_CFA_def_cfa_register: r31 \(sp\)
+  DW_CFA_restore: r29 \(x29\)
+  DW_CFA_restore: r30 \(x30\)
+  DW_CFA_def_cfa_offset: 0
+  DW_CFA_advance_loc: 4 to 0+001c
+  DW_CFA_restore_state
+  DW_CFA_advance_loc: 8 to 0+0024
+  DW_CFA_def_cfa_register: r31 \(sp\)
+  DW_CFA_restore: r29 \(x29\)
+  DW_CFA_restore: r30 \(x30\)
+  DW_CFA_def_cfa_offset: 0
+  DW_CFA_nop
+
+#pass
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cfg-2.l b/gas/testsuite/gas/scfi/aarch64/scfi-cfg-2.l
new file mode 100644 (file)
index 0000000..e9bde33
--- /dev/null
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*13: Warning: SCFI ignores most user-specified CFI directives
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cfg-2.s b/gas/testsuite/gas/scfi/aarch64/scfi-cfg-2.s
new file mode 100644 (file)
index 0000000..eef82b4
--- /dev/null
@@ -0,0 +1,42 @@
+# Testcase for backward flow of SCFI state.
+# The cfg has two exit paths, with epilogue duplicated in
+# the two.
+#
+# SCFI must synthesize the remember_state / restore_state pair.
+# Note how SCFI does not necessary generate the least number of
+# CFI directives (.cfi_remember_state can possibly be clubbed
+# together with other immediately following CFI directives).
+# This is not a correctness issue, however.
+       .global foo
+       .type   foo, %function
+foo:
+       .cfi_startproc
+       stp     x29, x30, [sp, -48]!
+       .cfi_def_cfa_offset 48
+       .cfi_offset 29, -48
+       .cfi_offset 30, -40
+       mov     x29, sp
+       .cfi_def_cfa_register 29
+       cmp     w4, w19
+       bge     .L1
+
+.L2:
+       .cfi_remember_state
+       bl      bar
+       ldp     x29, x30, [sp], 48
+       .cfi_def_cfa_register 31
+       .cfi_restore 29
+       .cfi_restore 30
+       .cfi_def_cfa_offset 0
+       ret
+.L1:
+       .cfi_restore_state
+       cbz     w3, .L2
+       ldp     x29, x30, [sp], 48
+       .cfi_def_cfa_register 31
+       .cfi_restore 29
+       .cfi_restore 30
+       .cfi_def_cfa_offset 0
+       ret
+       .cfi_endproc
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cfg-3.d b/gas/testsuite/gas/scfi/aarch64/scfi-cfg-3.d
new file mode 100644 (file)
index 0000000..4d17ee4
--- /dev/null
@@ -0,0 +1,32 @@
+#as: --scfi=experimental -W
+#objdump: -Wf
+#name: Synthesize CFI for cfg 3
+#...
+Contents of the .eh_frame section:
+
+
+0+0000 0+0010 0+0000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 4
+  Data alignment factor: -8
+  Return address column: 30
+  Augmentation data:     1b
+  DW_CFA_def_cfa: r31 \(sp\) ofs 0
+
+0+0014 0+0020 0+0018 FDE cie=00000000 pc=0+0000..0+002c
+  DW_CFA_advance_loc: 4 to 0+0004
+  DW_CFA_def_cfa_offset: 32
+  DW_CFA_offset: r29 \(x29\) at cfa-32
+  DW_CFA_offset: r30 \(x30\) at cfa-24
+  DW_CFA_advance_loc: 4 to 0+0008
+  DW_CFA_def_cfa_register: r29 \(x29\)
+  DW_CFA_advance_loc: 32 to 0+0028
+  DW_CFA_def_cfa_register: r31 \(sp\)
+  DW_CFA_restore: r29 \(x29\)
+  DW_CFA_restore: r30 \(x30\)
+  DW_CFA_def_cfa_offset: 0
+  DW_CFA_nop
+  DW_CFA_nop
+
+#pass
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cfg-3.l b/gas/testsuite/gas/scfi/aarch64/scfi-cfg-3.l
new file mode 100644 (file)
index 0000000..23ca734
--- /dev/null
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*9: Warning: SCFI ignores most user-specified CFI directives
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cfg-3.s b/gas/testsuite/gas/scfi/aarch64/scfi-cfg-3.s
new file mode 100644 (file)
index 0000000..2782e11
--- /dev/null
@@ -0,0 +1,34 @@
+# Testcase for cfg creation.
+# There is at least one bb here with a single GINSN_TYPE_SYMBOL instruction
+# for a user-defined label.  This ginsn is visited in the fallthrough path of
+# another bb.
+       .text
+       .global main
+       .type   main, %function
+main:
+       .cfi_startproc
+       stp     x29, x30, [sp, -32]!
+       .cfi_def_cfa_offset 32
+       .cfi_offset 29, -32
+       .cfi_offset 30, -24
+       mov     x29, sp
+       .cfi_def_cfa_register 29
+       cmp     w0, 0
+       bne     .L2
+#      ldr     x0, [sp, 24]
+#      bl      fclose
+       cmp     w0, 0
+       beq     .L3
+.L2:
+       mov     w0, 1
+       b       .L5
+.L3:
+       mov     w0, 0
+.L5:
+       ldp     x29, x30, [sp], 32
+       .cfi_def_cfa_register 31
+       .cfi_restore 29
+       .cfi_restore 30
+       .cfi_def_cfa_offset 0
+       ret
+       .cfi_endproc
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cfg-4.d b/gas/testsuite/gas/scfi/aarch64/scfi-cfg-4.d
new file mode 100644 (file)
index 0000000..6a23818
--- /dev/null
@@ -0,0 +1,41 @@
+#as: --scfi=experimental -W
+#objdump: -Wf
+#name: Synthesize CFI for cfg 4
+#...
+Contents of the .eh_frame section:
+
+
+0+0000 0+0010 0+0000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 4
+  Data alignment factor: -8
+  Return address column: 30
+  Augmentation data:     1b
+  DW_CFA_def_cfa: r31 \(sp\) ofs 0
+
+0+0014 0+[0-9a-f]+ 0+0018 FDE cie=00000000 pc=0+0000..0+002c
+  DW_CFA_advance_loc: 4 to 0+0004
+  DW_CFA_def_cfa_offset: 32
+  DW_CFA_offset: r29 \(x29\) at cfa-32
+  DW_CFA_offset: r30 \(x30\) at cfa-24
+  DW_CFA_advance_loc: 4 to 0+0008
+  DW_CFA_def_cfa_register: r29 \(x29\)
+  DW_CFA_advance_loc: 8 to 0+0010
+  DW_CFA_offset: r19 \(x19\) at cfa-16
+  DW_CFA_advance_loc: 4 to 0+0014
+  DW_CFA_remember_state
+  DW_CFA_advance_loc: 4 to 0+0018
+  DW_CFA_restore: r19 \(x19\)
+  DW_CFA_advance_loc: 8 to 0+0020
+  DW_CFA_def_cfa_register: r31 \(sp\)
+  DW_CFA_restore: r29 \(x29\)
+  DW_CFA_restore: r30 \(x30\)
+  DW_CFA_def_cfa_offset: 0
+  DW_CFA_advance_loc: 4 to 0+0024
+  DW_CFA_restore_state
+  DW_CFA_advance_loc: 4 to 0+0028
+  DW_CFA_restore: r19 \(x19\)
+  DW_CFA_nop
+
+#pass
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cfg-4.l b/gas/testsuite/gas/scfi/aarch64/scfi-cfg-4.l
new file mode 100644 (file)
index 0000000..6ec2438
--- /dev/null
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*7: Warning: SCFI ignores most user-specified CFI directives
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cfg-4.s b/gas/testsuite/gas/scfi/aarch64/scfi-cfg-4.s
new file mode 100644 (file)
index 0000000..499278d
--- /dev/null
@@ -0,0 +1,41 @@
+# Testcase for forward flow of SCFI information.
+# This testcase has two paths landing at the exit basic block,
+# where only one of the exit paths has a save/restore of x19
+# (while the other does not).
+       .type   foo, %function
+foo:
+       .cfi_startproc
+       stp     x29, x30, [sp, -32]!
+       .cfi_def_cfa_offset 32
+       .cfi_offset 29, -32
+       .cfi_offset 30, -24
+       mov     x29, sp
+       .cfi_def_cfa_register 29
+# do some work ...
+       cbz     x0, .L2
+       str     x19, [sp, 16]
+       .cfi_offset 19, -16
+# do some other work ...
+       cbz     w0, .L3
+       ldr     x19, [sp, 16]
+       .cfi_restore 19
+.L2:
+       mov     w0, 1
+.L1:
+       ldp     x29, x30, [sp], 32
+       .cfi_def_cfa_register 31
+       .cfi_restore 30
+       .cfi_restore 29
+       .cfi_def_cfa_offset 0
+       ret
+.L3:
+       .cfi_def_cfa_offset 32
+       .cfi_offset 19, -16
+       .cfi_offset 29, -32
+       .cfi_offset 30, -24
+# do yet some other work before return
+       ldr     x19, [sp, 16]
+       .cfi_restore 19
+       b       .L1
+       .cfi_endproc
+       .size    foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cond-br-1.d b/gas/testsuite/gas/scfi/aarch64/scfi-cond-br-1.d
new file mode 100644 (file)
index 0000000..dc656c7
--- /dev/null
@@ -0,0 +1,20 @@
+#as: --scfi=experimental -W
+#objdump: -Wf
+#name: Synthesize CFI for conditional br 1
+#...
+Contents of the .eh_frame section:
+
+
+0+0000 0+0010 0+0000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 4
+  Data alignment factor: -8
+  Return address column: 30
+  Augmentation data:     1b
+  DW_CFA_def_cfa: r31 \(sp\) ofs 0
+
+0+0014 0+0010 00000018 FDE cie=00000000 pc=0+0000..0+0010
+  DW_CFA_nop
+
+#pass
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cond-br-1.l b/gas/testsuite/gas/scfi/aarch64/scfi-cond-br-1.l
new file mode 100644 (file)
index 0000000..bcf3095
--- /dev/null
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*6: Warning: SCFI ignores most user-specified CFI directives
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-cond-br-1.s b/gas/testsuite/gas/scfi/aarch64/scfi-cond-br-1.s
new file mode 100644 (file)
index 0000000..03c330d
--- /dev/null
@@ -0,0 +1,13 @@
+       .text
+       .align  2
+       .global foo
+       .type   foo, %function
+foo:
+       .cfi_startproc
+       bge     .L10
+       ble     .L10
+       bne     .L10
+.L10:
+       ret
+       .cfi_endproc
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-diag-1.l b/gas/testsuite/gas/scfi/aarch64/scfi-diag-1.l
new file mode 100644 (file)
index 0000000..5a8e369
--- /dev/null
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*5: Warning: SCFI: ignored probable save/restore op with reg offset
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-diag-1.s b/gas/testsuite/gas/scfi/aarch64/scfi-diag-1.s
new file mode 100644 (file)
index 0000000..a6eac51
--- /dev/null
@@ -0,0 +1,6 @@
+       .text
+       .globl  foo
+       .type   foo, @function
+foo:
+       str     x19, [sp, x1]
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-diag-2.l b/gas/testsuite/gas/scfi/aarch64/scfi-diag-2.l
new file mode 100644 (file)
index 0000000..03a5f4f
--- /dev/null
@@ -0,0 +1,3 @@
+.*Assembler messages:
+.*7: Warning: SCFI ignores most user-specified CFI directives
+.*16: Warning: GINSN: found unreachable code in func 'foo'
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-diag-2.s b/gas/testsuite/gas/scfi/aarch64/scfi-diag-2.s
new file mode 100644 (file)
index 0000000..81855aa
--- /dev/null
@@ -0,0 +1,25 @@
+# Testcase that triggers a diagnostic for unreachable code for
+# the block of code after label .L2.  This also serves as a testcase
+# for cfg creation, as the said code block should not have been
+# included in the CFG (and hence the warning).
+       .type   foo, %function
+foo:
+       .cfi_startproc
+       ldr     w1, [x0]
+       cmp     w1, 8
+       stp     x19, x20, [sp, 16]
+       .cfi_offset 19, 16
+       .cfi_offset 20, 24
+       b       .L1
+.L2:
+       mov     w0, w1
+       ret
+.L1:
+       mov     w0, w1
+       ldp     x19, x20, [sp, 16]
+       .cfi_restore 19
+       .cfi_restore 20
+       .cfi_def_cfa_offset 0
+       ret
+       .cfi_endproc
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-diag-3.l b/gas/testsuite/gas/scfi/aarch64/scfi-diag-3.l
new file mode 100644 (file)
index 0000000..85b1279
--- /dev/null
@@ -0,0 +1,3 @@
+.*Assembler messages:
+.*6: Error: SCFI: 0x14000000 op with non-zero addend to sym not supported
+.*6: Error: SCFI: unhandled op 0x14000000 may cause incorrect CFI
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-diag-3.s b/gas/testsuite/gas/scfi/aarch64/scfi-diag-3.s
new file mode 100644 (file)
index 0000000..89a4d9a
--- /dev/null
@@ -0,0 +1,8 @@
+# Testcase with a branch instruction with symbol and an addend
+# Such insns make CFG creation difficult and hence make the
+# function ineligible for SCFI.
+       .type   foo, %function
+foo:
+       b       symbol+1
+       ret
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-ldrp-1.d b/gas/testsuite/gas/scfi/aarch64/scfi-ldrp-1.d
new file mode 100644 (file)
index 0000000..ce8fab5
--- /dev/null
@@ -0,0 +1,59 @@
+#as: --scfi=experimental -W
+#objdump: -Wf
+#name: Synthesize CFI for ldp ldr instructions
+#...
+Contents of the .eh_frame section:
+
+00000000 0+0010 00000000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 4
+  Data alignment factor: -8
+  Return address column: 30
+  Augmentation data:     1b
+  DW_CFA_def_cfa: r31 \(sp\) ofs 0
+
+00000014 0+0048 00000018 FDE cie=00000000 pc=0+0000..0+0040
+  DW_CFA_advance_loc: 4 to 0+0004
+  DW_CFA_def_cfa_offset: 128
+  DW_CFA_offset: r29 \(x29\) at cfa-128
+  DW_CFA_offset: r30 \(x30\) at cfa-120
+  DW_CFA_advance_loc: 4 to 0+0008
+  DW_CFA_def_cfa_register: r29 \(x29\)
+  DW_CFA_advance_loc: 4 to 0+000c
+  DW_CFA_offset: r19 \(x19\) at cfa-112
+  DW_CFA_offset: r20 \(x20\) at cfa-104
+  DW_CFA_advance_loc: 4 to 0+0010
+  DW_CFA_offset: r21 \(x21\) at cfa-96
+  DW_CFA_offset: r22 \(x22\) at cfa-88
+  DW_CFA_advance_loc: 4 to 0+0014
+  DW_CFA_offset: r23 \(x23\) at cfa-80
+  DW_CFA_offset: r24 \(x24\) at cfa-72
+  DW_CFA_advance_loc: 4 to 0+0018
+  DW_CFA_offset: r25 \(x25\) at cfa-64
+  DW_CFA_offset: r26 \(x26\) at cfa-56
+  DW_CFA_advance_loc: 4 to 0+001c
+  DW_CFA_offset: r27 \(x27\) at cfa-48
+  DW_CFA_advance_loc: 8 to 0+0024
+  DW_CFA_def_cfa_register: r31 \(sp\)
+  DW_CFA_advance_loc: 4 to 0+0028
+  DW_CFA_restore: r19 \(x19\)
+  DW_CFA_restore: r20 \(x20\)
+  DW_CFA_advance_loc: 4 to 0+002c
+  DW_CFA_restore: r21 \(x21\)
+  DW_CFA_restore: r22 \(x22\)
+  DW_CFA_advance_loc: 4 to 0+0030
+  DW_CFA_restore: r23 \(x23\)
+  DW_CFA_restore: r24 \(x24\)
+  DW_CFA_advance_loc: 4 to 0+0034
+  DW_CFA_restore: r25 \(x25\)
+  DW_CFA_restore: r26 \(x26\)
+  DW_CFA_advance_loc: 4 to 0+0038
+  DW_CFA_restore: r27 \(x27\)
+  DW_CFA_advance_loc: 4 to 0+003c
+  DW_CFA_restore: r29 \(x29\)
+  DW_CFA_restore: r30 \(x30\)
+  DW_CFA_def_cfa_offset: 0
+  DW_CFA_nop
+
+#pass
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-ldrp-1.l b/gas/testsuite/gas/scfi/aarch64/scfi-ldrp-1.l
new file mode 100644 (file)
index 0000000..5ff6048
--- /dev/null
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*8: Warning: SCFI ignores most user-specified CFI directives
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-ldrp-1.s b/gas/testsuite/gas/scfi/aarch64/scfi-ldrp-1.s
new file mode 100644 (file)
index 0000000..4226d71
--- /dev/null
@@ -0,0 +1,52 @@
+# Testcase for various ldp / ldr instructions.
+# This test also serves for checking callee-saved regs.
+       .text
+       .align  2
+       .global foo
+       .type   foo, %function
+foo:
+       .cfi_startproc
+       stp     x29, x30, [sp, -128]!
+       .cfi_def_cfa_offset 128
+       .cfi_offset 29, -128
+       .cfi_offset 30, -120
+       mov     x29, sp
+       .cfi_def_cfa_register 29
+       stp     x19, x20, [sp, 16]
+       .cfi_offset 19, -112
+       .cfi_offset 20, -104
+       stp     x21, x22, [sp, 32]
+       .cfi_offset 21, -96
+       .cfi_offset 22, -88
+       stp     x23, x24, [sp, 48]
+       .cfi_offset 23, -80
+       .cfi_offset 24, -72
+       stp     x25, x26, [sp, 64]
+       .cfi_offset 25, -64
+       .cfi_offset 26, -56
+       str     x27, [sp, 80]
+       .cfi_offset 27, -48
+       mov     w0, 0
+       mov     sp, x29
+       .cfi_def_cfa_register 31
+       ldp     x19, x20, [sp, 16]
+       .cfi_restore 19
+       .cfi_restore 20
+       ldp     x21, x22, [sp, 32]
+       .cfi_restore 21
+       .cfi_restore 22
+       ldp     x23, x24, [sp, 48]
+       .cfi_restore 23
+       .cfi_restore 24
+       ldp     x25, x26, [sp, 64]
+       .cfi_restore 25
+       .cfi_restore 26
+       ldr     x27, [sp, 80]
+       .cfi_restore 27
+       ldp     x29, x30, [sp], 128
+       .cfi_restore 29
+       .cfi_restore 30
+       .cfi_def_cfa_offset 0
+       ret
+       .cfi_endproc
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-ldrp-2.d b/gas/testsuite/gas/scfi/aarch64/scfi-ldrp-2.d
new file mode 100644 (file)
index 0000000..2a0fdb6
--- /dev/null
@@ -0,0 +1,33 @@
+#as: --scfi=experimental -W
+#objdump: -Wf
+#name: Synthesize CFI for ldr insns 2
+#...
+Contents of the .eh_frame section:
+
+00000000 0+0010 00000000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 4
+  Data alignment factor: -8
+  Return address column: 30
+  Augmentation data:     1b
+  DW_CFA_def_cfa: r31 \(sp\) ofs 0
+
+00000014 0+[0-9a-f]+ 00000018 FDE cie=00000000 pc=0+0000..0+0018
+  DW_CFA_advance_loc: 4 to 0+0004
+  DW_CFA_def_cfa_offset: 128
+  DW_CFA_offset: r29 \(x29\) at cfa-128
+  DW_CFA_offset: r30 \(x30\) at cfa-120
+  DW_CFA_advance_loc: 4 to 0+0008
+  DW_CFA_def_cfa_register: r29 \(x29\)
+  DW_CFA_advance_loc: 4 to 0+000c
+  DW_CFA_def_cfa_register: r31 \(sp\)
+  DW_CFA_advance_loc: 4 to 0+0010
+  DW_CFA_restore: r29 \(x29\)
+  DW_CFA_def_cfa_offset: 120
+  DW_CFA_advance_loc: 4 to 0+0014
+  DW_CFA_restore: r30 \(x30\)
+  DW_CFA_def_cfa_offset: 0
+  DW_CFA_nop
+
+#pass
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-ldrp-2.l b/gas/testsuite/gas/scfi/aarch64/scfi-ldrp-2.l
new file mode 100644 (file)
index 0000000..6ec2438
--- /dev/null
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*7: Warning: SCFI ignores most user-specified CFI directives
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-ldrp-2.s b/gas/testsuite/gas/scfi/aarch64/scfi-ldrp-2.s
new file mode 100644 (file)
index 0000000..ac4ad68
--- /dev/null
@@ -0,0 +1,26 @@
+# Testcase for various ldp / ldr instructions
+       .text
+       .align  2
+       .global foo
+       .type   foo, %function
+foo:
+       .cfi_startproc
+       stp     x29, x30, [sp, -128]!
+       .cfi_def_cfa_offset 128
+       .cfi_offset 29, -128
+       .cfi_offset 30, -120
+       mov     x29, sp
+       .cfi_def_cfa_register 29
+       mov     sp, x29
+       .cfi_def_cfa_register 31
+# Post-indexed ldr
+       ldr     x29, [sp], 8
+       .cfi_restore 29
+       .cfi_def_cfa_offset 120
+# Post-indexed ldr
+       ldr     x30, [sp], 120
+       .cfi_restore 30
+       .cfi_def_cfa_offset 0
+       ret
+       .cfi_endproc
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-ldstnap-1.d b/gas/testsuite/gas/scfi/aarch64/scfi-ldstnap-1.d
new file mode 100644 (file)
index 0000000..f2eeb86
--- /dev/null
@@ -0,0 +1,39 @@
+#as: --scfi=experimental -W
+#objdump: -Wf
+#name: Synthesize CFI for ldst no-allocate pair
+#...
+Contents of the .eh_frame section:
+
+00000000 0+0010 00000000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 4
+  Data alignment factor: -8
+  Return address column: 30
+  Augmentation data:     1b
+  DW_CFA_def_cfa: r31 \(sp\) ofs 0
+
+00000014 0+[0-9a-f]+ 00000018 FDE cie=00000000 pc=0+0000..0+0020
+  DW_CFA_advance_loc: 4 to 0+0004
+  DW_CFA_def_cfa_offset: 128
+  DW_CFA_offset: r29 \(x29\) at cfa-128
+  DW_CFA_offset: r30 \(x30\) at cfa-120
+  DW_CFA_advance_loc: 4 to 0+0008
+  DW_CFA_def_cfa_register: r29 \(x29\)
+  DW_CFA_advance_loc: 4 to 0+000c
+  DW_CFA_def_cfa_register: r31 \(sp\)
+  DW_CFA_advance_loc: 4 to 0+0010
+  DW_CFA_offset: r19 \(x19\) at cfa-112
+  DW_CFA_offset: r20 \(x20\) at cfa-104
+  DW_CFA_advance_loc: 4 to 0+0014
+  DW_CFA_restore: r19 \(x19\)
+  DW_CFA_restore: r20 \(x20\)
+  DW_CFA_advance_loc: 4 to 0+0018
+  DW_CFA_restore: r29 \(x29\)
+  DW_CFA_def_cfa_offset: 120
+  DW_CFA_advance_loc: 4 to 0+001c
+  DW_CFA_restore: r30 \(x30\)
+  DW_CFA_def_cfa_offset: 0
+  DW_CFA_nop
+
+#pass
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-ldstnap-1.l b/gas/testsuite/gas/scfi/aarch64/scfi-ldstnap-1.l
new file mode 100644 (file)
index 0000000..6ec2438
--- /dev/null
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*7: Warning: SCFI ignores most user-specified CFI directives
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-ldstnap-1.s b/gas/testsuite/gas/scfi/aarch64/scfi-ldstnap-1.s
new file mode 100644 (file)
index 0000000..ed1754b
--- /dev/null
@@ -0,0 +1,30 @@
+# Testcase for various ldnp / stnp instructions
+       .text
+       .align  2
+       .global foo
+       .type   foo, %function
+foo:
+       .cfi_startproc
+       stp     x29, x30, [sp, -128]!
+       .cfi_def_cfa_offset 128
+       .cfi_offset 29, -128
+       .cfi_offset 30, -120
+       mov     x29, sp
+       .cfi_def_cfa_register 29
+       mov     sp, x29
+       .cfi_def_cfa_register 31
+       stp     x19, x20, [sp, 16]
+       .cfi_offset 19, -112
+       .cfi_offset 20, -104
+       ldp     x19, x20, [sp, 16]
+       .cfi_restore 19
+       .cfi_restore 20
+       ldr     x29, [sp], 8
+       .cfi_restore 29
+       .cfi_def_cfa_offset 120
+       ldr     x30, [sp], 120
+       .cfi_restore 30
+       .cfi_def_cfa_offset 0
+       ret
+       .cfi_endproc
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-strp-1.d b/gas/testsuite/gas/scfi/aarch64/scfi-strp-1.d
new file mode 100644 (file)
index 0000000..cebd254
--- /dev/null
@@ -0,0 +1,39 @@
+#as: --scfi=experimental -W
+#objdump: -Wf
+#name: Synthesize CFI for str stp insns 1
+#...
+Contents of the .eh_frame section:
+
+00000000 0+0010 00000000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 4
+  Data alignment factor: -8
+  Return address column: 30
+  Augmentation data:     1b
+  DW_CFA_def_cfa: r31 \(sp\) ofs 0
+
+00000014 0+0030 00000018 FDE cie=00000000 pc=0+0000..0+002c
+  DW_CFA_advance_loc: 4 to 0+0004
+  DW_CFA_def_cfa_offset: 128
+  DW_CFA_offset: r29 \(x29\) at cfa-128
+  DW_CFA_offset: r30 \(x30\) at cfa-120
+  DW_CFA_advance_loc: 4 to 0+0008
+  DW_CFA_def_cfa_register: r29 \(x29\)
+  DW_CFA_advance_loc: 4 to 0+000c
+  DW_CFA_offset: r19 \(x19\) at cfa-112
+  DW_CFA_offset: r20 \(x20\) at cfa-104
+  DW_CFA_advance_loc: 4 to 0+0010
+  DW_CFA_offset: r21 \(x21\) at cfa-96
+  DW_CFA_offset: r22 \(x22\) at cfa-88
+  DW_CFA_advance_loc: 4 to 0+0014
+  DW_CFA_offset: r23 \(x23\) at cfa-80
+  DW_CFA_offset: r24 \(x24\) at cfa-72
+  DW_CFA_advance_loc: 4 to 0+0018
+  DW_CFA_offset: r25 \(x25\) at cfa-64
+  DW_CFA_offset: r26 \(x26\) at cfa-56
+  DW_CFA_advance_loc: 4 to 0+001c
+  DW_CFA_offset: r27 \(x27\) at cfa-48
+  DW_CFA_nop
+
+#pass
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-strp-1.l b/gas/testsuite/gas/scfi/aarch64/scfi-strp-1.l
new file mode 100644 (file)
index 0000000..bcf3095
--- /dev/null
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*6: Warning: SCFI ignores most user-specified CFI directives
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-strp-1.s b/gas/testsuite/gas/scfi/aarch64/scfi-strp-1.s
new file mode 100644 (file)
index 0000000..932ca4a
--- /dev/null
@@ -0,0 +1,37 @@
+## Testcase with a variety of str/stp instructions
+       .text
+       .globl  foo
+       .type   foo, @function
+foo:
+       .cfi_startproc
+# Pre-indexed addressing is like offset addressing, except that
+# the base pointer is updated as a result of the instruction.
+       stp     x29, x30, [sp, -128]!
+       .cfi_def_cfa_offset 128
+       .cfi_offset 29, -128
+       .cfi_offset 30, -120
+       mov     x29, sp
+       .cfi_def_cfa_register 29
+# Offset addressing mode is when ann offset can be applied optionally to the
+# base address.
+       stp     x19, x20, [sp, 16]
+       .cfi_offset 19, -112
+       .cfi_offset 20, -104
+       stp     x21, x22, [sp, 32]
+       .cfi_offset 21, -96
+       .cfi_offset 22, -88
+       stp     x23, x24, [sp, 48]
+       .cfi_offset 23, -80
+       .cfi_offset 24, -72
+       stp     x25, x26, [sp, 64]
+       .cfi_offset 25, -64
+       .cfi_offset 26, -56
+       str     x27, [sp, 80]
+       .cfi_offset 27, -48
+# Stores non callee-saved register on stack.
+       str     w0, [x29, 124]
+       str     wzr, [x29, 120]
+       str     w0, [x29, 120]
+       ret
+       .cfi_endproc
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-strp-2.d b/gas/testsuite/gas/scfi/aarch64/scfi-strp-2.d
new file mode 100644 (file)
index 0000000..d69ba0d
--- /dev/null
@@ -0,0 +1,35 @@
+#as: --scfi=experimental -W
+#objdump: -Wf
+#name: Synthesize CFI for str insns 2
+#...
+Contents of the .eh_frame section:
+
+00000000 0+0010 00000000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 4
+  Data alignment factor: -8
+  Return address column: 30
+  Augmentation data:     1b
+  DW_CFA_def_cfa: r31 \(sp\) ofs 0
+
+00000014 0+0028 00000018 FDE cie=00000000 pc=0+0000..0+001c
+  DW_CFA_advance_loc: 4 to 0+0004
+  DW_CFA_def_cfa_offset: 128
+  DW_CFA_offset: r29 \(x29\) at cfa-128
+  DW_CFA_offset: r30 \(x30\) at cfa-120
+  DW_CFA_advance_loc: 4 to 0+0008
+  DW_CFA_def_cfa_register: r29 \(x29\)
+  DW_CFA_advance_loc: 4 to 0+000c
+  DW_CFA_offset: r27 \(x27\) at cfa-128
+  DW_CFA_advance_loc: 4 to 0+0010
+  DW_CFA_def_cfa_register: r31 \(sp\)
+  DW_CFA_advance_loc: 4 to 0+0014
+  DW_CFA_restore: r29 \(x29\)
+  DW_CFA_def_cfa_offset: 120
+  DW_CFA_advance_loc: 4 to 0+0018
+  DW_CFA_restore: r30 \(x30\)
+  DW_CFA_def_cfa_offset: 0
+  DW_CFA_nop
+
+#pass
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-strp-2.l b/gas/testsuite/gas/scfi/aarch64/scfi-strp-2.l
new file mode 100644 (file)
index 0000000..6ec2438
--- /dev/null
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*7: Warning: SCFI ignores most user-specified CFI directives
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-strp-2.s b/gas/testsuite/gas/scfi/aarch64/scfi-strp-2.s
new file mode 100644 (file)
index 0000000..1792697
--- /dev/null
@@ -0,0 +1,30 @@
+# Testcase for a variety of stp/str including a post-indexed store
+       .text
+       .align  2
+       .global foo
+       .type   foo, %function
+foo:
+       .cfi_startproc
+       stp     x29, x30, [sp, -128]!
+       .cfi_def_cfa_offset 128
+       .cfi_offset 29, -128
+       .cfi_offset 30, -120
+       mov     x29, sp
+       .cfi_def_cfa_register 29
+# post-indexed store, a stack corrupting one which over-writes
+# x29!  Only for testing purposes for now
+# This does not generate a .cfi_def_cfa_offset 208 because
+# CFA is REG_FP based
+       str     x27, [sp], 80
+       .cfi_offset 27, -128
+       mov     sp, x29
+       .cfi_def_cfa_register 31
+       ldr     x29, [sp], 8
+       .cfi_restore 29
+       .cfi_def_cfa_offset 120
+       ldr     x30, [sp], 120
+       .cfi_restore 30
+       .cfi_def_cfa_offset 0
+       ret
+       .cfi_endproc
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-unsupported-1.l b/gas/testsuite/gas/scfi/aarch64/scfi-unsupported-1.l
new file mode 100644 (file)
index 0000000..de3ed86
--- /dev/null
@@ -0,0 +1,4 @@
+.*Assembler messages:
+.*7: Warning: SCFI ignores most user-specified CFI directives
+.*9: Error: SCFI: unsupported stack manipulation pattern
+.*31: Error: SCFI: forward pass failed for func 'foo'
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-unsupported-1.s b/gas/testsuite/gas/scfi/aarch64/scfi-unsupported-1.s
new file mode 100644 (file)
index 0000000..c143185
--- /dev/null
@@ -0,0 +1,31 @@
+# Testcase where immediate used for stack allocation is a wide
+# one.  Since SCFI does not currently have any data-flow
+# capabilities, this is currently not supported.
+       .global foo
+       .type   foo, %function
+foo:
+       .cfi_startproc
+       mov     x16, 4384
+       sub     sp, sp, x16
+       .cfi_def_cfa_offset 4384
+       stp     x29, x30, [sp]
+       .cfi_offset 29, -4384
+       .cfi_offset 30, -4376
+       mov     x29, sp
+       str     x0, [sp, 24]
+       str     x1, [sp, 16]
+       add     x0, sp, 4096
+       add     x0, x0, 112
+       bl      bar
+.L1:
+       str     xzr, [sp, 4376]
+.L2:
+       ldp     x29, x30, [sp]
+       mov     x16, 4384
+       add     sp, sp, x16
+       .cfi_restore 29
+       .cfi_restore 30
+       .cfi_def_cfa_offset 0
+       ret
+       .cfi_endproc
+       .size   foo, .-foo
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-unsupported-2.l b/gas/testsuite/gas/scfi/aarch64/scfi-unsupported-2.l
new file mode 100644 (file)
index 0000000..f1b9604
--- /dev/null
@@ -0,0 +1,2 @@
+.*Assembler messages:
+.*7: Error: SCFI: unhandled op 0xe5e0e000 may cause incorrect CFI
diff --git a/gas/testsuite/gas/scfi/aarch64/scfi-unsupported-2.s b/gas/testsuite/gas/scfi/aarch64/scfi-unsupported-2.s
new file mode 100644 (file)
index 0000000..a6a4dae
--- /dev/null
@@ -0,0 +1,8 @@
+# Testcase with an SVE instruction with Z register usage
+# of a callee-saved register.  Currently these are not handled
+# and the SCFI machinery must error out.
+       .arch   armv8-a+sve
+       .type   foo, %function
+foo:
+       st1d    z8.d, p2, [sp, #1, mul vl]
+       .size   foo, .-foo