* [debug/88006] -fdebug-types-section gives undefined ref
@ 2018-11-14 11:58 Nathan Sidwell
2018-11-14 12:34 ` Richard Biener
0 siblings, 1 reply; 4+ messages in thread
From: Nathan Sidwell @ 2018-11-14 11:58 UTC (permalink / raw)
To: GCC Patches, Richard Biener
[-- Attachment #1: Type: text/plain, Size: 1216 bytes --]
PR88006 and 87462 turn out to be the same problem, but started by
different commits.
The problem is that debug wants to emit a constant (for a non-type
template parameter of a template instantiation) that refers to the
address of some local function. That local might not be emitted though.
gen_remaining_tmpl_value_param_die_attribute is aware of the problem:
/* We do this in two phases - first get the cases we can
handle during early-finish, preserving those we cannot
(containing symbolic constants where we don't yet know
whether we are going to output the referenced symbols).
For those we try again at late-finish. */
But the second phase unconditionally emits the constant:
if (! early_dwarf
&& (dwarf_version >= 5 || !dwarf_strict))
loc = loc_descriptor_from_tree (e->arg, 2, NULL);
and loc_descriptor_from_tree eventually ends up in
const_ok_for_output_1. That function assumes pretty much any non
SYMBOL_REF_EXTERNAL_P SYMBOL_REF is accessible. That's not true.
I'm not sure if there's a more canonical way of checking for a
local-decl's emission, but not having a symtab entry seems significant?
booted & tested on x86_64-linux, ok?
nathan
--
Nathan Sidwell
[-- Attachment #2: pr88006.diff --]
[-- Type: text/x-patch, Size: 3768 bytes --]
2018-11-14 Nathan Sidwell <nathan@acm.org>
PR debug/88006
PR debug/87462
* dwarf2out.c (const_ok_for_output_1): Check symtab for internal
decls.
* g++.dg/debug/dwarf2/pr87462.C: New.
* g++.dg/debug/dwarf2/pr88006.C: New.
Index: dwarf2out.c
===================================================================
--- dwarf2out.c (revision 266082)
+++ dwarf2out.c (working copy)
@@ -14480,13 +14472,15 @@ const_ok_for_output_1 (rtx rtl)
if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
return false;
- /* Avoid references to external symbols in debug info, on several targets
- the linker might even refuse to link when linking a shared library,
- and in many other cases the relocations for .debug_info/.debug_loc are
- dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
- to be defined within the same shared library or executable are fine. */
if (SYMBOL_REF_EXTERNAL_P (rtl))
{
+ /* Avoid references to external symbols in debug info, on
+ several targets the linker might even refuse to link when
+ linking a shared library, and in many other cases the
+ relocations for .debug_info/.debug_loc are dropped, so the
+ address becomes zero anyway. Hidden symbols, guaranteed to
+ be defined within the same shared library or executable are
+ fine. */
tree decl = SYMBOL_REF_DECL (rtl);
if (decl == NULL || !targetm.binds_local_p (decl))
@@ -14496,6 +14490,18 @@ const_ok_for_output_1 (rtx rtl)
return false;
}
}
+ else
+ {
+ /* Internal decls are not necessarily emitted -- they could be
+ inlined or whatever. */
+ if (tree decl = SYMBOL_REF_DECL (rtl))
+ if (!symtab_node::get (decl))
+ {
+ expansion_failed (NULL_TREE, rtl,
+ "Symbol not emitted in current TU.\n");
+ return false;
+ }
+ }
return true;
}
Index: testsuite/g++.dg/debug/dwarf2/pr87462.C
===================================================================
--- testsuite/g++.dg/debug/dwarf2/pr87462.C (revision 0)
+++ testsuite/g++.dg/debug/dwarf2/pr87462.C (working copy)
@@ -0,0 +1,20 @@
+// { dg-additional-options "-dA -std=gnu++17 -gdwarf-4 -O1 -fdebug-types-section" }
+// reject .pseudo label, but "label" is ok.
+// { dg-final { scan-assembler-not "\[^L\"\]_ZN5Test18testFuncEv" } }
+// undefined ref to _ZN5Test18testFuncEv
+
+class Test1 {
+public:
+ static int testFunc() { return 1; }
+};
+
+template <typename T,
+ T (*funcImpl)()>
+class TestWrapper {
+public:
+ static T func() __attribute((noinline)) { return (*funcImpl)(); }
+};
+
+int main() {
+ return TestWrapper<int, &Test1::testFunc>::func();
+}
Index: testsuite/g++.dg/debug/dwarf2/pr88006.C
===================================================================
--- testsuite/g++.dg/debug/dwarf2/pr88006.C (revision 0)
+++ testsuite/g++.dg/debug/dwarf2/pr88006.C (working copy)
@@ -0,0 +1,39 @@
+// { dg-additional-options "-dA -std=gnu++17 -gdwarf-4 -O1 -fdebug-types-section" }
+// reject .pseudo label, but "label" is ok.
+// { dg-final { scan-assembler-not "\[^\"\]_ZN3Foo4mfunEv" } }
+// undefined ref to _ZN3Foo4mfunEv
+
+struct Foo {
+ void mfun () {}
+};
+
+struct A { static constexpr bool Value = false; };
+
+template <bool> struct B { typedef int Type; };
+
+class Arg
+{
+ template <typename Unused> struct Local : A {};
+
+public:
+ template <typename Init, typename = typename B<Local<Init>::Value>::Type>
+ Arg (Init) {}
+};
+
+class Lambda {
+ static constexpr int Unused = 0;
+
+public:
+ Lambda (Arg);
+};
+
+// Generated ref to Foo::mfun in the type die of an instantiation of this
+template <void (Foo::*unused)()> struct Callable {};
+
+class I {
+ I() : lamb ([this] {}) {}
+
+ Lambda lamb;
+
+ Callable<&Foo::mfun> bm;
+};
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [debug/88006] -fdebug-types-section gives undefined ref
2018-11-14 11:58 [debug/88006] -fdebug-types-section gives undefined ref Nathan Sidwell
@ 2018-11-14 12:34 ` Richard Biener
2018-11-14 15:08 ` Nathan Sidwell
0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2018-11-14 12:34 UTC (permalink / raw)
To: Nathan Sidwell; +Cc: GCC Patches
On Wed, Nov 14, 2018 at 12:58 PM Nathan Sidwell <nathan@acm.org> wrote:
>
> PR88006 and 87462 turn out to be the same problem, but started by
> different commits.
>
> The problem is that debug wants to emit a constant (for a non-type
> template parameter of a template instantiation) that refers to the
> address of some local function. That local might not be emitted though.
>
> gen_remaining_tmpl_value_param_die_attribute is aware of the problem:
> /* We do this in two phases - first get the cases we can
> handle during early-finish, preserving those we cannot
> (containing symbolic constants where we don't yet know
> whether we are going to output the referenced symbols).
> For those we try again at late-finish. */
>
> But the second phase unconditionally emits the constant:
> if (! early_dwarf
> && (dwarf_version >= 5 || !dwarf_strict))
> loc = loc_descriptor_from_tree (e->arg, 2, NULL);
>
> and loc_descriptor_from_tree eventually ends up in
> const_ok_for_output_1. That function assumes pretty much any non
> SYMBOL_REF_EXTERNAL_P SYMBOL_REF is accessible. That's not true.
>
> I'm not sure if there's a more canonical way of checking for a
> local-decl's emission, but not having a symtab entry seems significant?
>
> booted & tested on x86_64-linux, ok?
Hmm, there is reference_to_unused () used in a related case. But generally
for late emission such references are "OK" and expected to be pruned
later by resolve_addr () (which I see we do not call for type units?!). Quote:
/* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
an address in .rodata section if the string literal is emitted there,
or remove the containing location list or replace DW_AT_const_value
with DW_AT_location and empty location expression, if it isn't found
in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
to something that has been emitted in the current CU. */
static void
resolve_addr (dw_die_ref die)
{
Richard.
>
> nathan
>
> --
> Nathan Sidwell
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [debug/88006] -fdebug-types-section gives undefined ref
2018-11-14 12:34 ` Richard Biener
@ 2018-11-14 15:08 ` Nathan Sidwell
2018-11-14 18:40 ` Jeff Law
0 siblings, 1 reply; 4+ messages in thread
From: Nathan Sidwell @ 2018-11-14 15:08 UTC (permalink / raw)
To: Richard Biener; +Cc: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 876 bytes --]
On 11/14/18 7:33 AM, Richard Biener wrote:
> Hmm, there is reference_to_unused () used in a related case. But generally
> for late emission such references are "OK" and expected to be pruned
> later by resolve_addr () (which I see we do not call for type units?!). Quote:
>
> /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
> an address in .rodata section if the string literal is emitted there,
> or remove the containing location list or replace DW_AT_const_value
> with DW_AT_location and empty location expression, if it isn't found
> in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
> to something that has been emitted in the current CU. */
>
> static void
> resolve_addr (dw_die_ref die)
> {
That does seem to work. The attached survise bootstrapping on
x86_64-linux, ok?
nathan
--
Nathan Sidwell
[-- Attachment #2: pr88006-2.diff --]
[-- Type: text/x-patch, Size: 2604 bytes --]
2018-11-14 Nathan Sidwell <nathan@acm.org>
PR debug/88006
PR debug/87462
* dwarf2out.c (dwarf2out_finish): Apply resolve_addr to comdat
type list.
* g++.dg/debug/dwarf2/pr87462.C: New.
* g++.dg/debug/dwarf2/pr88006.C: New.
Index: dwarf2out.c
===================================================================
--- dwarf2out.c (revision 266082)
+++ dwarf2out.c (working copy)
@@ -31182,6 +31182,8 @@ dwarf2out_finish (const char *filename)
FOR_EACH_CHILD (die, c, gcc_assert (! c->die_mark));
}
#endif
+ for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
+ resolve_addr (ctnode->root_die);
resolve_addr (comp_unit_die ());
move_marked_base_types ();
Index: testsuite/g++.dg/debug/dwarf2/pr87462.C
===================================================================
--- testsuite/g++.dg/debug/dwarf2/pr87462.C (revision 0)
+++ testsuite/g++.dg/debug/dwarf2/pr87462.C (working copy)
@@ -0,0 +1,20 @@
+// { dg-additional-options "-dA -std=gnu++17 -gdwarf-4 -O1 -fdebug-types-section" }
+// reject .pseudo label, but "label" is ok.
+// { dg-final { scan-assembler-not "\[^L\"\]_ZN5Test18testFuncEv" } }
+// undefined ref to _ZN5Test18testFuncEv
+
+class Test1 {
+public:
+ static int testFunc() { return 1; }
+};
+
+template <typename T,
+ T (*funcImpl)()>
+class TestWrapper {
+public:
+ static T func() __attribute((noinline)) { return (*funcImpl)(); }
+};
+
+int main() {
+ return TestWrapper<int, &Test1::testFunc>::func();
+}
Index: testsuite/g++.dg/debug/dwarf2/pr88006.C
===================================================================
--- testsuite/g++.dg/debug/dwarf2/pr88006.C (revision 0)
+++ testsuite/g++.dg/debug/dwarf2/pr88006.C (working copy)
@@ -0,0 +1,39 @@
+// { dg-additional-options "-dA -std=gnu++17 -gdwarf-4 -O1 -fdebug-types-section" }
+// reject .pseudo label, but "label" is ok.
+// { dg-final { scan-assembler-not "\[^\"\]_ZN3Foo4mfunEv" } }
+// undefined ref to _ZN3Foo4mfunEv
+
+struct Foo {
+ void mfun () {}
+};
+
+struct A { static constexpr bool Value = false; };
+
+template <bool> struct B { typedef int Type; };
+
+class Arg
+{
+ template <typename Unused> struct Local : A {};
+
+public:
+ template <typename Init, typename = typename B<Local<Init>::Value>::Type>
+ Arg (Init) {}
+};
+
+class Lambda {
+ static constexpr int Unused = 0;
+
+public:
+ Lambda (Arg);
+};
+
+// Generated ref to Foo::mfun in the type die of an instantiation of this
+template <void (Foo::*unused)()> struct Callable {};
+
+class I {
+ I() : lamb ([this] {}) {}
+
+ Lambda lamb;
+
+ Callable<&Foo::mfun> bm;
+};
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [debug/88006] -fdebug-types-section gives undefined ref
2018-11-14 15:08 ` Nathan Sidwell
@ 2018-11-14 18:40 ` Jeff Law
0 siblings, 0 replies; 4+ messages in thread
From: Jeff Law @ 2018-11-14 18:40 UTC (permalink / raw)
To: Nathan Sidwell, Richard Biener; +Cc: GCC Patches
On 11/14/18 8:08 AM, Nathan Sidwell wrote:
> On 11/14/18 7:33 AM, Richard Biener wrote:
>
>> Hmm, there is reference_to_unused () used in a related case.  But generally
>>
>> for late emission such references are "OK" and expected to be pruned
>> later by resolve_addr () (which I see we do not call for type units?!).  Quote:
>>
>>
>> /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
>>     an address in .rodata section if the string literal is emitted there,
>>     or remove the containing location list or replace DW_AT_const_value
>>     with DW_AT_location and empty location expression, if it isn't found
>>     in .rodata.  Similarly for SYMBOL_REFs, keep only those that refer
>>     to something that has been emitted in the current CU.  */
>>
>> static void
>> resolve_addr (dw_die_ref die)
>> {
>
> That does seem to work. The attached survise bootstrapping on
> x86_64-linux, ok?
>
> nathan
>
> --Â
> Nathan Sidwell
>
> pr88006-2.diff
>
> 2018-11-14 Nathan Sidwell <nathan@acm.org>
>
> PR debug/88006
> PR debug/87462
> * dwarf2out.c (dwarf2out_finish): Apply resolve_addr to comdat
> type list.
>
> * g++.dg/debug/dwarf2/pr87462.C: New.
> * g++.dg/debug/dwarf2/pr88006.C: New.
OK
jeff
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-11-14 18:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-14 11:58 [debug/88006] -fdebug-types-section gives undefined ref Nathan Sidwell
2018-11-14 12:34 ` Richard Biener
2018-11-14 15:08 ` Nathan Sidwell
2018-11-14 18:40 ` 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).