public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/100908] New: asan clobberes register asm variables
@ 2021-06-04 17:57 krebbel at gcc dot gnu.org
  2021-06-04 18:11 ` [Bug middle-end/100908] " krebbel at gcc dot gnu.org
  2021-06-04 18:25 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: krebbel at gcc dot gnu.org @ 2021-06-04 17:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100908

            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=50933&action=edit
Testcase

Compiling the testcase with either:
gcc -O3 t1.c -o t -fsanitize=address --param
asan-instrumentation-with-call-threshold=0
or
gcc -O3 t1.c -o t -fsanitize=kernel-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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/100908] asan clobberes register asm variables
  2021-06-04 17:57 [Bug middle-end/100908] New: asan clobberes register asm variables krebbel at gcc dot gnu.org
@ 2021-06-04 18:11 ` krebbel at gcc dot gnu.org
  2021-06-04 18:25 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: krebbel at gcc dot gnu.org @ 2021-06-04 18:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100908

--- Comment #1 from Andreas Krebbel <krebbel at gcc dot gnu.org> ---
https://gcc.gnu.org/pipermail/gcc/2021-June/236269.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/100908] asan clobberes register asm variables
  2021-06-04 17:57 [Bug middle-end/100908] New: asan clobberes register asm variables krebbel at gcc dot gnu.org
  2021-06-04 18:11 ` [Bug middle-end/100908] " krebbel at gcc dot gnu.org
@ 2021-06-04 18:25 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-04 18:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100908

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andreas Krebbel from comment #1)
> https://gcc.gnu.org/pipermail/gcc/2021-June/236269.html

Yes this will help solve the limitations which are already mentioned in the
manual:
Warning: In the above example, be aware that a register (for example r0) can be
call-clobbered by subsequent code, including function calls and library calls
for arithmetic operators on other variables (for example the initialization of
p2). In this case, use temporary variables for expressions between the register
assignments:

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-04 18:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-04 17:57 [Bug middle-end/100908] New: asan clobberes register asm variables krebbel at gcc dot gnu.org
2021-06-04 18:11 ` [Bug middle-end/100908] " krebbel at gcc dot gnu.org
2021-06-04 18:25 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).