]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
AArch64: Fix PR103085
authorWilco Dijkstra <wdijkstr@arm.com>
Fri, 5 Nov 2021 15:05:15 +0000 (15:05 +0000)
committerWilco Dijkstra <wdijkstr@arm.com>
Fri, 5 Nov 2021 15:36:32 +0000 (15:36 +0000)
The stack protector implementation hides symbols in a const unspec, which means
movdi/movsi patterns must always support const on symbol operands and
explicitly strip away the unspec. Do this for the recently added GOT
alternatives. Add a test to ensure stack-protector tests GOT accesses as well.

2021-11-05  Wilco Dijkstra  <wdijkstr@arm.com>

PR target/103085
* config/aarch64/aarch64.c (aarch64_mov_operand_p): Strip the salt
first.
* config/aarch64/constraints.md: Support const in Usw.

gcc/testsuite/
PR target/103085
* gcc.target/aarch64/pr103085.c: New test

gcc/config/aarch64/aarch64.c
gcc/config/aarch64/constraints.md
gcc/testsuite/gcc.target/aarch64/pr103085.c [new file with mode: 0644]

index 69f08052ce808c140ed2933ab6b2e2617ca6f669..fdf05505846721b02059df494d6395ae9423a8ef 100644 (file)
@@ -20379,12 +20379,14 @@ aarch64_mov_operand_p (rtx x, machine_mode mode)
       return aarch64_simd_valid_immediate (x, NULL);
     }
 
+  /* Remove UNSPEC_SALT_ADDR before checking symbol reference.  */
+  x = strip_salt (x);
+
   /* GOT accesses are valid moves.  */
   if (SYMBOL_REF_P (x)
       && aarch64_classify_symbolic_expression (x) == SYMBOL_SMALL_GOT_4G)
     return true;
 
-  x = strip_salt (x);
   if (SYMBOL_REF_P (x) && mode == DImode && CONSTANT_ADDRESS_P (x))
     return true;
 
index 87c0e5fe2a9cefdfe6fc4f6e51ab8947a00775ef..b197ec26060ac086ed7701448a1f504f9ebb91b7 100644 (file)
        (match_test "aarch64_symbolic_address_p (op)")
        (match_test "aarch64_mov_operand_p (op, GET_MODE (op))")))
 
+;; const is needed here to support UNSPEC_SALT_ADDR.
 (define_constraint "Usw"
   "@internal
    A constraint that matches a small GOT access."
-  (and (match_code "symbol_ref")
+  (and (match_code "const,symbol_ref")
        (match_test "aarch64_classify_symbolic_expression (op)
                     == SYMBOL_SMALL_GOT_4G")))
 
diff --git a/gcc/testsuite/gcc.target/aarch64/pr103085.c b/gcc/testsuite/gcc.target/aarch64/pr103085.c
new file mode 100644 (file)
index 0000000..dbc9c15
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fstack-protector-strong -fPIC" } */
+
+void g(int*);
+void
+f (int x)
+{
+  int arr[10];
+  g (arr);
+}
+