]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite/arm: Add arm_cmse_hw effective target
authorChristophe Lyon <christophe.lyon@linaro.org>
Mon, 26 Apr 2021 11:23:41 +0000 (11:23 +0000)
committerChristophe Lyon <christophe.lyon@linaro.org>
Mon, 26 Apr 2021 11:23:41 +0000 (11:23 +0000)
Some of the CMSE tests have 'dg-do run', but qemu-arm does not support
the privileged instructions involved; one has to use qemu-system-arm
for this, which in turn requires modifications to the default
newlib/libgloss startup code to enable the FPU as the FP status
registers need to be saved when using CMSE code.

This patch introduces arm_cmse_hw, similar to arm_neon_hw, to detect
whether the execution engine supports the CMSE instructions. If not,
we set dg-do-what-default to assemble instead of run. We thus remove
all the 'dg-do run' directives from CMSE tests, to rely on
dg-do-what-default instead.

Note that cmse-16.c used to pass with dg-do run under qemu-arm,
because the property being tested is not available (qemu-arm does not
model secure vs non-secure memory). The patch removes dg-do from it
too, since it is relevant only with an adequate simulator.

Before the patch, bitfield-[123].c and struct-1.c fail at execution
under qemu-arm. With the patch, execution is skipped.

The same tests pass under qemu-system-arm both with and without the
patch.

This avoids failures when testing with
-mthumb/-mfloat-abi=hard/-march=armv8-m.main+fp+dsp under qemu-arm for
cortex-m33.

I'm also running tests with qemu-system-arm for cortex-m33, but I run
only cmse.exp with a patched newlib in this case: I use qemu-arm for
all combinations except that one because it's faster and supports
semihosting.

I do not have a setup to check this with actual hardware or another
simulator.

2021-04-26  Christophe Lyon  <christophe.lyon@linaro.org>

gcc/
* doc/sourcebuild.texi (arm_cmse_hw): Document.

gcc/testsuite/
* gcc.target/arm/cmse/bitfield-1.c: Remove dg-do.
* gcc.target/arm/cmse/bitfield-2.c: Likewise.
* gcc.target/arm/cmse/bitfield-3.c: Likewise.
* gcc.target/arm/cmse/cmse-16.c: Likewise.
* gcc.target/arm/cmse/struct-1.c: Likewise.
* gcc.target/arm/cmse/cmse.exp: Set dg-do-what-default depending
on arm_cmse_hw.
* lib/target-supports.exp (check_effective_target_arm_cmse_hw):
New.

gcc/doc/sourcebuild.texi
gcc/testsuite/gcc.target/arm/cmse/bitfield-1.c
gcc/testsuite/gcc.target/arm/cmse/bitfield-2.c
gcc/testsuite/gcc.target/arm/cmse/bitfield-3.c
gcc/testsuite/gcc.target/arm/cmse/cmse-16.c
gcc/testsuite/gcc.target/arm/cmse/cmse.exp
gcc/testsuite/gcc.target/arm/cmse/struct-1.c
gcc/testsuite/lib/target-supports.exp

index d3200a42e44170e96ef0b8854e7d3352ec29cf18..3a1d65368338022ca4dea7c64796b18f84a5fdc3 100644 (file)
@@ -2096,6 +2096,9 @@ div instruction.
 ARM target supports ARMv8-M Security Extensions, enabled by the @code{-mcmse}
 option.
 
+@item arm_cmse_hw
+Test system supports executing CMSE instructions.
+
 @item arm_coproc1_ok
 @anchor{arm_coproc1_ok}
 ARM target supports the following coprocessor instructions: @code{CDP},
index cae2f06140766176c9af6e4b2b4a3e722fbad67c..5685f744435cac17d65f8896dcefdf657ad3dd45 100644 (file)
@@ -1,4 +1,4 @@
-/* { dg-do run } */
+/* This test is executed only if the execution engine supports CMSE instructions.  */
 /* { dg-options "--save-temps -mcmse -Wl,--section-start,.gnu.sgstubs=0x00400000" } */
 
 typedef struct
index 21a53cd85792e439314f5c88080d7f1c6fcdec66..7a794d446448ad2f3ca5329098cf7a4abac93bdf 100644 (file)
@@ -1,4 +1,4 @@
-/* { dg-do run } */
+/* This test is executed only if the execution engine supports CMSE instructions.  */
 /* { dg-options "--save-temps -mcmse -Wl,--section-start,.gnu.sgstubs=0x00400000" } */
 
 typedef struct
index e8f973e3f06881d33d661f81c0eb6671e48a0d01..5875f8dff486e3e44cec91a255acf4d08c6c6a7e 100644 (file)
@@ -1,4 +1,4 @@
-/* { dg-do run } */
+/* This test is executed only if the execution engine supports CMSE instructions.  */
 /* { dg-options "--save-temps -mcmse -Wl,--section-start,.gnu.sgstubs=0x00400000" } */
 
 typedef struct
index 3fb0380afaafa506cdb68f4d3c1dd7b535d43f26..6a243d5fa8d26ac2b83aa1575144ddf7dfdf56ff 100644 (file)
@@ -1,4 +1,8 @@
-/* { dg-do run } */
+/* This test is executed only if the execution engine supports CMSE instructions.  */
+/* Note that it "passes" on qemu-arm while it shouldn't because that simulator
+   does not model secure memory: it's better to skip it in this case, and rely
+   on do-what-default as set in cmse.exp. (It works as expected with
+   qemu-system-mode).  */
 /* { dg-options "-Os -mcmse" }  */
 
 #include <arm_cmse.h>
index 6ce99fedef29be09d8c53282bd1507613bae638a..4da1a465547c06d109bde20e448fa93c9ebaa10a 100644 (file)
@@ -34,7 +34,12 @@ if ![info exists DEFAULT_CFLAGS] then {
 dg-init
 
 set saved-dg-do-what-default ${dg-do-what-default}
-set dg-do-what-default "assemble"
+
+if {[is-effective-target arm_cmse_hw]} then {
+    set dg-do-what-default run
+} else {
+    set dg-do-what-default assemble
+}
 
 set saved-lto_torture_options ${LTO_TORTURE_OPTIONS}
 set LTO_TORTURE_OPTIONS ""
index 755564369ae7deecfb038e67591e679bb06f62b1..75a99f487e7a0cb4ab6960b6c0bf0338a9c171fd 100644 (file)
@@ -1,4 +1,4 @@
-/* { dg-do run } */
+/* This test is executed only if the execution engine supports CMSE instructions.  */
 /* { dg-options "--save-temps -mcmse -Wl,--section-start,.gnu.sgstubs=0x00400000" } */
 
 typedef struct
index ad323107f2ec5d55a77214beca5e4135643528b4..a522da322aa8b1f6305fe66a106f3516e354910c 100644 (file)
@@ -4861,6 +4861,21 @@ proc check_effective_target_arm_cmse_ok {} {
     } "-mcmse"];
 }
 
+# Return 1 if the target supports executing CMSE instructions, 0
+# otherwise.  Cache the result.
+
+proc check_effective_target_arm_cmse_hw { } {
+    return [check_runtime arm_cmse_hw_available {
+       int __attribute__ ((cmse_nonsecure_entry)) ns_func(void)
+       {
+           return 0;
+       }
+       int main (void)
+       {
+           return ns_func();
+       }
+    } "-mcmse -Wl,--section-start,.gnu.sgstubs=0x00400000"]
+}
 # Return 1 if the target supports executing MVE instructions, 0
 # otherwise.