From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0847E3851C27; Fri, 4 Jun 2021 17:57:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0847E3851C27 From: "krebbel at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/100908] New: asan clobberes register asm variables Date: Fri, 04 Jun 2021 17:57:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: krebbel at gcc dot gnu.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 attachments.created 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: Fri, 04 Jun 2021 17:57:35 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100908 Bug ID: 100908 Summary: asan clobberes register asm variables Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: krebbel at gcc dot gnu.org Target Milestone: --- Created attachment 50933 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D50933&action=3Dedit Testcase Compiling the testcase with either: gcc -O3 t1.c -o t -fsanitize=3Daddress --param asan-instrumentation-with-call-threshold=3D0 or gcc -O3 t1.c -o t -fsanitize=3Dkernel-address -lasan aborts because dereferencing y triggers the address sanitizer to introduce a function call. That a function call might clobber registers assigned with register asm is a documented limitation of the register asm construct: https://gcc.gnu.org/onlinedocs/gcc/Local-Register-Variables.html However, in combination with the address sanitizer this becomes even less obvious making even the most experienced kernel developers trip over it: https://lkml.org/lkml/2020/10/23/908 For IBM Z quite a few cases like this have been reported to me. Here just one I could find quickly: https://lore.kernel.org/patchwork/patch/1413907/ Btw. clang appears to handle this more gracefully and preserves the value of the variable around function calls. The attached testcase works fine with clang. I think it would be much better to find a solution which allows to directly name hard registers as inline assembly constraints. I'll post an RFC on the mailing list.=