* [PATCH] debug/108772 - ICE with late debug generated with -flto
@ 2023-03-01 13:07 Richard Biener
0 siblings, 0 replies; 6+ messages in thread
From: Richard Biener @ 2023-03-01 13:07 UTC (permalink / raw)
To: gcc-patches; +Cc: Jakub Jelinek, jason
When combining -g1 with -flto we run into the DIE location annotation
machinery for globals calling dwarf2out_late_global_decl but not
having any early generated DIE for function scope statics. In
this process we'd generate a limbo DIE since also the function scope
doesn't have any early generated DIE. The limbo handling then tries
to force a DIE for the context chain which ultimatively fails and
ICEs at the std namespace decl because at -g1 we don't represent that.
The following avoids this situation by making sure to never generate
any limbo DIEs from dwarf2out_late_global_decl in the in_lto_p path
but instead for function scope globals rely on DIE generation for
the function to output a DIE for the local static (which doesn't
happen for -g1).
I explored a lot of other options to fix this but in the end this
seems to be the most spot-on fix with the least risk of unwanted
effects.
LTO bootstrapped on x86_64-unknown-linux-gnu (running into PR108984),
bootstrapped and tested on x86_64-unknown-linux-gnu.
OK?
Thanks,
Richard.
PR debug/108772
* dwarf2out.cc (dwarf2out_late_global_decl): Do not
generate a DIE for a function scope static when we do
not have a DIE for the function already.
* g++.dg/lto/pr108772_0.C: New testcase.
---
gcc/dwarf2out.cc | 12 ++++++-
gcc/testsuite/g++.dg/lto/pr108772_0.C | 46 +++++++++++++++++++++++++++
2 files changed, 57 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/lto/pr108772_0.C
diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 1f39df3b1e2..6f457ed4472 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -27283,7 +27283,17 @@ dwarf2out_late_global_decl (tree decl)
was not enabled at compile-time or the target doesn't support
the LTO early debug scheme. */
if (! die && in_lto_p)
- dwarf2out_decl (decl);
+ {
+ /* Avoid relying on the ability to force context DIEs for
+ local entities. Instead if the function context was not
+ instantiated yet defer to it producing its local DIEs.
+ See PR108772. */
+ dw_die_ref context_die = comp_unit_die ();
+ if (local_function_static (decl))
+ context_die = lookup_decl_die (DECL_CONTEXT (decl));
+ if (context_die)
+ dwarf2out_decl (decl);
+ }
else if (die)
{
/* We get called via the symtab code invoking late_global_decl
diff --git a/gcc/testsuite/g++.dg/lto/pr108772_0.C b/gcc/testsuite/g++.dg/lto/pr108772_0.C
new file mode 100644
index 00000000000..81f15a90a3e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/pr108772_0.C
@@ -0,0 +1,46 @@
+// { dg-lto-do link }
+// { dg-require-effective-target shared }
+// { dg-require-effective-target fpic }
+// { dg-lto-options { "-flto -fPIC -shared -O1 -fimplicit-constexpr -g1" } }
+// { dg-extra-ld-options "-shared" }
+
+namespace std {
+struct _Sp_counted_base {
+ virtual void *_M_get_deleter(const int &);
+};
+bool _S_eq(int);
+struct _Sp_make_shared_tag {
+ static const int &_S_ti() {
+ static constexpr char __tag{};
+ return reinterpret_cast<const int &>(__tag);
+ }
+};
+struct _Impl {
+ _Impl(int);
+};
+int _Sp_counted_ptr_inplace___a;
+struct _Sp_counted_ptr_inplace : _Sp_counted_base {
+ _Sp_counted_ptr_inplace() : _M_impl(_Sp_counted_ptr_inplace___a) {}
+ void *_M_get_deleter(const int &__ti) {
+ auto __ptr(_M_ptr());
+ &__ti == &_Sp_make_shared_tag::_S_ti() || _S_eq(__ti);
+ return __ptr;
+ }
+ int *_M_ptr();
+ _Impl _M_impl;
+};
+struct __shared_count {
+ __shared_count(int, int) { _Sp_counted_ptr_inplace(); }
+};
+int _M_ptr;
+struct __shared_ptr {
+ template <typename _Alloc>
+ __shared_ptr(_Alloc __tag) : _M_refcount(_M_ptr, __tag) {}
+ __shared_count _M_refcount;
+};
+int shared_ptr___tag;
+struct shared_ptr : __shared_ptr {
+ shared_ptr() : __shared_ptr(shared_ptr___tag) {}
+};
+void ArgEq() { shared_ptr(); }
+} // namespace std
--
2.35.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] debug/108772 - ICE with late debug generated with -flto
[not found] <20230301130718.E51473858C62@sourceware.org>
@ 2023-03-11 20:08 ` Jeff Law
0 siblings, 0 replies; 6+ messages in thread
From: Jeff Law @ 2023-03-11 20:08 UTC (permalink / raw)
To: Richard Biener, gcc-patches; +Cc: Jakub Jelinek, jason
On 3/1/23 06:07, Richard Biener via Gcc-patches wrote:
> When combining -g1 with -flto we run into the DIE location annotation
> machinery for globals calling dwarf2out_late_global_decl but not
> having any early generated DIE for function scope statics. In
> this process we'd generate a limbo DIE since also the function scope
> doesn't have any early generated DIE. The limbo handling then tries
> to force a DIE for the context chain which ultimatively fails and
> ICEs at the std namespace decl because at -g1 we don't represent that.
>
> The following avoids this situation by making sure to never generate
> any limbo DIEs from dwarf2out_late_global_decl in the in_lto_p path
> but instead for function scope globals rely on DIE generation for
> the function to output a DIE for the local static (which doesn't
> happen for -g1).
>
> I explored a lot of other options to fix this but in the end this
> seems to be the most spot-on fix with the least risk of unwanted
> effects.
>
> LTO bootstrapped on x86_64-unknown-linux-gnu (running into PR108984),
> bootstrapped and tested on x86_64-unknown-linux-gnu.
>
> OK?
>
> Thanks,
> Richard.
>
> PR debug/108772
> * dwarf2out.cc (dwarf2out_late_global_decl): Do not
> generate a DIE for a function scope static when we do
> not have a DIE for the function already.
>
> * g++.dg/lto/pr108772_0.C: New testcase.
OK.
jeff
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] debug/108772 - ICE with late debug generated with -flto
2023-03-02 7:43 ` Richard Biener
@ 2023-03-02 13:19 ` Jason Merrill
0 siblings, 0 replies; 6+ messages in thread
From: Jason Merrill @ 2023-03-02 13:19 UTC (permalink / raw)
To: Richard Biener; +Cc: Jakub Jelinek, gcc-patches
On 3/2/23 02:43, Richard Biener wrote:
> On Wed, 1 Mar 2023, Jason Merrill wrote:
>
>> On 3/1/23 08:09, Jakub Jelinek wrote:
>>> On Wed, Mar 01, 2023 at 01:07:02PM +0000, Richard Biener wrote:
>>>> When combining -g1 with -flto we run into the DIE location annotation
>>>> machinery for globals calling dwarf2out_late_global_decl but not
>>>> having any early generated DIE for function scope statics. In
>>>> this process we'd generate a limbo DIE since also the function scope
>>>> doesn't have any early generated DIE. The limbo handling then tries
>>>> to force a DIE for the context chain which ultimatively fails and
>>>> ICEs at the std namespace decl because at -g1 we don't represent that.
>>>>
>>>> The following avoids this situation by making sure to never generate
>>>> any limbo DIEs from dwarf2out_late_global_decl in the in_lto_p path
>>>> but instead for function scope globals rely on DIE generation for
>>>> the function to output a DIE for the local static (which doesn't
>>>> happen for -g1).
>>
>> So the issue is that we're trying to force out a DIE for a decl that we
>> wouldn't have generated without -flto? How is it avoided in the non-LTO case?
>
> When we go rest_of_decl_compilation for this decl we defer to the
> containing function to generate an early DIE but that doesn't
> (because of -g1). The call to late_global_decl that's done by
> assemble_decl then does nothing because there's no early DIE. But with
> -flto we cannot completely rely on early DIE presence (not even without,
> in case of cloning - but we don't clone global variables), esp. because
> there's still the "supported" non-early-LTO path for non-ELF targets.
>
> So at this point it seems to be the best thing to mimic what
> rest_of_decl_compilation does and defer to dwarf2out of the
> containing function to generate the DIE (or not). For the reason
> of the least amount of changes at this point in stage4 I went for
> querying the DECL_CONTEXT DIE instead of right-out not handling
> local_function_static () decls in this path.
>
> If you'd prefer that, so
>
> if (! die && in_lto_p
> /* Function scope variables are emitted when emitting the
> DIE for the function. */
> && ! local_function_static (decl))
> dwarf2out_decl (decl);
>
> then I can test that variant as well which feels a bit more
> consistent.
That variant is OK, thanks.
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] debug/108772 - ICE with late debug generated with -flto
2023-03-01 20:11 ` Jason Merrill
@ 2023-03-02 7:43 ` Richard Biener
2023-03-02 13:19 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Richard Biener @ 2023-03-02 7:43 UTC (permalink / raw)
To: Jason Merrill; +Cc: Jakub Jelinek, gcc-patches
On Wed, 1 Mar 2023, Jason Merrill wrote:
> On 3/1/23 08:09, Jakub Jelinek wrote:
> > On Wed, Mar 01, 2023 at 01:07:02PM +0000, Richard Biener wrote:
> >> When combining -g1 with -flto we run into the DIE location annotation
> >> machinery for globals calling dwarf2out_late_global_decl but not
> >> having any early generated DIE for function scope statics. In
> >> this process we'd generate a limbo DIE since also the function scope
> >> doesn't have any early generated DIE. The limbo handling then tries
> >> to force a DIE for the context chain which ultimatively fails and
> >> ICEs at the std namespace decl because at -g1 we don't represent that.
> >>
> >> The following avoids this situation by making sure to never generate
> >> any limbo DIEs from dwarf2out_late_global_decl in the in_lto_p path
> >> but instead for function scope globals rely on DIE generation for
> >> the function to output a DIE for the local static (which doesn't
> >> happen for -g1).
>
> So the issue is that we're trying to force out a DIE for a decl that we
> wouldn't have generated without -flto? How is it avoided in the non-LTO case?
When we go rest_of_decl_compilation for this decl we defer to the
containing function to generate an early DIE but that doesn't
(because of -g1). The call to late_global_decl that's done by
assemble_decl then does nothing because there's no early DIE. But with
-flto we cannot completely rely on early DIE presence (not even without,
in case of cloning - but we don't clone global variables), esp. because
there's still the "supported" non-early-LTO path for non-ELF targets.
So at this point it seems to be the best thing to mimic what
rest_of_decl_compilation does and defer to dwarf2out of the
containing function to generate the DIE (or not). For the reason
of the least amount of changes at this point in stage4 I went for
querying the DECL_CONTEXT DIE instead of right-out not handling
local_function_static () decls in this path.
If you'd prefer that, so
if (! die && in_lto_p
/* Function scope variables are emitted when emitting the
DIE for the function. */
&& ! local_function_static (decl))
dwarf2out_decl (decl);
then I can test that variant as well which feels a bit more
consistent.
Thanks,
Richard.
> >> I explored a lot of other options to fix this but in the end this
> >> seems to be the most spot-on fix with the least risk of unwanted
> >> effects.
> >>
> >> LTO bootstrapped on x86_64-unknown-linux-gnu (running into PR108984),
> >> bootstrapped and tested on x86_64-unknown-linux-gnu.
> >>
> >> OK?
> >>
> >> Thanks,
> >> Richard.
> >>
> >> PR debug/108772
> >> * dwarf2out.cc (dwarf2out_late_global_decl): Do not
> >> generate a DIE for a function scope static when we do
> >> not have a DIE for the function already.
> >>
> >> * g++.dg/lto/pr108772_0.C: New testcase.
> >
> > LGTM, but please give Jason a day to chime in if he disagrees.
> >
> > Jakub
> >
>
>
>
--
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] debug/108772 - ICE with late debug generated with -flto
2023-03-01 13:09 ` Jakub Jelinek
@ 2023-03-01 20:11 ` Jason Merrill
2023-03-02 7:43 ` Richard Biener
0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2023-03-01 20:11 UTC (permalink / raw)
To: Jakub Jelinek, Richard Biener; +Cc: gcc-patches
On 3/1/23 08:09, Jakub Jelinek wrote:
> On Wed, Mar 01, 2023 at 01:07:02PM +0000, Richard Biener wrote:
>> When combining -g1 with -flto we run into the DIE location annotation
>> machinery for globals calling dwarf2out_late_global_decl but not
>> having any early generated DIE for function scope statics. In
>> this process we'd generate a limbo DIE since also the function scope
>> doesn't have any early generated DIE. The limbo handling then tries
>> to force a DIE for the context chain which ultimatively fails and
>> ICEs at the std namespace decl because at -g1 we don't represent that.
>>
>> The following avoids this situation by making sure to never generate
>> any limbo DIEs from dwarf2out_late_global_decl in the in_lto_p path
>> but instead for function scope globals rely on DIE generation for
>> the function to output a DIE for the local static (which doesn't
>> happen for -g1).
So the issue is that we're trying to force out a DIE for a decl that we
wouldn't have generated without -flto? How is it avoided in the non-LTO
case?
>> I explored a lot of other options to fix this but in the end this
>> seems to be the most spot-on fix with the least risk of unwanted
>> effects.
>>
>> LTO bootstrapped on x86_64-unknown-linux-gnu (running into PR108984),
>> bootstrapped and tested on x86_64-unknown-linux-gnu.
>>
>> OK?
>>
>> Thanks,
>> Richard.
>>
>> PR debug/108772
>> * dwarf2out.cc (dwarf2out_late_global_decl): Do not
>> generate a DIE for a function scope static when we do
>> not have a DIE for the function already.
>>
>> * g++.dg/lto/pr108772_0.C: New testcase.
>
> LGTM, but please give Jason a day to chime in if he disagrees.
>
> Jakub
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] debug/108772 - ICE with late debug generated with -flto
[not found] <01327.123030108070400465@us-mta-295.us.mimecast.lan>
@ 2023-03-01 13:09 ` Jakub Jelinek
2023-03-01 20:11 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2023-03-01 13:09 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches, jason
On Wed, Mar 01, 2023 at 01:07:02PM +0000, Richard Biener wrote:
> When combining -g1 with -flto we run into the DIE location annotation
> machinery for globals calling dwarf2out_late_global_decl but not
> having any early generated DIE for function scope statics. In
> this process we'd generate a limbo DIE since also the function scope
> doesn't have any early generated DIE. The limbo handling then tries
> to force a DIE for the context chain which ultimatively fails and
> ICEs at the std namespace decl because at -g1 we don't represent that.
>
> The following avoids this situation by making sure to never generate
> any limbo DIEs from dwarf2out_late_global_decl in the in_lto_p path
> but instead for function scope globals rely on DIE generation for
> the function to output a DIE for the local static (which doesn't
> happen for -g1).
>
> I explored a lot of other options to fix this but in the end this
> seems to be the most spot-on fix with the least risk of unwanted
> effects.
>
> LTO bootstrapped on x86_64-unknown-linux-gnu (running into PR108984),
> bootstrapped and tested on x86_64-unknown-linux-gnu.
>
> OK?
>
> Thanks,
> Richard.
>
> PR debug/108772
> * dwarf2out.cc (dwarf2out_late_global_decl): Do not
> generate a DIE for a function scope static when we do
> not have a DIE for the function already.
>
> * g++.dg/lto/pr108772_0.C: New testcase.
LGTM, but please give Jason a day to chime in if he disagrees.
Jakub
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-03-11 20:08 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-01 13:07 [PATCH] debug/108772 - ICE with late debug generated with -flto Richard Biener
[not found] <01327.123030108070400465@us-mta-295.us.mimecast.lan>
2023-03-01 13:09 ` Jakub Jelinek
2023-03-01 20:11 ` Jason Merrill
2023-03-02 7:43 ` Richard Biener
2023-03-02 13:19 ` Jason Merrill
[not found] <20230301130718.E51473858C62@sourceware.org>
2023-03-11 20:08 ` Jeff Law
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).