From: Richard Biener <richard.guenther@gmail.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: "H.J. Lu" <hjl.tools@gmail.com>, Hongtao Liu <crazylht@gmail.com>,
Uros Bizjak <ubizjak@gmail.com>, Jan Hubicka <jh@suse.cz>,
gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] i386: Guard noreturn no-callee-saved-registers optimization with -mnoreturn-no-callee-saved-registers [PR38534]
Date: Thu, 29 Feb 2024 14:24:34 +0100 [thread overview]
Message-ID: <CAFiYyc0J=OPirRN3-jEoCEFme0ZRkms_2uf708mv353LO5=xNA@mail.gmail.com> (raw)
In-Reply-To: <ZeB8382hbTMsx38t@tucnak>
On Thu, Feb 29, 2024 at 1:47 PM Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Thu, Feb 29, 2024 at 04:26:00AM -0800, H.J. Lu wrote:
> > > > Adding Hongtao and Honza into the loop as the ones who acked the original
> > > > patch.
> > > >
> > > > The no_callee_saved_registers by default for noreturn functions change can
> > > > break in-process backtrace(3) or backtraces from debugger or other process
> > > > (quite often, any time the noreturn function decides to use the bp register
> > > > and any of the parent frames uses a frame pointer; the unwinder just crashes
> > > > in the libgcc unwinder case, gdb prints stack corrupted message), so I'd
> > > > like to save bp register in that case:
> > > >
> > > > https://gcc.gnu.org/pipermail/gcc-patches/2024-February/646591.html
> > > I think this patch makes sense and LGTM, we save and restore frame
> > > pointer for noreturn.
> > > >
> > > > and additionally the no_callee_saved_registers by default for noreturn
> > > > functions change can make debugging harder, again not localized to the
> > > > noreturn function, but any of its callers. So, if say glibc abort function
> > > > implementation needs a lot of normally callee-saved registers, no matter how
> > > > users recompile their apps, they will see garbage or optimized out
> > > > vars/parameters in their code unless they rebuild their glibc with -O0.
> > > > So, I think we should guard that by a non-default option:
> > > >
> > > > https://gcc.gnu.org/pipermail/gcc-patches/2024-February/646649.html
> > > So it turns off the optimization for noreturn functions by default,
> > > I'm not sure about this.
> > > Any comments, H.J?
> >
> > We need BP for backtrace. I don't think we need to save other
> > registers. True, GDB may not see function parameters. But
> > optimization always has this impact. When I need to debug a
> > program, I always use -O0 or -Og.
>
> The problem is that it doesn't help in this case.
> If some optimization makes debugging of some function harder, normally it is
> enough to recompile the translation unit that defines it with -O0/-Og, or
> add optimize attribute on the function.
> While in this case, the optimization interferes with debugging of other
> functions, not necessarily from the same translation unit, not necessarily
> even from the same library or binary, or even from the same package.
> As I tried to explain, supposedly glibc abort is compiled with -O2 and needs
> a lot of registers, so say it uses all of %rbx, %rbp, %r12, %r13, %r14,
> %r15 and this optimization is applied on it. That means debugging of any
> application (-O2, -Og or even -O0 compiled) to understand what went wrong
> and why it aborted will be harder. Including core file analysis.
> Recompiling those apps with -O0/-Og will not help. The only thing that
> would help is to recompile glibc with -O0/-Og.
> Doesn't have to be abort, doesn't have to be glibc. Any library which
> exports some noreturn APIs may be affected.
> And there is not even a workaround other than to recompile with -O0/-Og the
> noreturn functions, no way to disable this optimization.
>
> Given that most users just will not be aware of this, even adding the option
> but defaulting to on would mean a problem for a lot of users. Most of them
> will not know the problem is that some noreturn function 10 frames deep in
> the call stack was optimized this way.
>
> If people only call the noreturn functions from within the same package,
> for some strange reason care about performance of noreturn functions (they
> don't return, so unless you longjmp out of them or something similar
> which is costly on its own already, they should be entered exactly once)
> and are willing to pay the price in worse debugging in that case, let them
> use the option. But if they provide libraries that other packages then
> consume, I'd say it wouldn't be a good idea.
+1
I'll definitely patch this by-default behavior out if we as upstream keep it.
Debugging customer core dumps is more important than optimizing
glibc abort/assert.
I do hope such patch will be at least easy, like flipping the default of an
option.
Richard.
> Jakub
>
next prev parent reply other threads:[~2024-02-29 13:24 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-27 8:40 [PATCH] i386: For noreturn functions save at least the bp register if it is used [PR114116] Jakub Jelinek
2024-02-27 8:54 ` Richard Biener
2024-02-27 9:04 ` Jakub Jelinek
2024-02-27 9:13 ` Jakub Jelinek
2024-02-27 9:50 ` Richard Biener
2024-02-27 9:55 ` Jakub Jelinek
2024-02-27 12:09 ` Jakub Jelinek
2024-02-27 14:57 ` [PATCH] i386: Guard noreturn no-callee-saved-registers optimization with -mnoreturn-no-callee-saved-registers [PR38534] Jakub Jelinek
2024-02-28 8:00 ` Jakub Jelinek
2024-02-28 8:53 ` Jakub Jelinek
2024-02-29 6:20 ` Hongtao Liu
2024-02-29 12:26 ` H.J. Lu
2024-02-29 12:47 ` Jakub Jelinek
2024-02-29 13:24 ` Richard Biener [this message]
2024-02-29 13:31 ` Jan Hubicka
2024-02-29 13:56 ` Jakub Jelinek
2024-02-29 14:15 ` Jan Hubicka
2024-02-29 14:28 ` H.J. Lu
2024-02-29 15:10 ` Jakub Jelinek
2024-02-29 15:26 ` Jan Hubicka
2024-03-05 4:52 ` Hongtao Liu
2024-02-29 16:25 ` [PATCH] i386: For noreturn functions save at least the bp register if it is used [PR114116] Michael Matz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAFiYyc0J=OPirRN3-jEoCEFme0ZRkms_2uf708mv353LO5=xNA@mail.gmail.com' \
--to=richard.guenther@gmail.com \
--cc=crazylht@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=hjl.tools@gmail.com \
--cc=jakub@redhat.com \
--cc=jh@suse.cz \
--cc=ubizjak@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).