public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Alex Coplan <acoplan@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] libstdc++: Update personality function for purecap Date: Tue, 12 Jul 2022 10:36:33 +0000 (GMT) [thread overview] Message-ID: <20220712103633.E838C3857C76@sourceware.org> (raw) https://gcc.gnu.org/g:afaa9f2bb327ae04a22d26c5793079f7c06da1bf commit afaa9f2bb327ae04a22d26c5793079f7c06da1bf Author: Alex Coplan <alex.coplan@arm.com> Date: Sat Jun 18 11:45:33 2022 +0100 libstdc++: Update personality function for purecap This updates the C++ personality function following the changes made to the libgcc C personality function for pure-capability Morello. There are two main changes here. The first is using __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. We also improve on the robustness of the existing code in the C personality function by asserting that we only see the implemented capability landing pad marker value (0xd) and also handling the case where this is no associated landing pad with a given call-site table entry. This fixes many execution tests involving exception handling in the g++ testsuite. libgcc/ChangeLog: * unwind-c.c (PERSONALITY_FUNCTION): Fix handling of case where call-site table entry doesn't have an associated landing pad. libstdc++-v3/ChangeLog: * libsupc++/eh_personality.cc (PERSONALITY_FUNCTION): Adapt for pure-capability Morello. Diff: --- libgcc/unwind-c.c | 17 +++++++++--- libstdc++-v3/libsupc++/eh_personality.cc | 45 +++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/libgcc/unwind-c.c b/libgcc/unwind-c.c index ac0085c1159..a2a5c2e92bf 100644 --- a/libgcc/unwind-c.c +++ b/libgcc/unwind-c.c @@ -214,10 +214,19 @@ PERSONALITY_FUNCTION (int version, _Unwind_Ptr marker = 0; /* Single uleb128 value as the capability marker. */ p = read_encoded_value (0, DW_EH_PE_uleb128, p, &marker); - /* 8 byte value indicating the offset from said 8 byte value. - Could use DW_EH_PE_indirect except that the offset is zero if there is - no landing pad. */ - p = read_encoded_value (0, DW_EH_PE_pcrel | DW_EH_PE_udata8, p, &cs_lp); + if (marker == 0xd) + { + /* 8 byte value indicating the offset from said 8 byte value. + Could use DW_EH_PE_indirect except that the offset is zero + if there is no landing pad. */ + p = read_encoded_value (0, DW_EH_PE_pcrel | DW_EH_PE_udata8, p, + &cs_lp); + } + else if (marker) + /* Unsupported landing pad marker value. */ + __builtin_abort (); + else + cs_lp = 0; /* No landing pad. */ # else p = read_encoded_value (0, info.call_site_encoding, p, &cs_lp); # endif diff --git a/libstdc++-v3/libsupc++/eh_personality.cc b/libstdc++-v3/libsupc++/eh_personality.cc index fd7cd6fc798..25079f76725 100644 --- a/libstdc++-v3/libsupc++/eh_personality.cc +++ b/libstdc++-v3/libsupc++/eh_personality.cc @@ -375,7 +375,8 @@ PERSONALITY_FUNCTION (int version, const unsigned char *language_specific_data; const unsigned char *action_record; const unsigned char *p; - _Unwind_Ptr landing_pad, ip; + _Unwind_Ptr landing_pad, ip_ptr; + _Unwind_Address ip; int handler_switch_value; void* thrown_ptr = 0; bool foreign_exception; @@ -422,8 +423,8 @@ PERSONALITY_FUNCTION (int version, // function and LSDA pointers. The ARM implementation caches these in // the exception header (UCB). To avoid rewriting everything we make a // virtual scratch register point at the UCB. - ip = (_Unwind_Ptr) ue_header; - _Unwind_SetGR(context, UNWIND_POINTER_REG, ip); + ip_ptr = (_Unwind_Ptr) ue_header; + _Unwind_SetGR (context, UNWIND_POINTER_REG, ip_ptr); #else __cxa_exception* xh = __get_exception_header_from_ue(ue_header); @@ -454,10 +455,17 @@ PERSONALITY_FUNCTION (int version, p = parse_lsda_header (context, language_specific_data, &info); info.ttype_base = base_of_encoded_value (info.ttype_encoding, context); #ifdef _GLIBCXX_HAVE_GETIPINFO - ip = _Unwind_GetIPInfo (context, &ip_before_insn); + ip_ptr = _Unwind_GetIPInfo (context, &ip_before_insn); #else - ip = _Unwind_GetIP (context); + ip_ptr = _Unwind_GetIP (context); #endif + +#ifdef __USING_SJLJ_EXCEPTIONS__ + ip = (_Unwind_Address) ip_ptr; +#else + ip = __builtin_code_address_from_pointer ((void *)ip_ptr); +#endif + if (! ip_before_insn) --ip; landing_pad = 0; @@ -502,7 +510,26 @@ PERSONALITY_FUNCTION (int version, // Note that all call-site encodings are "absolute" displacements. p = read_encoded_value (0, info.call_site_encoding, p, &cs_start); p = read_encoded_value (0, info.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. + std::abort (); + } + else + cs_lp = 0; // No landing pad. +#else p = read_encoded_value (0, info.call_site_encoding, p, &cs_lp); +#endif p = read_uleb128 (p, &cs_action); // The table is sorted, so if we've passed the ip, stop. @@ -511,7 +538,13 @@ PERSONALITY_FUNCTION (int version, else if (ip < info.Start + cs_start + cs_len) { if (cs_lp) - landing_pad = info.LPStart + cs_lp; + { +#ifdef __CHERI_PURE_CAPABILITY__ + landing_pad = *(_Unwind_Ptr *)cs_lp; +#else + landing_pad = info.LPStart + cs_lp; +#endif + } if (cs_action) action_record = info.action_table + cs_action - 1; goto found_something;
reply other threads:[~2022-07-12 10:36 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220712103633.E838C3857C76@sourceware.org \ --to=acoplan@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).