From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3B5B03858017; Fri, 29 Oct 2021 22:57:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B5B03858017 From: "andrew.cooper3 at citrix dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/102953] Improvements to CET-IBT and ENDBR generation Date: Fri, 29 Oct 2021 22:57:28 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: andrew.cooper3 at citrix dot com X-Bugzilla-Status: WAITING X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: hjl.tools at gmail dot com X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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: Fri, 29 Oct 2021 22:57:29 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102953 --- Comment #17 from Andrew Cooper --- I think I've found a bug in the -fcf-check-attribute implementation. $ cat fnptr-array-arg.c static int __attribute__((cf_check)) foo(char a[], int b) { return 0; } int (*ptr)(char[], int) =3D foo; $ gcc -Wall -fcf-protection=3Dbranch -mmanual-endbr -fcf-check-attribute= =3Dno -c fnptr-array-arg.c -o tmp.o && objdump -d tmp.o fnptr-array-arg.c:5:27: warning: initialization of 'int (*)(char *, int)' from incompatible pointer type 'int (__attribute__((nocf_check)) *)(char *, int)' [-Wincompatible-pointer-types] 5 | int (*ptr)(char[], int) =3D foo; | ^~~ tmp.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 : 0: 31 c0 xor %eax,%eax 2: c3 retq=20=20=20 Despite the explicit cf_check, a diagnostic is raised complaining about cf_check-ness of the pointer, and the generated code has no `endbr64` instruction. This issue only manifests when using array arguments in the function. When switching `char[]` for `char*`, everything works as expected. Also, droppi= ng -fcf-check-attribute=3Dno also causes things to work. $ gcc -Wall -fcf-protection=3Dbranch -mmanual-endbr -c fnptr-array-arg.c = -o tmp.o && objdump -d tmp.o tmp.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 : 0: f3 0f 1e fa endbr64=20 4: 31 c0 xor %eax,%eax 6: c3 retq=20=20=20 Something about the array type seems to cause the explicit cf_check attribu= te to be lost.=