From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2049) id 43DE7385802B; Mon, 28 Feb 2022 12:08:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 43DE7385802B Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Matthew Malcomson To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] A testsuite-only patch that will: X-Act-Checkin: gcc X-Git-Author: Stam Markianos-Wright X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: 6404652ab0fc9904b48224d4a8a2e955f30c4e5e X-Git-Newrev: 39294e2fe8abb2b2a06c2d196cd05107b26b37cd Message-Id: <20220228120835.43DE7385802B@sourceware.org> Date: Mon, 28 Feb 2022 12:08:35 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Feb 2022 12:08:35 -0000 https://gcc.gnu.org/g:39294e2fe8abb2b2a06c2d196cd05107b26b37cd commit 39294e2fe8abb2b2a06c2d196cd05107b26b37cd Author: Stam Markianos-Wright Date: Wed Oct 20 09:53:48 2021 +0100 A testsuite-only patch that will: - Skip a number of tests that, by their design, will do something illegal with capability pointers. This includes casting to/from integers, using executable-stack trampolines or under-aligning the capability in a packed struct (for tests that are in a generic part of the testsuite -- tests that under-align capabilities in the aarch64 testsuite are left as FAILs in order to be revisited at a later data) - In the builtins testsuite: Here all the affected tests would override the Newlib definition of memset/memcpy/memmove/etc. with one provided in a) the test itself (e.g. see memops-asm) b) the `lib/chk.c` file, c) the `lib/.c` file. These overrides causes a problem for memset, because memset also gets called at the very start of crt0.s, before `__init_global_caps` and `__processRelocs`, so an exception gets raised when this new memset tries to access global variables like `memset_disallowed` `inside_main` through the GOT. To avoid this clash I have renamed the new memset to test_memset, which no longer overrides Newlib's memset (the final binary includes both Newlib's `memset` and the new `test_memset`) Now most things from the tests will call `test_memset`, but crt0 will correctly call Newlib's `memset`. Some test coverage is lost when doing this (namely the check against `memset_disallowed && inside_main && n < 2`) - In global_constants.c: Simply skip an invalid section of the test (we may want to further expand the test for PureCap in the future). The remaining execution failures in the testsuite are: The following are in the aarch64 target testsuite and they under-align capabilities in packed structs. This will need to be further addressed and the tests modified in the future: - aapcs64/morello-test_7.c - aapcs64/morello-test_8.c - aapcs64/morello-func-ret-1.c Builtin apply has not been implemented for Purecap Morello: - stackalign/builtin-apply-2.c - gcc.dg/builtin-apply2.c Diff: --- gcc/testsuite/gcc.c-torture/execute/960117-1.c | 1 + gcc/testsuite/gcc.c-torture/execute/builtin-prefetch-6.c | 1 + gcc/testsuite/gcc.c-torture/execute/builtins/chk.h | 4 ++++ gcc/testsuite/gcc.c-torture/execute/builtins/lib/chk.c | 8 ++++++++ gcc/testsuite/gcc.c-torture/execute/builtins/lib/memset.c | 4 ++++ gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c | 4 ++++ gcc/testsuite/gcc.c-torture/execute/comp-goto-1.c | 1 + gcc/testsuite/gcc.c-torture/execute/pr36339.c | 1 + gcc/testsuite/gcc.c-torture/execute/pr60003.c | 6 ++++-- gcc/testsuite/gcc.c-torture/execute/strct-pack-2.c | 1 + gcc/testsuite/gcc.dg/compat/struct-layout-1.exp | 6 ++++++ gcc/testsuite/gcc.dg/pragma-align.c | 2 +- gcc/testsuite/gcc.dg/strlenopt-63.c | 4 +++- gcc/testsuite/gcc.dg/torture/pr45623.c | 1 + gcc/testsuite/gcc.dg/torture/pr45967-2.c | 1 + gcc/testsuite/gcc.dg/torture/pr45967-3.c | 1 + gcc/testsuite/gcc.dg/torture/pr45967.c | 1 + gcc/testsuite/gcc.dg/torture/pr65077.c | 1 + gcc/testsuite/gcc.target/aarch64/morello/global-constants.c | 5 +++-- gcc/testsuite/lib/target-supports.exp | 2 ++ 20 files changed, 49 insertions(+), 6 deletions(-) diff --git a/gcc/testsuite/gcc.c-torture/execute/960117-1.c b/gcc/testsuite/gcc.c-torture/execute/960117-1.c index 741455b08b9..ce97dc69485 100644 --- a/gcc/testsuite/gcc.c-torture/execute/960117-1.c +++ b/gcc/testsuite/gcc.c-torture/execute/960117-1.c @@ -1,3 +1,4 @@ +/* { dg-skip-if "Test performs capability-invalidating illegal memory accesses" { cheri_capability_pure } } */ static char id_space[2] [32 +1]; typedef short COUNT; diff --git a/gcc/testsuite/gcc.c-torture/execute/builtin-prefetch-6.c b/gcc/testsuite/gcc.c-torture/execute/builtin-prefetch-6.c index f643c5c7286..9a9f2ab6da0 100644 --- a/gcc/testsuite/gcc.c-torture/execute/builtin-prefetch-6.c +++ b/gcc/testsuite/gcc.c-torture/execute/builtin-prefetch-6.c @@ -1,6 +1,7 @@ /* Test that __builtin_prefetch does no harm. Data prefetch should not fault if used with an invalid address. */ +/* { dg-skip-if "Test performs illegal memory accesses with invalid capabilities" { cheri_capability_pure } } */ #include diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/chk.h b/gcc/testsuite/gcc.c-torture/execute/builtins/chk.h index 9bf725560bf..9890af5c1e2 100644 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/chk.h +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/chk.h @@ -55,7 +55,11 @@ #undef __builtin_memmove #define __builtin_memmove(dst, src, len) memmove (dst, src, len) #undef __builtin_memset +#ifdef __CHERI_PURE_CAPABILITY__ +#define __builtin_memset(dst, val, len) test_memset (dst, val, len) +#else #define __builtin_memset(dst, val, len) memset (dst, val, len) +#endif #undef __builtin_strcpy #define __builtin_strcpy(dst, src) strcpy (dst, src) #undef __builtin_stpcpy diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/chk.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/chk.c index fd9e6015faa..2c82a9e3f8b 100644 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/chk.c +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/chk.c @@ -130,7 +130,11 @@ __memmove_chk (void *dst, const void *src, __SIZE_TYPE__ n, __SIZE_TYPE__ size) } void * +#ifdef __CHERI_PURE_CAPABILITY__ +test_memset (void *dst, int c, __SIZE_TYPE__ n) +#else memset (void *dst, int c, __SIZE_TYPE__ n) +#endif { while (n-- != 0) n[(char *) dst] = c; @@ -155,7 +159,11 @@ __memset_chk (void *dst, int c, __SIZE_TYPE__ n, __SIZE_TYPE__ size) ++chk_calls; if (n > size) __chk_fail (); +#ifdef __CHERI_PURE_CAPABILITY__ + return test_memset (dst, c, n); +#else return memset (dst, c, n); +#endif } char * diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memset.c b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memset.c index 90545abbf24..a39aabc89cb 100644 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memset.c +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/lib/memset.c @@ -3,7 +3,11 @@ extern int inside_main; __attribute__ ((__noinline__)) void * +#ifdef __CHERI_PURE_CAPABILITY__ +test_memset (void *dst, int c, __SIZE_TYPE__ n) +#else memset (void *dst, int c, __SIZE_TYPE__ n) +#endif { while (n-- != 0) n[(char *) dst] = c; diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c index 3baf7a64622..d9970e208c9 100644 --- a/gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c +++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c @@ -96,7 +96,11 @@ bcopy (const void *s, void *d, size_t n) } void * +#ifdef __CHERI_PURE_CAPABILITY__ +test_memset (void *d, int c, size_t n) +#else memset (void *d, int c, size_t n) +#endif { void *result = my_memset (d, c, n); TEST_ABORT; diff --git a/gcc/testsuite/gcc.c-torture/execute/comp-goto-1.c b/gcc/testsuite/gcc.c-torture/execute/comp-goto-1.c index 4379fe70e9c..5b6b4674c58 100644 --- a/gcc/testsuite/gcc.c-torture/execute/comp-goto-1.c +++ b/gcc/testsuite/gcc.c-torture/execute/comp-goto-1.c @@ -1,5 +1,6 @@ /* { dg-require-effective-target label_values } */ /* { dg-require-stack-size "4000" } */ +/* { dg-skip-if "Test performs capability-invalidating illegal memory accesses" { cheri_capability_pure } } */ #include diff --git a/gcc/testsuite/gcc.c-torture/execute/pr36339.c b/gcc/testsuite/gcc.c-torture/execute/pr36339.c index c4f36ddcace..2cfcc172871 100644 --- a/gcc/testsuite/gcc.c-torture/execute/pr36339.c +++ b/gcc/testsuite/gcc.c-torture/execute/pr36339.c @@ -1,3 +1,4 @@ +/* { dg-skip-if "Test performs capability-invalidating illegal memory accesses" { cheri_capability_pure } } */ extern void abort (void); typedef unsigned long my_uintptr_t; diff --git a/gcc/testsuite/gcc.c-torture/execute/pr60003.c b/gcc/testsuite/gcc.c-torture/execute/pr60003.c index 92bcc565980..cd33485cc72 100644 --- a/gcc/testsuite/gcc.c-torture/execute/pr60003.c +++ b/gcc/testsuite/gcc.c-torture/execute/pr60003.c @@ -2,9 +2,11 @@ /* { dg-require-effective-target indirect_jumps } */ extern void abort (void); - +#ifdef __GCC_ARM_CAPABILITY_ANY +__uintcap_t jmp_buf[5]; +#else unsigned long long jmp_buf[5]; - +#endif __attribute__((noinline, noclone)) void baz (void) { diff --git a/gcc/testsuite/gcc.c-torture/execute/strct-pack-2.c b/gcc/testsuite/gcc.c-torture/execute/strct-pack-2.c index be76c764521..60f343a9693 100644 --- a/gcc/testsuite/gcc.c-torture/execute/strct-pack-2.c +++ b/gcc/testsuite/gcc.c-torture/execute/strct-pack-2.c @@ -1,3 +1,4 @@ +/* { dg-skip-if "Test performs capability-invalidating illegal memory accesses" { cheri_capability_pure } } */ typedef struct { short a __attribute__ ((aligned (2),packed)); diff --git a/gcc/testsuite/gcc.dg/compat/struct-layout-1.exp b/gcc/testsuite/gcc.dg/compat/struct-layout-1.exp index 66ee483e491..8578a69b4c5 100644 --- a/gcc/testsuite/gcc.dg/compat/struct-layout-1.exp +++ b/gcc/testsuite/gcc.dg/compat/struct-layout-1.exp @@ -34,6 +34,12 @@ if $tracelevel then { strace $tracelevel } +# The random generator in this testsuite may deliberately underalign +# capabilities in a packed struct. This is currently not supported. +if { [check_effective_target_cheri_capability_pure] } then { + return +} + global GCC_UNDER_TEST global compat_save_gcc_under_test global compat_use_alt diff --git a/gcc/testsuite/gcc.dg/pragma-align.c b/gcc/testsuite/gcc.dg/pragma-align.c index 4c0138b5f89..0ecf993234b 100644 --- a/gcc/testsuite/gcc.dg/pragma-align.c +++ b/gcc/testsuite/gcc.dg/pragma-align.c @@ -9,7 +9,7 @@ struct { long two; } defaultalign; -#if defined(__LP64__) +#if __SIZEOF_LONG__ == 8 #pragma pack(8) #else #pragma pack(4) diff --git a/gcc/testsuite/gcc.dg/strlenopt-63.c b/gcc/testsuite/gcc.dg/strlenopt-63.c index f77db6bbe7a..f09bbc002cf 100644 --- a/gcc/testsuite/gcc.dg/strlenopt-63.c +++ b/gcc/testsuite/gcc.dg/strlenopt-63.c @@ -3,7 +3,9 @@ Verify that strlen of pointers to char arrays are computed correctly (whether folded or not). { dg-do run } - { dg-options "-O2 -Wall" } */ + { dg-options "-O2 -Wall" } + { dg-skip-if "Test performs illegal out-of-bounds capability memory accesses" { cheri_capability_pure } } + */ #include "strlenopt.h" diff --git a/gcc/testsuite/gcc.dg/torture/pr45623.c b/gcc/testsuite/gcc.dg/torture/pr45623.c index 693a8c4c7be..ce3914e93ec 100644 --- a/gcc/testsuite/gcc.dg/torture/pr45623.c +++ b/gcc/testsuite/gcc.dg/torture/pr45623.c @@ -1,5 +1,6 @@ /* { dg-do run } */ /* { dg-options "-std=c99" } */ +/* { dg-skip-if "Test performs capability-invalidating illegal memory accesses" { cheri_capability_pure } } */ #include diff --git a/gcc/testsuite/gcc.dg/torture/pr45967-2.c b/gcc/testsuite/gcc.dg/torture/pr45967-2.c index 6959fd5e15c..8c0a7c420ba 100644 --- a/gcc/testsuite/gcc.dg/torture/pr45967-2.c +++ b/gcc/testsuite/gcc.dg/torture/pr45967-2.c @@ -1,4 +1,5 @@ /* { dg-do run } */ +/* { dg-skip-if "Test performs capability-invalidating illegal memory accesses" { cheri_capability_pure } } */ extern void abort (void); int b; diff --git a/gcc/testsuite/gcc.dg/torture/pr45967-3.c b/gcc/testsuite/gcc.dg/torture/pr45967-3.c index 1a23a773b17..66bf2a229cc 100644 --- a/gcc/testsuite/gcc.dg/torture/pr45967-3.c +++ b/gcc/testsuite/gcc.dg/torture/pr45967-3.c @@ -1,4 +1,5 @@ /* { dg-do run } */ +/* { dg-skip-if "Test performs capability-invalidating illegal memory accesses" { cheri_capability_pure } } */ extern void abort (void); void diff --git a/gcc/testsuite/gcc.dg/torture/pr45967.c b/gcc/testsuite/gcc.dg/torture/pr45967.c index 0a5b206e5e1..02515f3b79b 100644 --- a/gcc/testsuite/gcc.dg/torture/pr45967.c +++ b/gcc/testsuite/gcc.dg/torture/pr45967.c @@ -1,4 +1,5 @@ /* { dg-do run } */ +/* { dg-skip-if "Test performs capability-invalidating illegal memory accesses" { cheri_capability_pure } } */ extern void abort (void); void __attribute__((noinline,noclone)) diff --git a/gcc/testsuite/gcc.dg/torture/pr65077.c b/gcc/testsuite/gcc.dg/torture/pr65077.c index f57356c60bb..5c191fd911e 100644 --- a/gcc/testsuite/gcc.dg/torture/pr65077.c +++ b/gcc/testsuite/gcc.dg/torture/pr65077.c @@ -1,4 +1,5 @@ /* { dg-do run } */ +/* { dg-skip-if "Test performs capability-invalidating illegal memory accesses" { cheri_capability_pure } } */ extern void abort (void); extern void *memcpy(void *, const void *, __SIZE_TYPE__); diff --git a/gcc/testsuite/gcc.target/aarch64/morello/global-constants.c b/gcc/testsuite/gcc.target/aarch64/morello/global-constants.c index 8e413aace32..624e6742095 100644 --- a/gcc/testsuite/gcc.target/aarch64/morello/global-constants.c +++ b/gcc/testsuite/gcc.target/aarch64/morello/global-constants.c @@ -33,13 +33,14 @@ int main() assert (ucap2 == 100); assert (((char*)ucap)[0] == 'a' && ((char*)ucap)[7] == 'h' && ((char*)ucap)[8] == '\0'); */ - /* TODO put an `if !pure-cap` clause here, and assert that accesses fail if - * on purecap. */ +#ifndef __CHERI_PURE_CAPABILITY__ assert (((char*)x)[0] == 'a' && ((char*)x)[4] == 'e' && ((char*)x)[5] == '\0'); assert (basicstring[0] == 'a' && basicstring[6] == 'g' && basicstring[7] == '\0'); assert (stringval[0] == 'a' && stringval[5] == 'f' && stringval[6] == '\0'); +#endif + return 0; } /* TODO Execution test to check everything works properly (i.e. all the diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index be4f0e6db73..544d597710b 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -537,6 +537,8 @@ proc check_effective_target_trampolines { } { return 0 } if { [istarget avr-*-*] + || [istarget aarch64-none-elf] + && [check_effective_target_aarch64_capability_any] || [istarget msp430-*-*] || [istarget nvptx-*-*] || [istarget hppa2.0w-hp-hpux11.23]