Hi!

The following testcase fails to assemble, because with -ffunction-sections
and hot/cold partitioning, secname_for_decl returns the same section
for both the hot and cold partition, even when we actually use two different
sections - .text._Z3fooi and .text.unlikely._Z3fooi.  If the secname is
the same, we then try to emit DW_LLE_offset_pair with the same base in all
entries, which is not possible if there is a section switch in between.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

BTW, I believe the secname_for_decl handling of VAR_OR_FUNCTION_NAME_P
(decl) is wrong, because we should never care about in what section
the variable is, secname is only used as something to base the
start/end labels of the various ranges, so IMHO we always care solely
about current_function_decl.  Is it ok as a follow-up to change that?

2018-11-26  Jakub Jelinek  <ja...@redhat.com>

        PR c++/86900
        * dwarf2out.c (secname_for_decl): For functions with
        DECL_SECTION_NAME if in_cold_section_p, try to return
        current_function_section's name if it is a named section.

        * g++.dg/debug/dwarf2/pr86900.C: New test.

--- gcc/dwarf2out.c.jj  2018-11-19 14:43:35.717901171 +0100
+++ gcc/dwarf2out.c     2018-11-26 17:02:20.353324680 +0100
@@ -16742,7 +16742,15 @@ secname_for_decl (const_tree decl)
       && DECL_SECTION_NAME (decl))
     secname = DECL_SECTION_NAME (decl);
   else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
-    secname = DECL_SECTION_NAME (current_function_decl);
+    {
+      if (in_cold_section_p)
+       {
+         section *sec = current_function_section ();
+         if (sec->common.flags & SECTION_NAMED)
+           return sec->named.name;
+       }
+      secname = DECL_SECTION_NAME (current_function_decl);
+    }
   else if (cfun && in_cold_section_p)
     secname = crtl->subsections.cold_section_label;
   else
--- gcc/testsuite/g++.dg/debug/dwarf2/pr86900.C.jj      2018-11-26 
17:21:16.637674159 +0100
+++ gcc/testsuite/g++.dg/debug/dwarf2/pr86900.C 2018-11-26 17:21:01.172927384 
+0100
@@ -0,0 +1,14 @@
+// PR c++/86900
+// { dg-do assemble { target function_sections } }
+// { dg-options "-O2 -gdwarf-5 -ffunction-sections" }
+
+struct A;
+struct B { B (A); };
+struct A { A (int); ~A (); };
+
+void
+foo (int x)
+{
+  A d(0);
+  B e(d);
+}

        Jakub

Reply via email to