From patchwork Tue Sep 26 11:46:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 144839 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1849999vqu; Tue, 26 Sep 2023 04:52:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvn4dKfxoaPdLDwuDubNvh0nSPc4tmgzy7B8YJNzOkc7Jhw9oWIupfm/A23yTYtG1R37nB X-Received: by 2002:a17:907:75c2:b0:9a9:f042:deb9 with SMTP id jl2-20020a17090775c200b009a9f042deb9mr3560279ejc.19.1695729132229; Tue, 26 Sep 2023 04:52:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695729132; cv=none; d=google.com; s=arc-20160816; b=K56KFc1GYtTaS3NmuaMG6eJSjoRkPr4NKdC/IRkLsYTrZQCCs177uvR3lqxEQAiDW7 jenpZPi02z60J+Az9PqJci+CFfOsUcEviwsceDgFlJXRwvvtIRVlp0i3hfTzVxKer5kD 1VhfdBnVrSw2QNXh+YwIPE++EYdzX/e6IZjxhpKhNMDABx+taw7495XUjomR5WYxlUzX srQTSqbq9vWUg8nNUd2HwIS6JoUFh4QSXxHVD4BQhW4TMmlSsXlNw22KhpBCh4smomxh pPwWoIj32HEPEYPBoryklSpMCYXJq2KNoBEOcTn2oNItiSXA3ricu2JaqJ4r3NKt5Lnm K3pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=Chj5mFw/CLmcbZaGGsQvWNET9Xvic7Ltgn0G6rA+B9o=; fh=SM/j4n0SpiXu4rAydeMvRR0AQztOTSK6Iork7L9Y9A4=; b=F2y1EIkPsz8xjfqVuNI4nw2T4ZWmISZQydFhNKO4PuezGinawaa+7pNX9EfZkIISE1 pVKF0jAuHpOgycR7b2JHjnOfW7/XuOseJc7HyhX+5cTa/oM/xXhrfjUP+og/mI8AXhjy f706F2XpX9/PmaybRycwERTejt6jMXgRYBWSM7Vt28geNbjBQ8Pg29FlXKegLIOI4rgX jhVf3yy+EPpzdi4uz16s9CzbvywvzNgsdCqPLwensfttv1jigFXOTfbuRohh6wMnvnTr XUfmgzkkmWWyWCs15dRQVUUrqoWMtWf+tJpeJwQPf+PyHRaCNnJX14jvmGsR5KZL+GUG G7oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=UsXR3fEr; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id br11-20020a170906d14b00b0099bce4aa78dsi10446056ejb.865.2023.09.26.04.52.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 04:52:12 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=UsXR3fEr; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 607533947438 for ; Tue, 26 Sep 2023 11:47:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 7C1C7386194F for ; Tue, 26 Sep 2023 11:46:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7C1C7386194F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-401d6f6b2e0so64862705e9.1 for ; Tue, 26 Sep 2023 04:46:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1695728789; x=1696333589; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Chj5mFw/CLmcbZaGGsQvWNET9Xvic7Ltgn0G6rA+B9o=; b=UsXR3fEr74tS3HAJjrI3fXaY+9t/QvJRiH/Q4fo3eWlenfAaur8hijf+upC7QjXlLD snEaHMminL6KTXKPiMc04D66hrxC/QH97IjUt1B3JDYkxfEhHa5ynabEqdfPpL5iHCFl wm65cTpdSXoKpVQTGHw4sjwUtJRDkOUUEnfJfrIXeb0zqIFI6ivGQVI5LplXfMeUxg9B 1mytgd3GZzLkDr+Pg9hQKV2592o0azq/ODJZCycXKZZcxIjbhutDAkrgYjLCADFlXbb9 /L10XaNe2N26DA8I2wuPqmgAXYIWyCHM+Qwql4hEVPtf8NrFWMhsZ69uk+uT9MAPcGaN Y00g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695728789; x=1696333589; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Chj5mFw/CLmcbZaGGsQvWNET9Xvic7Ltgn0G6rA+B9o=; b=k6pMcIXwyGIL1HIaLeAT6scELw75JgA03RhTSR5435/G2oNZtvDAPQ75XJsM/TZx1Z aoyouxFX+plw5QR6Xpn1sRyIMI2ayHi4EEm2TK4ReD7QRo0opmSxNiNOIbtxdW2vyPXX fXoBLkbC9StsveeYfTt6CPFw2CJ5jI6VWxa5J3UWF58C9110YUe63Q0Aj1VVRaqyANor 7cxuZUJNbdFT389RyPWfnI6815Q3TO8QEiaWPl+lhNYd/X75PXXu5nPI3fb6zKeh53YR eXhP3Uq1N1rnVDefl4ypYMIrKRqsvvP93PQOhJ1Xi1gsR99O5QY2HM4m9bJwqEB6+BNl ImgQ== X-Gm-Message-State: AOJu0YyAL94RkkV/Mpuc36QMHQEYWDeHPU+u/w0axKefnepr3LMwvhO0 UJeXa8t5CV41Fcf0RcqSCMpgHKQHKLfa4k8CL5FLbg== X-Received: by 2002:adf:fc8f:0:b0:323:269d:5a6e with SMTP id g15-20020adffc8f000000b00323269d5a6emr1996232wrr.6.1695728789232; Tue, 26 Sep 2023 04:46:29 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:27f0:a2f3:f97:f30e]) by smtp.gmail.com with ESMTPSA id x15-20020adfcc0f000000b0032330e43590sm3035488wrh.22.2023.09.26.04.46.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 04:46:28 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Daniel King Subject: [COMMITTED] ada: Update personality function for CHERI purecap Date: Tue, 26 Sep 2023 13:46:27 +0200 Message-ID: <20230926114627.3272774-1-poulhies@adacore.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778100870750740878 X-GMAIL-MSGID: 1778100870750740878 From: Daniel King This makes two changes to the GNAT personality function to reflect differences for pure capability CHERI/Morello. The first is to use __builtin_code_address_from_pointer to drop the LSB from Morello code pointers when searching through call-site tables (without this we would never find the right landing pad when unwinding). The second change is to reflect the change in the exception table format for pure-capability Morello where the landing pad is a capability indirected by an offset in the call-site table. gcc/ada/ * raise-gcc.c (get_ip_from_context): Adapt for CHERI purecap (get_call_site_action_for): Adapt for CHERI purecap Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/raise-gcc.c | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/gcc/ada/raise-gcc.c b/gcc/ada/raise-gcc.c index 56ddfc5a6cf..bdf1c26e612 100644 --- a/gcc/ada/raise-gcc.c +++ b/gcc/ada/raise-gcc.c @@ -50,10 +50,12 @@ #ifdef __cplusplus # include +# include # include #else # include # include +# include # include #endif @@ -592,6 +594,11 @@ get_ip_from_context (_Unwind_Context *uw_context) #else _Unwind_Ptr ip = _Unwind_GetIP (uw_context); #endif + +#if !defined(__USING_SJLJ_EXCEPTIONS__) && defined(__CHERI__) + ip = __builtin_code_address_from_pointer ((void *)ip); +#endif + /* Subtract 1 if necessary because GetIPInfo yields a call return address in this case, while we are interested in information for the call point. This does not always yield the exact call instruction address but always @@ -850,7 +857,27 @@ get_call_site_action_for (_Unwind_Ptr ip, /* Note that all call-site encodings are "absolute" displacements. */ p = read_encoded_value (0, region->call_site_encoding, p, &cs_start); p = read_encoded_value (0, region->call_site_encoding, p, &cs_len); +#ifdef __CHERI_PURE_CAPABILITY__ + // Single uleb128 value as the capability marker. + _Unwind_Ptr marker = 0; + p = read_encoded_value (0, DW_EH_PE_uleb128, p, &marker); + if (marker == 0xd) + { + /* 8-byte offset to the (indirected) capability. */ + p = read_encoded_value (0, DW_EH_PE_pcrel | DW_EH_PE_udata8, p, + &cs_lp); + } + else if (marker) + { + /* Unsupported landing pad marker value. */ + abort (); + } + else + cs_lp = 0; // No landing pad. +#else p = read_encoded_value (0, region->call_site_encoding, p, &cs_lp); +#endif + p = read_uleb128 (p, &cs_action); db (DB_CSITE, @@ -859,18 +886,24 @@ get_call_site_action_for (_Unwind_Ptr ip, (char *)region->lp_base + cs_lp, (void *)cs_lp); /* The table is sorted, so if we've passed the IP, stop. */ - if (ip < region->base + cs_start) + if (ip < region->base + (size_t)cs_start) break; /* If we have a match, fill the ACTION fields accordingly. */ - else if (ip < region->base + cs_start + cs_len) + else if (ip < region->base + (size_t)cs_start + (size_t)cs_len) { /* Let the caller know there may be an action to take, but let it determine the kind. */ action->kind = unknown; if (cs_lp) - action->landing_pad = region->lp_base + cs_lp; + { +#ifdef __CHERI_PURE_CAPABILITY__ + action->landing_pad = *(_Unwind_Ptr *)cs_lp; +#else + action->landing_pad = region->lp_base + cs_lp; +#endif + } else action->landing_pad = 0;