From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2049) id 363C93856DF1; Thu, 5 May 2022 12:04:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 363C93856DF1 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)] Hack to investigate work required for Hybrid capabilities X-Act-Checkin: gcc X-Git-Author: Matthew Malcomson X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: 61be3869a3cf4067f1a7dacb5cc26900146d18e4 X-Git-Newrev: f67875053959be76f8437b453f4674faecd0409c Message-Id: <20220505120409.363C93856DF1@sourceware.org> Date: Thu, 5 May 2022 12:04:09 +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: Thu, 05 May 2022 12:04:09 -0000 https://gcc.gnu.org/g:f67875053959be76f8437b453f4674faecd0409c commit f67875053959be76f8437b453f4674faecd0409c Author: Matthew Malcomson Date: Thu Mar 17 15:46:40 2022 +0000 Hack to investigate work required for Hybrid capabilities This patch introduces a `-ffake-hybrid` flag. That flag randomly turns non-capability pionters into __capability pointers. This enables simulating Hybrid Morello code using C code not written for that target. Having that hack enables testing Hybrid functionality on our GCC testsuite. This can be done for both Hybrid Morello *and* for hybrid fake-capability. Having both means we can still use stock AArch64 machines for faster turnaround, and can use Morello environments to double-check our codegen. Diff: --- gcc/c-family/c-common.c | 20 ++++++++++++++++++++ gcc/c-family/c-common.h | 1 + gcc/c/c-convert.c | 3 +++ gcc/c/c-decl.c | 9 +++++++++ gcc/common.opt | 9 +++++++++ gcc/config/aarch64/aarch64.c | 3 +++ 6 files changed, 45 insertions(+) diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 11195e16576..6bba7c392d1 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -2679,6 +2679,26 @@ c_common_cap_from_noncap (tree type, tree expr) return ret; } +/* Generate a cast from a non-capability pointer to a capability pointer. + As above, this cast will necessarily create a pointer that does not have + valid metadata. */ +tree +c_common_cap_from_ptr (tree type, tree ptr_expr) +{ + gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr_expr)) + && capability_type_p (type)); + /* MORELLO TODO address spaces. + * Need to do special handling for capabilities, but also need to do special + * handling for address spaces, capability handling is usually done in + * frontend while address space handling is usually done in generic code + * `convert_to_pointer_1`. */ + gcc_assert (TYPE_ADDR_SPACE (TREE_TYPE (type)) + == TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (ptr_expr)))); + tree int_expr = convert (noncapability_type (type), ptr_expr); + return c_common_cap_from_noncap (type, int_expr); +} + + /* Build a bit-field integer type for the given WIDTH and UNSIGNEDP. */ tree diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 363f8d5bc77..88535e28feb 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -861,6 +861,7 @@ extern tree c_common_unsigned_type (tree); extern tree c_common_signed_type (tree); extern tree c_common_signed_or_unsigned_type (int, tree); extern tree c_common_cap_from_noncap (tree, tree); +extern tree c_common_cap_from_ptr (tree, tree); extern void c_common_init_ts (void); extern tree c_build_bitfield_integer_type (unsigned HOST_WIDE_INT, int); extern enum conversion_safety unsafe_conversion_p (tree, tree, tree, bool); diff --git a/gcc/c/c-convert.c b/gcc/c/c-convert.c index 3edd7ebe73a..3f763e8aaed 100644 --- a/gcc/c/c-convert.c +++ b/gcc/c/c-convert.c @@ -145,6 +145,9 @@ convert (tree type, tree expr) case REFERENCE_TYPE: if (capability_type_p (type) && TREE_CODE (TREE_TYPE (e)) == INTEGER_TYPE) ret = c_common_cap_from_noncap (type, e); + else if (capability_type_p (type) && !capability_type_p (TREE_TYPE (e)) + && POINTER_TYPE_P (TREE_TYPE (e))) + ret = c_common_cap_from_ptr (type, e); else ret = convert_to_pointer (type, e); goto maybe_fold; diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index e45f7c054f2..83a720c34dd 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -6984,6 +6984,15 @@ grokdeclarator (const struct c_declarator *declarator, type_quals = declarator->u.pointer_quals; declarator = declarator->declarator; + if (flag_fake_hybrid + && (rand() % flag_fake_hybrid) == 0) + { + capability_levels_in_declarator++; + tree attr_name = get_identifier ("cheri_capability"); + // tree attr_args = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE); + tree new_attrs = tree_cons (attr_name, NULL_TREE, returned_attrs); + returned_attrs = decl_attributes (&type, new_attrs, ATTR_FLAG_CHERI_INNER_APPLY); + } break; } default: diff --git a/gcc/common.opt b/gcc/common.opt index 4e254f25100..a874b24842a 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -172,6 +172,9 @@ int rtl_dump_and_exit Variable int flag_print_asm_name +Variable +int flag_fake_hybrid + ; Name of top-level original source file (what was input to cpp). ; This comes from the #-command at the beginning of the actual input. ; If there isn't any there, then this is the cc1 input file name. @@ -1218,6 +1221,12 @@ fdbg-cnt= Common RejectNegative Joined Var(common_deferred_options) Defer -fdbg-cnt=[:-][:-:...][,:...] Set the debug counter limit. +ffake-hybrid= +Common Joined RejectNegative UInteger Var(flag_fake_hybrid) Init(0) +Choose to do some fake hybrid capability stuff. +This is largely in order to explore whether using hybrid capabilities will +cause a lot of problems or not. + fdebug-prefix-map= Common Joined RejectNegative Var(common_deferred_options) Defer -fdebug-prefix-map== Map one directory name to another in debug information. diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 89840e54990..05b78dac74c 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -74,6 +74,7 @@ #include "intl.h" #include "expmed.h" #include "function-abi.h" +#include "toplev.h" /* This file should be included last. */ #include "target-def.h" @@ -15155,6 +15156,8 @@ aarch64_override_options_internal (struct gcc_options *opts) error ("MORELLO TODO OpenACC has not been implemented for Morello"); if (!flag_inline_atomics && TARGET_CAPABILITY_ANY) error ("MORELLO TODO -fno-inline-atomics has not been implemented for Morello"); + if (flag_fake_hybrid) + srand(get_random_seed(false)); if (TARGET_CAPABILITY_ANY && TARGET_SVE) error ("SVE is not supported with capabilities");