]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Enable -gvariable-location-views by default
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Mon, 19 Aug 2024 05:11:18 +0000 (07:11 +0200)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Thu, 22 Aug 2024 10:40:07 +0000 (12:40 +0200)
This affects only the RISC-V targets, where the compiler options
-gvariable-location-views and consequently also -ginline-points
are disabled by default, which is unexpected and disables some
useful features of the generated debug info.

Due to a bug in the gas assembler the .loc statement
is not usable to generate location view debug info.
That is detected by configure:

configure:31500: checking assembler for dwarf2 debug_view support
configure:31509: .../riscv-unknown-elf/bin/as    -o conftest.o conftest.s >&5
conftest.s: Assembler messages:
conftest.s:5: Error: .uleb128 only supports constant or subtract expressions
conftest.s:6: Error: .uleb128 only supports constant or subtract expressions
configure:31512: $? = 1
configure: failed program was
        .file 1 "conftest.s"
        .loc 1 3 0 view .LVU1
        nop
        .data
        .uleb128 .LVU1
        .uleb128 .LVU1

configure:31523: result: no

This results in dwarf2out_as_locview_support being set to false,
and that creates a sequence of events, with the end result that
most inlined functions either have no DW_AT_entry_pc, or one
with a wrong entry pc value.

But the location views can also be generated without using any
.loc statements, therefore we should enable the option
-gvariable-location-views by default, regardless of the status
of -gas-locview-support.

Note however, that the combination of the following compiler options
-g -O2 -gvariable-location-views -gno-as-loc-support
turned out to create invalid assembler intermediate files,
with lots of assembler errors like:
Error: leb128 operand is an undefined symbol: .LVU3

This affects all targets, except RISC-V of course ;-)
and is fixed by the changes in dwarf2out.cc

Finally the .debug_loclists created without assembler locview support
did contain location view pairs like v0000000ffffffff v000000000000000
which is the value from FORCE_RESET_NEXT_VIEW, but that is most likely
not as expected either, so change that as well.

gcc/ChangeLog:

* dwarf2out.cc (dwarf2out_maybe_output_loclist_view_pair,
output_loc_list): Correct handling of -gno-as-loc-support,
use ZERO_VIEW_P to output view number as zero value.
* toplev.cc (process_options): Do not automatically disable
-gvariable-location-views when -gno-as-loc-support or
-gno-as-locview-support is used, instead do automatically
disable -gas-locview-support if -gno-as-loc-support is used.

gcc/testsuite/ChangeLog:

* gcc.dg/debug/dwarf2/inline2.c: Add checks for inline entry_pc.
* gcc.dg/debug/dwarf2/inline6.c: Add -gno-as-loc-support and check
the resulting location views.

gcc/dwarf2out.cc
gcc/testsuite/gcc.dg/debug/dwarf2/inline2.c
gcc/testsuite/gcc.dg/debug/dwarf2/inline6.c
gcc/toplev.cc

index 75ce91efd47c3dad9581ec5f84ce4866ea5b55c3..a26a07e3424271635c854c59dbd4ce45f2a73b03 100644 (file)
@@ -10396,8 +10396,10 @@ dwarf2out_maybe_output_loclist_view_pair (dw_loc_list_ref curr)
     }
   else
     {
-      dw2_asm_output_data_uleb128 (curr->vbegin, "Location view begin");
-      dw2_asm_output_data_uleb128 (curr->vend, "Location view end");
+      dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vbegin)
+                                  ? 0 : curr->vbegin, "Location view begin");
+      dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vend)
+                                  ? 0 : curr->vend, "Location view end");
     }
 #endif /* DW_LLE_view_pair */
 
@@ -10460,10 +10462,12 @@ output_loc_list (dw_loc_list_ref list_head)
            }
          else
            {
-             dw2_asm_output_data_uleb128 (curr->vbegin,
+             dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vbegin)
+                                          ? 0 : curr->vbegin,
                                           "View list begin (%s)",
                                           list_head->vl_symbol);
-             dw2_asm_output_data_uleb128 (curr->vend,
+             dw2_asm_output_data_uleb128 (ZERO_VIEW_P (curr->vend)
+                                          ? 0 : curr->vend,
                                           "View list end (%s)",
                                           list_head->vl_symbol);
            }
index 9c36450ae2de7326bb1cc4091bce2d6bd5c2bbda..6893ddfa2ebe3d6f30ba771db481387f650b6b1b 100644 (file)
@@ -30,6 +30,9 @@
    layout.  */
 /* { dg-final { scan-assembler-times "\\(DIE \\(\[^\n\]*\\) DW_TAG_lexical_block" 0 } } */
 
+/* Each inline instance should have DW_AT_entry_pc and DW_AT_GNU_entry_view.  */
+/* { dg-final { scan-assembler-times " DW_AT_entry_pc" 6 } } */
+/* { dg-final { scan-assembler-times " DW_AT_GNU_entry_view" 6 } } */
 
 /* There are 3 DW_AT_inline attributes: one per abstract inline instance.
    The value of the attribute must be 0x3, meaning the function was
index fde8c27820da60aa42a24f20b8c7b84189c3b101..d7c86f89895c228def2d3ac54bcb2d967deb80a7 100644 (file)
@@ -16,7 +16,7 @@
 
 /* Explicitly use dwarf-5 which uses DW_FORM_implicit_const.  */
 /* { dg-do compile } */
-/* { dg-options "-O -g3 -gdwarf-5 -dA -fgnu89-inline" } */
+/* { dg-options "-O -g3 -gdwarf-5 -dA -fgnu89-inline -gno-as-loc-support" } */
 
 /* There are 6 inlined subroutines:
    - One for each subroutine inlined into main, that's 3.
    layout.  */
 /* { dg-final { scan-assembler-times "\\(DIE \\(\[^\n\]*\\) DW_TAG_lexical_block" 0 } } */
 
+/* Each inline instance should have DW_AT_entry_pc and DW_AT_GNU_entry_view. */
+/* { dg-final { scan-assembler-times " DW_AT_entry_pc" 6 } } */
+/* { dg-final { scan-assembler-times " DW_AT_GNU_entry_view" 6 } } */
+/* { dg-final { scan-assembler-times "uleb128\[^\n\]*LVU\[^\n\]* (View list|Location view) (begin|end)" 0 } } */
+/* { dg-final { scan-assembler-times "uleb128\[^\n\]*0xffffffff\[^\n\]* (View list|Location view) (begin|end)" 0 } } */
 
 /* There are 3 DW_AT_inline attributes: one per abstract inline instance.
    The value of the attribute must be 0x3, meaning the function was
index f308fb151083ee8a1642269926881a7ae6b4ef1d..bc442a08c63ef7f22b4722659c4aa1a638fc586a 100644 (file)
@@ -1505,6 +1505,14 @@ process_options ()
     dwarf2out_as_loc_support = dwarf2out_default_as_loc_support ();
   if (!OPTION_SET_P (dwarf2out_as_locview_support))
     dwarf2out_as_locview_support = dwarf2out_default_as_locview_support ();
+  if (dwarf2out_as_locview_support && !dwarf2out_as_loc_support)
+    {
+      if (OPTION_SET_P (dwarf2out_as_locview_support))
+       warning_at (UNKNOWN_LOCATION, 0,
+                   "%<-gas-locview-support%> is forced disabled "
+                   "without %<-gas-loc-support%>");
+      dwarf2out_as_locview_support = false;
+    }
 
   if (!OPTION_SET_P (debug_variable_location_views))
     {
@@ -1512,9 +1520,7 @@ process_options ()
        = (flag_var_tracking
           && debug_info_level >= DINFO_LEVEL_NORMAL
           && dwarf_debuginfo_p ()
-          && !dwarf_strict
-          && dwarf2out_as_loc_support
-          && dwarf2out_as_locview_support);
+          && !dwarf_strict);
     }
   else if (debug_variable_location_views == -1 && dwarf_version != 5)
     {