Message ID | VE1PR08MB55999AB6A9F7E819F3F3C158838E9@VE1PR08MB5599.eurprd08.prod.outlook.com |
---|---|
State | New |
Headers | show |
Series | AArch64: Fix PR103085 | expand |
Wilco Dijkstra <Wilco.Dijkstra@arm.com> writes: > 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. > > Passes bootstrap and regress. OK for commit? > > 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.target/aarch64/pr103085.c: New test OK, thanks. Richard > --- > > diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c > index 430ea036a7be4da842fd08998923a3462457dbfd..39de231d8ac6d10362cdd2b48eb9bd9de60c6703 100644 > --- a/gcc/config/aarch64/aarch64.c > +++ b/gcc/config/aarch64/aarch64.c > @@ -20155,12 +20155,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; > > diff --git a/gcc/config/aarch64/constraints.md b/gcc/config/aarch64/constraints.md > index 70ca66070217d06f974b18f7690326bc329fed89..da5438e7ce254272eb10e9ac60d5367c46635e84 100644 > --- a/gcc/config/aarch64/constraints.md > +++ b/gcc/config/aarch64/constraints.md > @@ -152,10 +152,11 @@ (define_constraint "Usa" > (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 > index 0000000000000000000000000000000000000000..dbc9c15b71f224b3c7dec0cca5655a31adc207f6 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/aarch64/pr103085.c > @@ -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); > +} > +
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 430ea036a7be4da842fd08998923a3462457dbfd..39de231d8ac6d10362cdd2b48eb9bd9de60c6703 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -20155,12 +20155,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; diff --git a/gcc/config/aarch64/constraints.md b/gcc/config/aarch64/constraints.md index 70ca66070217d06f974b18f7690326bc329fed89..da5438e7ce254272eb10e9ac60d5367c46635e84 100644 --- a/gcc/config/aarch64/constraints.md +++ b/gcc/config/aarch64/constraints.md @@ -152,10 +152,11 @@ (define_constraint "Usa" (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 index 0000000000000000000000000000000000000000..dbc9c15b71f224b3c7dec0cca5655a31adc207f6 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr103085.c @@ -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); +} +