From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 09FF2385801D; Sun, 8 Nov 2020 00:53:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09FF2385801D From: "martingalvan at sourceware dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libgcc/97754] New: arm/lib1funcs.S (RETLDM): CFI may be incorrect Date: Sun, 08 Nov 2020 00:53:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libgcc X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: martingalvan at sourceware 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: Sun, 08 Nov 2020 00:53:35 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97754 Bug ID: 97754 Summary: arm/lib1funcs.S (RETLDM): CFI may be incorrect Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libgcc Assignee: unassigned at gcc dot gnu.org Reporter: martingalvan at sourceware dot org Target Milestone: --- Hi all, I'm looking at the RETLDM macro for the ARM libgcc code: .macro RETLDM regs=3D, cond=3D, unwind=3D, dirn=3Dia #if defined (__INTERWORKING__) .ifc "\regs","" ldr\cond lr, [sp], #8 .else # if defined(__thumb2__) pop\cond {\regs, lr} # else ldm\cond\dirn sp!, {\regs, lr} # endif .endif .ifnc "\unwind", "" /* Mark LR as restored. */ 97: cfi_pop 97b - \unwind, 0xe, 0x0 .endif bx\cond lr #else <...> .endm Here we can see that for the __INTERWORKING__ case, some CFI data is emitte= d if we have an 'unwind' argument. However, I believe this may be wrong if a RET= LDM macro appears in the middle of another function. For the __INTERWORKING__ c= ase, the resulting output would be e.g: pop {r4, r5, lr} cfi_pop <...> bx lr Here, 'cfi_pop' would affect the rest of the function unless the caller is careful enough to restore the CFI status for lr after doing RETLDM. This can happen e.g. if we pass a 'cond' argument, which means the branch may not be taken. Unless I'm mistaken, the way to fix this would be to introduce a couple of .cfi_remember/restore_state directives: .ifnc "\unwind", "" /* Mark LR as restored. */ .cfi_remember_state 97: cfi_pop 97b - \unwind, 0xe, 0x0 .endif bx\cond lr .ifnc "\unwind", "" .cfi_restore_state .endif If this is correct, I'll send in a patch to add this change. Speaking of this file, I have a couple more questions: 1. The file is defining macros like cfi_start, cfi_push, etc which insert t= he CFI data directly in binary form. Why can't we use gas' .cfi_* directives a= s we do elsewhere? If we can, I'll send a separate patch to add this change as w= ell. 2. Why is the __INTERWORKING__ macro only defined for ARMv4t? I'm not saying that this is wrong, just curious. Thanks.=