From: Iain Sandoe <idsandoe@googlemail.com>
To: Jason Merrill <jason@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>, Jakub Jelinek <jakub@redhat.com>
Subject: [PATCH/RFC] On the use of -funreachable-traps to deal with PR 109627
Date: Tue, 9 Apr 2024 00:04:01 +0100 [thread overview]
Message-ID: <56A9A5FB-8294-47CB-A6C4-22FD5561C71A@googlemail.com> (raw)
Hi
PR 109627 is about functions that have had their bodies completely elided, but still have the wrappers for EH frames (either .cfi_xxx or LFSxx/LFExx).
These are causing issues for some linkers because such functions result in FDEs with a 0 code extent.
The simplest representation of this is (from PR109527)
void foo () { __builtin_unreachable (); }
The solution (so far) is to detect this case during final lowering and replace the unreachable (which is expanded to nothing, at least for the targets I’ve dealt with) by a trap; this results in two positive improvements (1) the FDE is now finite-sized so the linker consumes it and (2) actually the trap is considerably more user-friendly UB than falling through to some other arbitrary place.
I was looking into using -funreachable-traps to do this for aarch64 Darwin - because the ad-hoc solutions that were applied to X86 and PPC are not easily usable for aarch64.
-funreachabe-traps was added for similar reasons (helping make missing returns less unexpected) in r13-1204-gd68d3664253696 by Jason (and then there have been further improvements resulting in the use of __builtin_unreachable trap () from Jakub)
As I read the commit message for r13-1204, I would expect -funreachable-traps to work for the simple case above, but it does not. I think that is because the incremental patch below is needed. however, I am not sure if there was some reason this was not done at the time?
PR 109627 is currently a show-stopper for the aarch64-darwin branch since libgomp and libgm2 fail to bootstrap - and other workarounds (e.g. -D__builtin_unreachable=__builtin_trap) do not work got m2 (since it does not use the C preprocessor by default).
Setting -funreachable-traps either per affected file, or globally for a target resolves the issue in a neater manner.
Any guidance / comments would be most welcome - if the direction seems sane, I can repost this patch formally.
(I have tested quite widely on Darwin and on a small number of Linux cases too)
thanks
Iain
* I will note that applying this does result in some regressions in several contracts test cases - but they also regress for -fsanitize=undefined -fsanitise-traps (not yet clear if that’s expected or we’ve uncovered a bug in the contracts impl.).
----------
diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index f8d94c4b435..e2d26e45744 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -5931,7 +5931,8 @@ expand_builtin_unreachable (void)
{
/* Use gimple_build_builtin_unreachable or builtin_decl_unreachable
to avoid this. */
- gcc_checking_assert (!sanitize_flags_p (SANITIZE_UNREACHABLE));
+ gcc_checking_assert (!sanitize_flags_p (SANITIZE_UNREACHABLE)
+ && !flag_unreachable_traps);
emit_barrier ();
}
@@ -10442,7 +10443,7 @@ fold_builtin_0 (location_t loc, tree fndecl)
case BUILT_IN_UNREACHABLE:
/* Rewrite any explicit calls to __builtin_unreachable. */
- if (sanitize_flags_p (SANITIZE_UNREACHABLE))
+ if (sanitize_flags_p (SANITIZE_UNREACHABLE) || flag_unreachable_traps)
return build_builtin_unreachable (loc);
break;
====
next reply other threads:[~2024-04-08 23:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-08 23:04 Iain Sandoe [this message]
2024-04-08 23:11 ` Andrew Pinski
2024-04-09 4:03 ` Jeff Law
2024-04-09 7:03 ` Richard Biener
2024-04-09 7:11 ` Jakub Jelinek
2024-04-09 7:44 ` Richard Biener
2024-04-09 7:48 ` Jakub Jelinek
2024-04-09 7:53 ` Iain Sandoe
2024-04-09 13:59 ` Iain Sandoe
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=56A9A5FB-8294-47CB-A6C4-22FD5561C71A@googlemail.com \
--to=idsandoe@googlemail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=jason@redhat.com \
/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: link
Be 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).