The loclists_base attribute is used to point to the beginning of the
loclists index of a DWARF5 loclists table when using DW_FORM_loclistsx.
For split compile units the base is not given by the attribute, but is
either the first (and only) index in the .debug_loclists section, or
(when placed in a .dwp file) given by the DW_SECT_LOCLISTS row in the
.debug_cu_index section.

The loclists_base attribute is only valid for the full (or skeleton)
compile unit DIE in the main (relocatable) object. But GCC only ever
generates a loclists table index for the .debug_loclists section put
into the split DWARF .dwo file.

For split compile unit DIEs it is confusing (and not according to spec)
to also have a DW_AT_loclists_base attribute (which might be wrong,
since its relocatable offset won't actually be relocated).

gcc/ChangeLog

        * dwarf2out.c (dwarf2out_finish): Remove generation of
        DW_AT_loclists_base.
---

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index c05bfe4..103ded0 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -31292,11 +31292,17 @@ dwarf2out_finish (const char *)
   if (dwarf_split_debug_info)
     {
       if (have_location_lists)
        {
-         if (dwarf_version >= 5)
-           add_AT_loclistsptr (comp_unit_die (), DW_AT_loclists_base,
-                               loc_section_label);
+         /* Since we generate the loclists in the split DWARF .dwo
+            file itself, we don't need to generate a loclists_base
+            attribute for the split compile unit DIE.  That attribute
+            (and using relocatable sec_offset FORMs) isn't allowed
+            for a split compile unit.  Only if the .debug_loclists
+            section was in the main file, would we need to generate a
+            loclists_base attribute here (for the full or skeleton
+            unit DIE).  */
+
          /* optimize_location_lists calculates the size of the lists,
             so index them first, and assign indices to the entries.
             Although optimize_location_lists will remove entries from
             the table, it only does so for duplicates, and therefore

Reply via email to