From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 67E343858D39; Fri, 31 Dec 2021 20:48:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 67E343858D39 From: "krystalgamer at protonmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/103882] Register corruption in ASM only functions when optization is -O2/-Os/-O3 Date: Fri, 31 Dec 2021 20:48:50 +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: 10.3.0 X-Bugzilla-Keywords: inline-asm X-Bugzilla-Severity: normal X-Bugzilla-Who: krystalgamer at protonmail dot com 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_status resolution 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, 31 Dec 2021 20:48:50 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103882 Jose Silva changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |UNCONFIRMED Resolution|INVALID |--- --- Comment #2 from Jose Silva --- Marking as noinline does not help. See the generated code: ``` 0040014c : 40014c: 27bdffe0 addiu sp,sp,-32 400150: afbf001c sw ra,28(sp) 400154: 0c100050 jal 400140 400158: 00000000 nop 40015c: 80820000 lb v0,0(a0) 400160: 8fbf001c lw ra,28(sp) 400164: 27bd0020 addiu sp,sp,32 400168: 38420061 xori v0,v0,0x61 40016c: 03e00008 jr ra 400170: 2c420001 sltiu v0,v0,1 ``` The marking as a clobbered does work, but it doesn't fix the underlying iss= ue. On my original code I had a `syscall`, which passes the code execution to t= he kernel that I have no control over or know the full implementation. The specific syscall was overwriting the $a0 register which I simplified in= my example. GCC when -O2 is enabled is making too strong assumptions about the code. To better illustrate the issue, let me give another example. If I call a funct= ion via a function pointer regardless of the optimization level, GCC will save = all caller-saved registers in use. But when it encounters an ASM statement it treats it like it doesn't exist. In my opinion, the same assumptions made w= hen calling from a function pointer should apply when calling a function with inline-asm*. * Manually indicating the clobbered registers could override this behaviour=