]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
iesFrom: Alexandre Oliva <oliva@adacore.com>
authorAlexandre Oliva <oliva@adacore.com>
Thu, 22 May 2025 18:06:24 +0000 (15:06 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Thu, 22 May 2025 18:06:24 +0000 (15:06 -0300)
[aarch64] [vxworks] mark x18 as fixed, adjust tests

VxWorks uses x18 as the TCB, so STATIC_CHAIN_REGNUM has long been set
(in gcc/config/aarch64/aarch64-vxworks.h) to use x9 instead.

This patch marks x18 as fixed if the newly-introduced
TARGET_OS_USES_R18 is defined, so that it is not chosen by the
register allocator, rejects -fsanitize-shadow-call-stack due to the
register conflict, and adjusts tests that depend on x18 or on the
static chain register.

for  gcc/ChangeLog

* config/aarch64/aarch64-vxworks.h (TARGET_OS_USES_R18): Define.
Update comments.
* config/aarch64/aarch64.cc (aarch64_conditional_register_usage):
Mark x18 as fixed on VxWorks.
(aarch64_override_options_internal): Issue sorry message on
-fsanitize=shadow-call-stack if TARGET_OS_USES_R18.

for  gcc/testsuite/ChangeLog

* gcc.dg/cwsc1.c (CHAIN, aarch64): x9 instead x18 for __vxworks.
* gcc.target/aarch64/reg-alloc-4.c: Drop x18-assigned asm
operand on vxworks.
* gcc.target/aarch64/shadow_call_stack_1.c: Don't expect
-ffixed-x18 error on vxworks, but rather the sorry message.
* gcc.target/aarch64/shadow_call_stack_2.c: Skip on vxworks.
* gcc.target/aarch64/shadow_call_stack_3.c: Likewise.
* gcc.target/aarch64/shadow_call_stack_4.c: Likewise.
* gcc.target/aarch64/shadow_call_stack_5.c: Likewise.
* gcc.target/aarch64/shadow_call_stack_6.c: Likewise.
* gcc.target/aarch64/shadow_call_stack_7.c: Likewise.
* gcc.target/aarch64/shadow_call_stack_8.c: Likewise.
* gcc.target/aarch64/stack-check-prologue-19.c: Likewise.
* gcc.target/aarch64/stack-check-prologue-20.c: Likewise.

14 files changed:
gcc/config/aarch64/aarch64-vxworks.h
gcc/config/aarch64/aarch64.cc
gcc/testsuite/gcc.dg/cwsc1.c
gcc/testsuite/gcc.target/aarch64/reg-alloc-4.c
gcc/testsuite/gcc.target/aarch64/shadow_call_stack_1.c
gcc/testsuite/gcc.target/aarch64/shadow_call_stack_2.c
gcc/testsuite/gcc.target/aarch64/shadow_call_stack_3.c
gcc/testsuite/gcc.target/aarch64/shadow_call_stack_4.c
gcc/testsuite/gcc.target/aarch64/shadow_call_stack_5.c
gcc/testsuite/gcc.target/aarch64/shadow_call_stack_6.c
gcc/testsuite/gcc.target/aarch64/shadow_call_stack_7.c
gcc/testsuite/gcc.target/aarch64/shadow_call_stack_8.c
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-19.c
gcc/testsuite/gcc.target/aarch64/stack-check-prologue-20.c

index 41adada9b1de3712f679e844acb3d2be091d72eb..7b4da934b60836e78eebd4ae02df942a3c0560db 100644 (file)
@@ -66,9 +66,8 @@ along with GCC; see the file COPYING3.  If not see
 #define VXWORKS_PERSONALITY "llvm"
 
 /* VxWorks uses R18 as a TCB pointer.  We must pick something else as
-   the static chain and R18 needs to be claimed "fixed".  Until we
-   arrange to override the common parts of the port family to
-   acknowledge the latter, configure --with-specs="-ffixed-r18".  */
+   the static chain and R18 needs to be claimed "fixed" (TARGET_OS_USES_R18
+   does that in aarch64_conditional_register_usage).  */
 #undef  STATIC_CHAIN_REGNUM
 #define STATIC_CHAIN_REGNUM 9
-
+#define TARGET_OS_USES_R18
index ecb0bac2e5501f638f8e4f933af4d430ab96abe0..1fa3ec522c3a1da0579ce0bcbee3c27123f67b18 100644 (file)
@@ -18826,9 +18826,16 @@ aarch64_override_options_internal (struct gcc_options *opts)
       aarch64_stack_protector_guard_offset = offs;
     }
 
-  if ((flag_sanitize & SANITIZE_SHADOW_CALL_STACK)
-      && !fixed_regs[R18_REGNUM])
-    error ("%<-fsanitize=shadow-call-stack%> requires %<-ffixed-x18%>");
+  if ((flag_sanitize & SANITIZE_SHADOW_CALL_STACK))
+    {
+      if (!fixed_regs[R18_REGNUM])
+       error ("%<-fsanitize=shadow-call-stack%> requires %<-ffixed-x18%>");
+#ifdef TARGET_OS_USES_R18
+      else
+       sorry ("%<-fsanitize=shadow-call-stack%> conflicts with the use of"
+              " register x18 by the target operating system");
+#endif
+    }
 
   aarch64_feature_flags isa_flags = aarch64_get_isa_flags (opts);
   if ((isa_flags & (AARCH64_FL_SM_ON | AARCH64_FL_ZA_ON))
@@ -22046,6 +22053,14 @@ aarch64_conditional_register_usage (void)
       fixed_regs[SPECULATION_SCRATCH_REGNUM] = 1;
       call_used_regs[SPECULATION_SCRATCH_REGNUM] = 1;
     }
+
+#ifdef TARGET_OS_USES_R18
+  /* R18 is the STATIC_CHAIN_REGNUM on most aarch64 ports, but VxWorks
+     uses it as the TCB, so aarch64-vxworks.h overrides
+     STATIC_CHAIN_REGNUM, and here we mark R18 as fixed.  */
+  fixed_regs[R18_REGNUM] = 1;
+  call_used_regs[R18_REGNUM] = 1;
+#endif
 }
 
 /* Implement TARGET_MEMBER_TYPE_FORCES_BLK.  */
index e793e26116af4eea9e8af04b23f3be85a24d1005..cccf4139c35b5f43861bb7286a15ed95cfe386d8 100644 (file)
@@ -6,7 +6,11 @@
 #elif defined(__i386__)
 # define CHAIN  "%ecx"
 #elif defined(__aarch64__)
-# define CHAIN  "x18"
+# if defined __vxworks
+#  define CHAIN "x9"
+# else
+#  define CHAIN  "x18"
+# endif
 #elif defined(__alpha__)
 # define CHAIN  "$1"
 #elif defined(__arm__)
index ceb6f50de2dc38c4e57f0d9d15526cd721591e74..0576dc27eb0727302049dd519488435b1859caa1 100644 (file)
@@ -61,7 +61,9 @@ foo (volatile struct L *head, int inc)
                        "r" (inner->next),      /* x15 */
                        "r" (inner->next),      /* x16 */
                        "r" (inner->next),      /* x17 */
+#ifndef __vxworks /* x18 is a fixed register on VxWorks, used for the TCB.  */
                        "r" (inner->next),      /* x18 */
+#endif
                        "r" (inner->next) :     /* x30 */
                        "x19", "x20", "x21", "x22", "x23",
                        "x24", "x25", "x26", "x27", "x28");
index ab68d6e84825260ea07a5c96ada31bddb338be4f..fb19bd4ecb4f6e10886a57950c604859b0245e1b 100644 (file)
@@ -3,4 +3,6 @@
 
 int i;
 
-/* { dg-error "'-fsanitize=shadow-call-stack' requires '-ffixed-x18'" "" {target "aarch64*-*-*" } 0 } */
+/* aarch64-*-vxworks has x18 as a fixed register.  */
+/* { dg-error "'-fsanitize=shadow-call-stack' requires '-ffixed-x18'" "" { target { aarch64*-*-* && { ! aarch64-*-vxworks* } } } 0 } */
+/* { dg-message "sorry, unimplemented: '-fsanitize=shadow-call-stack' conflicts with the use of register x18" "" { target { aarch64-*-vxworks* } } 0 } */
index b5139a245597b645c6c54b966aba82c1e4e6230f..2c381cd7962988cd21b2e01b8ccecca248d04369 100644 (file)
@@ -1,5 +1,6 @@
 /* { dg-do compile } */
 /* { dg-options "-fsanitize=shadow-call-stack -ffixed-x18 -fexceptions" } */
+/* { dg-skip-if "conflicts with x18" { aarch64-*-vxworks* } } */
 
 int i;
 
index b88e490f3ae71dcd6e262c70d71bbf7837aa7630..95d41e722a002d802de7f6e04e4025535f09d37d 100644 (file)
@@ -3,6 +3,7 @@
 /* scs_pop: ldr x30, [x18, #-8]! */
 /* { dg-do compile } */
 /* { dg-options "-O2 -fsanitize=shadow-call-stack -ffixed-x18 -fno-exceptions" } */
+/* { dg-skip-if "conflicts with x18" { aarch64-*-vxworks* } } */
 
 int foo (int);
 
index f63169340e12585f09250164ba0e7dc932b3aa0b..1e84ab630f98a3fd038d4aa615106aa1f8e4fa73 100644 (file)
@@ -3,6 +3,7 @@
 /* scs_pop: ldr x30, [x18, #-8]! */
 /* { dg-do compile } */
 /* { dg-options "-O2 -fno-omit-frame-pointer -fsanitize=shadow-call-stack -ffixed-x18 -fno-exceptions" } */
+/* { dg-skip-if "conflicts with x18" { aarch64-*-vxworks* } } */
 
 int foo (int);
 
index d7f82984ff533208c0b9ced15bee4c55eac53632..e76de4796f9335717af5f887941538c792b23d6c 100644 (file)
@@ -8,6 +8,7 @@
 
 /* { dg-do compile } */
 /* { dg-options "-O2 -fno-omit-frame-pointer -fsanitize=shadow-call-stack -fno-exceptions -ffixed-x18 --save-temps -fno-stack-protector" } */
+/* { dg-skip-if "conflicts with x18" { aarch64-*-vxworks* } } */
 
 #include "test_frame_common.h"
 
index 8d088aecc202e827e8a6d83fabe2b1c6baf7d5d7..35093757f7c6079dcf8ab5939008ce66f7c99546 100644 (file)
@@ -8,6 +8,7 @@
 
 /* { dg-do compile } */
 /* { dg-options "-O2 -fomit-frame-pointer -fsanitize=shadow-call-stack -fno-exceptions -ffixed-x18 --save-temps -fno-stack-protector" } */
+/* { dg-skip-if "conflicts with x18" { aarch64-*-vxworks* } } */
 
 #include "test_frame_common.h"
 
index a2f376e0091c20610012c3415824e2087bf630b7..9ddd71a203a7b941aa65355b743b4cee73f2fa95 100644 (file)
@@ -8,6 +8,7 @@
 
 /* { dg-do compile } */
 /* { dg-options "-O2 -fomit-frame-pointer -fsanitize=shadow-call-stack -fno-exceptions -ffixed-x18 --save-temps -fno-stack-protector" } */
+/* { dg-skip-if "conflicts with x18" { aarch64-*-vxworks* } } */
 
 #include "test_frame_common.h"
 
index 5162cbb391757aa08d64558ac264100528f2cdb9..be8d8166ddab845b481da7c52d82bbbc6be0b1f8 100644 (file)
@@ -10,6 +10,7 @@
 
 /* { dg-do compile } */
 /* { dg-options "-O0 -fomit-frame-pointer -fsanitize=shadow-call-stack -fno-exceptions -ffixed-x18 --save-temps -fno-stack-protector" } */
+/* { dg-skip-if "conflicts with x18" { aarch64-*-vxworks* } } */
 
 int func1 (void)
 {
index 38eab4d36ab2d98ae87748c4ddcdf18409b3e9d7..49dc51142e6e8e743a7d85e85482e56a1a23c97b 100644 (file)
@@ -1,4 +1,5 @@
 /* { dg-options "-O2 -fstack-clash-protection -fomit-frame-pointer --param stack-clash-protection-guard-size=12 -fsanitize=shadow-call-stack -ffixed-x18 -fno-stack-protector" } */
+/* { dg-skip-if "conflicts with x18" { aarch64-*-vxworks* } } */
 /* { dg-final { check-function-bodies "**" "" } } */
 
 void f(int, ...);
index 690aae8dfd5b5d2a0218a6efee16fa5608dd8e97..35b8ccc99e44e8786128e2d65a4d49be52a18196 100644 (file)
@@ -1,3 +1,4 @@
 /* { dg-options "-O2 -fstack-protector-all -fstack-clash-protection -fomit-frame-pointer --param stack-clash-protection-guard-size=12 -fsanitize=shadow-call-stack -ffixed-x18" } */
+/* { dg-skip-if "conflicts with x18" { aarch64-*-vxworks* } } */
 
 #include "stack-check-prologue-19.c"