From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 145FA384B820; Mon, 8 Feb 2021 06:15:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 145FA384B820 From: "luto at kernel dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/98997] New: Linking mismatched -fcf-protection objects generates incorrect code Date: Mon, 08 Feb 2021 06:15:36 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: luto at kernel dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Feb 2021 06:15:37 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98997 Bug ID: 98997 Summary: Linking mismatched -fcf-protection objects generates incorrect code Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: luto at kernel dot org Target Milestone: --- $ gcc --version gcc (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9) Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ cat cet1.c #include void test(jmp_buf buf) { __builtin_longjmp(buf, 1); } $ cat cet2.c #include void test(jmp_buf buf); int main() { jmp_buf buf; if (__builtin_setjmp(buf) =3D=3D 0) test(buf); return 0; } $ gcc -c -O2 cet1.c -fcf-protection=3Dfull $ gcc -c -O2 cet2.c $ gcc -o cet -O2 cet1.o cet2.o $ ./cet Illegal instruction (core dumped) Presumably the magic CET fixup in the builtin setjmp/longjmp requires that matching code is generated for both. I'm testing on a non-CET system. I haven't even tried to figure out if anything sensible happens to the CET = GNU property, but I think the current GCC behavior is impolite at best. I think GCC should do one of a few things: 1. Generate working code. 2. Fail to link. 3. At least document this pitfall very clearly. I really hope this doesn't affect shared objects.=