OK.

On Mon, May 14, 2018 at 9:42 AM, Mark Wielaard <m...@klomp.org> wrote:
> On Mon, 2018-04-30 at 14:35 +0200, Mark Wielaard wrote:
>> We already emit DWARF5 attributes and tables for indirect addresses
>> and string offsets, but still use GNU forms. Add a new helper function
>> dwarf_FORM () for emitting the right form.
>>
>> Currently we only use the uleb128 forms. But DWARF5 also allows
>> 1, 2, 3 and 4 byte forms (DW_FORM_strx[1234] and DW_FORM_addrx[1234])
>> which might be more space efficient.
>
> Ping.
>
> gcc/ChangeLog:
>
>         * dwarf2out.c (dwarf_FORM): New function.
>         (set_indirect_string): Use dwarf_FORM.
>         (reset_indirect_string): Likewise.
>         (size_of_die): Likewise.
>         (value_format): Likewise.
>         (output_die): Likewise.
>         (add_skeleton_AT_string): Likewise.
>         (output_macinfo_op): Likewise.
>         (index_string): Likewise.
>         (output_index_string_offset): Likewise.
>         (output_index_string): Likewise.
>         (count_index_strings): Likewise.
>
> diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
> index 340de5b..85a1a8b 100644
> --- a/gcc/dwarf2out.c
> +++ b/gcc/dwarf2out.c
> @@ -246,7 +246,7 @@ static GTY (()) hash_table<indirect_string_hasher> 
> *debug_line_str_hash;
>     That is, the comp_dir and dwo_name will appear in both places.
>
>     2) Strings can use four forms: DW_FORM_string, DW_FORM_strp,
> -   DW_FORM_line_strp or DW_FORM_GNU_str_index.
> +   DW_FORM_line_strp or DW_FORM_strx/GNU_str_index.
>
>     3) GCC chooses the form to use late, depending on the size and
>     reference count.
> @@ -1757,6 +1757,28 @@ dwarf_TAG (enum dwarf_tag tag)
>    return tag;
>  }
>
> +/* And similarly for forms.  */
> +static inline enum dwarf_form
> +dwarf_FORM (enum dwarf_form form)
> +{
> +  switch (form)
> +    {
> +    case DW_FORM_addrx:
> +      if (dwarf_version < 5)
> +       return DW_FORM_GNU_addr_index;
> +      break;
> +
> +    case DW_FORM_strx:
> +      if (dwarf_version < 5)
> +       return DW_FORM_GNU_str_index;
> +      break;
> +
> +    default:
> +      break;
> +    }
> +  return form;
> +}
> +
>  static unsigned long int get_base_type_offset (dw_die_ref);
>
>  /* Return the size of a location descriptor.  */
> @@ -4387,8 +4409,8 @@ AT_class (dw_attr_node *a)
>  }
>
>  /* Return the index for any attribute that will be referenced with a
> -   DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index.  String indices
> -   are stored in dw_attr_val.v.val_str for reference counting
> +   DW_FORM_addrx/GNU_addr_index or DW_FORM_strx/GNU_str_index.  String
> +   indices are stored in dw_attr_val.v.val_str for reference counting
>     pruning.  */
>
>  static inline unsigned int
> @@ -4652,7 +4674,7 @@ set_indirect_string (struct indirect_string_node *node)
>    /* Already indirect is a no op.  */
>    if (node->form == DW_FORM_strp
>        || node->form == DW_FORM_line_strp
> -      || node->form == DW_FORM_GNU_str_index)
> +      || node->form == dwarf_FORM (DW_FORM_strx))
>      {
>        gcc_assert (node->label);
>        return;
> @@ -4668,7 +4690,7 @@ set_indirect_string (struct indirect_string_node *node)
>      }
>    else
>      {
> -      node->form = DW_FORM_GNU_str_index;
> +      node->form = dwarf_FORM (DW_FORM_strx);
>        node->index = NO_INDEX_ASSIGNED;
>      }
>  }
> @@ -4681,7 +4703,7 @@ int
>  reset_indirect_string (indirect_string_node **h, void *)
>  {
>    struct indirect_string_node *node = *h;
> -  if (node->form == DW_FORM_strp || node->form == DW_FORM_GNU_str_index)
> +  if (node->form == DW_FORM_strp || node->form == dwarf_FORM (DW_FORM_strx))
>      {
>        free (node->label);
>        node->label = NULL;
> @@ -9419,7 +9441,7 @@ size_of_die (dw_die_ref die)
>            form = AT_string_form (a);
>           if (form == DW_FORM_strp || form == DW_FORM_line_strp)
>             size += DWARF_OFFSET_SIZE;
> -         else if (form == DW_FORM_GNU_str_index)
> +         else if (form == dwarf_FORM (DW_FORM_strx))
>             size += size_of_uleb128 (AT_index (a));
>           else
>             size += strlen (a->dw_attr_val.v.val_str->str) + 1;
> @@ -9666,7 +9688,7 @@ value_format (dw_attr_node *a)
>         case DW_AT_entry_pc:
>         case DW_AT_trampoline:
>            return (AT_index (a) == NOT_INDEXED
> -                  ? DW_FORM_addr : DW_FORM_GNU_addr_index);
> +                  ? DW_FORM_addr : dwarf_FORM (DW_FORM_addrx));
>         default:
>           break;
>         }
> @@ -9839,7 +9861,7 @@ value_format (dw_attr_node *a)
>        return DW_FORM_data;
>      case dw_val_class_lbl_id:
>        return (AT_index (a) == NOT_INDEXED
> -              ? DW_FORM_addr : DW_FORM_GNU_addr_index);
> +              ? DW_FORM_addr : dwarf_FORM (DW_FORM_addrx));
>      case dw_val_class_lineptr:
>      case dw_val_class_macptr:
>      case dw_val_class_loclistsptr:
> @@ -10807,7 +10829,7 @@ output_die (dw_die_ref die)
>                                    a->dw_attr_val.v.val_str->label,
>                                    debug_line_str_section,
>                                    "%s: \"%s\"", name, AT_string (a));
> -          else if (a->dw_attr_val.v.val_str->form == DW_FORM_GNU_str_index)
> +          else if (a->dw_attr_val.v.val_str->form == dwarf_FORM 
> (DW_FORM_strx))
>              dw2_asm_output_data_uleb128 (AT_index (a),
>                                           "%s: \"%s\"", name, AT_string (a));
>            else
> @@ -11088,7 +11110,7 @@ add_skeleton_AT_string (dw_die_ref die, enum 
> dwarf_attribute attr_kind,
>
>    node = find_AT_string_in_table (str, skeleton_debug_str_hash);
>    find_string_form (node);
> -  if (node->form == DW_FORM_GNU_str_index)
> +  if (node->form == dwarf_FORM (DW_FORM_strx))
>      node->form = DW_FORM_strp;
>
>    attr.dw_attr = attr_kind;
> @@ -28052,7 +28074,7 @@ output_macinfo_op (macinfo_entry *ref)
>        node = find_AT_string (ref->info);
>        gcc_assert (node
>                   && (node->form == DW_FORM_strp
> -                     || node->form == DW_FORM_GNU_str_index));
> +                     || node->form == dwarf_form (DW_FORM_strx)));
>        dw2_asm_output_data (1, ref->code,
>                            ref->code == DW_MACRO_define_strp
>                            ? "Define macro strp"
> @@ -28683,7 +28705,7 @@ index_string (indirect_string_node **h, unsigned int 
> *index)
>    indirect_string_node *node = *h;
>
>    find_string_form (node);
> -  if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
> +  if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
>      {
>        gcc_assert (node->index == NO_INDEX_ASSIGNED);
>        node->index = *index;
> @@ -28701,7 +28723,7 @@ output_index_string_offset (indirect_string_node **h, 
> unsigned int *offset)
>  {
>    indirect_string_node *node = *h;
>
> -  if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
> +  if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
>      {
>        /* Assert that this node has been assigned an index.  */
>        gcc_assert (node->index != NO_INDEX_ASSIGNED
> @@ -28721,7 +28743,7 @@ output_index_string (indirect_string_node **h, 
> unsigned int *cur_idx)
>  {
>    struct indirect_string_node *node = *h;
>
> -  if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
> +  if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
>      {
>        /* Assert that the strings are output in the same order as their
>           indexes were assigned.  */
> @@ -28740,7 +28762,7 @@ count_index_strings (indirect_string_node **h, 
> unsigned int *last_idx)
>  {
>    struct indirect_string_node *node = *h;
>
> -  if (node->form == DW_FORM_GNU_str_index && node->refcount > 0)
> +  if (node->form == dwarf_FORM (DW_FORM_strx) && node->refcount > 0)
>      *last_idx += 1;
>    return 1;
>  }

Reply via email to