From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 5E1FD3858CD1 for ; Mon, 8 Apr 2024 23:04:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E1FD3858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=googlemail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=googlemail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5E1FD3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::332 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712617447; cv=none; b=tnvQzpLdvArlWmj1Zbcx0oUXdye/PMsJAEwihZtRT5xU0gLZCGDnTYsYYMSFbb5izHw5+sLlTw6nxLJZeKQ2Lvt2RR++UutXPgBe3+ODEOl/68xCLDwdQbEpWmw0e2u/ESwll8KOkbGEyyoP9njm5/yCvuJjhs0DKwqIAcEsQIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712617447; c=relaxed/simple; bh=XgJsSuF6uvJc6b7ch3CvH7tgoxctXeDeY9QZM3QvQks=; h=DKIM-Signature:From:Mime-Version:Subject:Message-Id:Date:To; b=bZVl1cDofe/ldfw8uAPUzjbFPx9ValQrrGUUFyGi9Z11z6BQp2cqVPcEXxrud/PFCylaYOVzUx/D4xe1xFngfaC/c2wmoiYpp3W3tdxFTyY2iN09AZi7Uzs5717g58Ptwr/XbXKLJu8Tn45wv+tSEP4pKRnp7MP2v7zJeGGDqkc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-416923f05faso5758595e9.1 for ; Mon, 08 Apr 2024 16:04:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20230601; t=1712617443; x=1713222243; darn=gcc.gnu.org; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=12XuM/Z2+X4SzRTpVp/a8l6WfM4fBNkyK0PG37gKIf0=; b=i9WkIElvKblj5g3u2DLeiBZ7jhuOU/YGligd805vpVEofhZr0LowO/HQuorHrnbwgr uunfQjiie/91mv9Lu6roRP70gwtDFiybsBHl/GPyTLEQAR1IrScCkkK9isNd8R/ZgkcO XQFJcCosygZYn3MOprumACU4Uoa2d7+A0dooekwaEI6OGUeSoxlM2J2quJLrcml1K9+q G3ohteQB6As+8XrkCnasuVi10w8zBakD1X1NLNB65sXK7WDO4FM6dCQ47WD/RSJ8kd+b crCL2G0HxnEgsnOvuKop83oq4tG5irWqUDQN34muQp+I7xWB8BnP9ogJX73gVSFgxcDG kJgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712617443; x=1713222243; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=12XuM/Z2+X4SzRTpVp/a8l6WfM4fBNkyK0PG37gKIf0=; b=N0unPwrA9JEbPRBGTdtTpkTYeI2S8nD0HABHztlAmW5IWQu/1dNDeEBdEacOp9nrMJ eHLT4Y/4buYvzeMa14mSSVqXv7TM+1Z3221xKjudHDF0RIXb3+veL/q3TCSnqCL+ZR/8 4I1hGzrBhaoGB2pwu89H6TCYyma/3Tg7NaWNfuZEHsjc5HBIxFEOQv786ECqvDmbq9MF 4ppWdMtwQaLIklWcaap/qtsMKyy5L687mM3EwuRpe9S7pWLSOh6FqYJVqRPjN+MNL1Fu nsjB2p1zYrR594ihKb8SbCN8zYlQ7cHlqSsV6S4lph43o0xRZyJbR+kRdG6FlVzLnfsV URQg== X-Gm-Message-State: AOJu0Yxv6QJMjgewqPBg2d8W4V8JPFkeol1HqCir22gXlYC7kZbt94uD bjMBRBcSZZnviwO/Y6rQGnUJh013XiyWFBZSmvX61BJWe6+SG/nT X-Google-Smtp-Source: AGHT+IG7sTNeOq1FyXcTJujPnZ6M3LLt7Myn6lJ0H7Loy57Cj8Xn7PcTyf5bQJZ/4DMgLL7vqLnTfw== X-Received: by 2002:a05:600c:4f14:b0:416:6a36:147d with SMTP id l20-20020a05600c4f1400b004166a36147dmr3074206wmq.6.1712617442833; Mon, 08 Apr 2024 16:04:02 -0700 (PDT) Received: from smtpclient.apple (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.googlemail.com with ESMTPSA id o6-20020a05600c4fc600b0041663450a4asm6432708wmq.45.2024.04.08.16.04.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Apr 2024 16:04:02 -0700 (PDT) From: Iain Sandoe Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.8\)) Subject: [PATCH/RFC] On the use of -funreachable-traps to deal with PR 109627 Message-Id: <56A9A5FB-8294-47CB-A6C4-22FD5561C71A@googlemail.com> Date: Tue, 9 Apr 2024 00:04:01 +0100 Cc: GCC Patches , Jakub Jelinek To: Jason Merrill X-Mailer: Apple Mail (2.3696.120.41.1.8) X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_NUMSUBJECT,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 List-Id: 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=E2=80=99ve 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=3D__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=3Dundefined -fsanitise-traps (not yet clear if that=E2=80=99s = expected or we=E2=80=99ve 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 (); } =20 @@ -10442,7 +10443,7 @@ fold_builtin_0 (location_t loc, tree fndecl) =20 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; =20 =3D=3D=3D=3D=