diff mbox series

dwarf: Add -gdwarf{32,64} options

Message ID 20201201103618.GS3788@tucnak
State New
Headers show
Series dwarf: Add -gdwarf{32,64} options | expand

Commit Message

Jakub Jelinek Dec. 1, 2020, 10:36 a.m. UTC
Hi!

The following patch makes the choice between 32-bit and 64-bit DWARF formats
selectable by command line switch, rather than being hardcoded through
DWARF_OFFSET_SIZE macro.

The options themselves don't turn on debug info themselves, so one needs
to use -g -gdwarf64 or similar.

Ok for trunk if it passes bootstrap/regtest?

I've tried it on a few smaller and larger testcases and readelf -wi was
happy about the output.

2020-12-01  Jakub Jelinek  <jakub@redhat.com>

	* common.opt (-gdwarf32, -gdwarf64): New options.
	* config/rs6000/rs6000.c (rs6000_option_override_internal): Default
	dwarf_offset_size to 8 if not overridden from the command line.
	* dwarf2out.c: Change all occurrences of DWARF_OFFSET_SIZE to
	dwarf_offset_size.
	* doc/invoke.texi (-gdwarf32, -gdwarf64): Document.


	Jakub

Comments

Richard Biener Dec. 1, 2020, 10:49 a.m. UTC | #1
On Tue, 1 Dec 2020, Jakub Jelinek wrote:

> Hi!
> 
> The following patch makes the choice between 32-bit and 64-bit DWARF formats
> selectable by command line switch, rather than being hardcoded through
> DWARF_OFFSET_SIZE macro.
> 
> The options themselves don't turn on debug info themselves, so one needs
> to use -g -gdwarf64 or similar.
> 
> Ok for trunk if it passes bootstrap/regtest?

OK.  Note there's

/* Various DIE's use offsets relative to the beginning of the
   .debug_info section to refer to each other.  */

typedef long int dw_offset;

which on L32 hosts means we might not support dwarf64 generation
for CUs that do not fit in 31bits?  Should we change that to
int64_t?  Or should we sorry() for -gdwarf64 on 32bit hosts?

There's also

  unsigned long die_abbrev;

and other uses of '[unsigned] long' in dwarf2out.c.

> I've tried it on a few smaller and larger testcases and readelf -wi was
> happy about the output.

Do dwarf32 and dwarf64 objects inter-operate just fine (as long as
the linker can resolve all relocations w/o truncating)?

Richard.

> 2020-12-01  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* common.opt (-gdwarf32, -gdwarf64): New options.
> 	* config/rs6000/rs6000.c (rs6000_option_override_internal): Default
> 	dwarf_offset_size to 8 if not overridden from the command line.
> 	* dwarf2out.c: Change all occurrences of DWARF_OFFSET_SIZE to
> 	dwarf_offset_size.
> 	* doc/invoke.texi (-gdwarf32, -gdwarf64): Document.
> 
> --- gcc/common.opt.jj	2020-11-26 01:14:47.444082913 +0100
> +++ gcc/common.opt	2020-12-01 11:07:33.088093473 +0100
> @@ -3178,6 +3178,14 @@ gdwarf-
>  Common Driver Joined UInteger Var(dwarf_version) Init(4) Negative(gstabs)
>  Generate debug information in DWARF v2 (or later) format.
>  
> +gdwarf32
> +Common Driver Var(dwarf_offset_size,4) Init(4) RejectNegative
> +Use 32-bit DWARF format when emitting DWARF debug information.
> +
> +gdwarf64
> +Common Driver Var(dwarf_offset_size,8) RejectNegative
> +Use 64-bit DWARF format when emitting DWARF debug information.
> +
>  ggdb
>  Common Driver JoinedOrMissing
>  Generate debug information in default extended format.
> --- gcc/config/rs6000/rs6000.c.jj	2020-11-27 11:20:53.484334843 +0100
> +++ gcc/config/rs6000/rs6000.c	2020-12-01 11:12:31.618731395 +0100
> @@ -3863,6 +3863,12 @@ rs6000_option_override_internal (bool gl
>    if (TARGET_DEBUG_REG || TARGET_DEBUG_TARGET)
>      rs6000_print_isa_options (stderr, 0, "before defaults", rs6000_isa_flags);
>  
> +#ifdef XCOFF_DEBUGGING_INFO
> +  /* For AIX default to 64-bit DWARF.  */
> +  if (!global_options_set.x_dwarf_offset_size)
> +    dwarf_offset_size = 8;
> +#endif
> +
>    /* Handle explicit -mno-{altivec,vsx,power8-vector,power9-vector} and turn
>       off all of the options that depend on those flags.  */
>    ignore_masks = rs6000_disable_incompatible_switches ();
> --- gcc/dwarf2out.c.jj	2020-12-01 09:41:07.223490914 +0100
> +++ gcc/dwarf2out.c	2020-12-01 11:03:04.692115667 +0100
> @@ -182,14 +182,14 @@ static GTY(()) section *debug_frame_sect
>     bytes.
>  
>     However, the SGI/MIPS ABI uses an initial length which is equal to
> -   DWARF_OFFSET_SIZE.  It is defined (elsewhere) accordingly.  */
> +   dwarf_offset_size.  It is defined (elsewhere) accordingly.  */
>  
>  #ifndef DWARF_INITIAL_LENGTH_SIZE
> -#define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
> +#define DWARF_INITIAL_LENGTH_SIZE (dwarf_offset_size == 4 ? 4 : 12)
>  #endif
>  
>  #ifndef DWARF_INITIAL_LENGTH_SIZE_STR
> -#define DWARF_INITIAL_LENGTH_SIZE_STR (DWARF_OFFSET_SIZE == 4 ? "-4" : "-12")
> +#define DWARF_INITIAL_LENGTH_SIZE_STR (dwarf_offset_size == 4 ? "-4" : "-12")
>  #endif
>  
>  /* Round SIZE up to the nearest BOUNDARY.  */
> @@ -199,7 +199,7 @@ static GTY(()) section *debug_frame_sect
>  /* CIE identifier.  */
>  #if HOST_BITS_PER_WIDE_INT >= 64
>  #define DWARF_CIE_ID \
> -  (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
> +  (unsigned HOST_WIDE_INT) (dwarf_offset_size == 4 ? DW_CIE_ID : DW64_CIE_ID)
>  #else
>  #define DWARF_CIE_ID DW_CIE_ID
>  #endif
> @@ -287,8 +287,8 @@ static GTY(()) bool do_eh_frame = false;
>  static unsigned int rnglist_idx;
>  
>  /* Data and reference forms for relocatable data.  */
> -#define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
> -#define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
> +#define DW_FORM_data (dwarf_offset_size == 8 ? DW_FORM_data8 : DW_FORM_data4)
> +#define DW_FORM_ref (dwarf_offset_size == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
>  
>  #ifndef DEBUG_FRAME_SECTION
>  #define DEBUG_FRAME_SECTION	".debug_frame"
> @@ -602,10 +602,10 @@ output_fde (dw_fde_ref fde, bool for_eh,
>    ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
>    if (!XCOFF_DEBUGGING_INFO || for_eh)
>      {
> -      if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
> +      if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4 && !for_eh)
>  	dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
>  			     " indicating 64-bit DWARF extension");
> -      dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
> +      dw2_asm_output_delta (for_eh ? 4 : dwarf_offset_size, l2, l1,
>  			    "FDE Length");
>      }
>    ASM_OUTPUT_LABEL (asm_out_file, l1);
> @@ -613,7 +613,7 @@ output_fde (dw_fde_ref fde, bool for_eh,
>    if (for_eh)
>      dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
>    else
> -    dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
> +    dw2_asm_output_offset (dwarf_offset_size, section_start_label,
>  			   debug_frame_section, "FDE CIE offset");
>  
>    begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
> @@ -806,17 +806,17 @@ output_call_frame_info (int for_eh)
>    ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
>    if (!XCOFF_DEBUGGING_INFO || for_eh)
>      {
> -      if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
> +      if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4 && !for_eh)
>  	dw2_asm_output_data (4, 0xffffffff,
>  	  "Initial length escape value indicating 64-bit DWARF extension");
> -      dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
> +      dw2_asm_output_delta (for_eh ? 4 : dwarf_offset_size, l2, l1,
>  			    "Length of Common Information Entry");
>      }
>    ASM_OUTPUT_LABEL (asm_out_file, l1);
>  
>    /* Now that the CIE pointer is PC-relative for EH,
>       use 0 to identify the CIE.  */
> -  dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
> +  dw2_asm_output_data ((for_eh ? 4 : dwarf_offset_size),
>  		       (for_eh ? 0 : DWARF_CIE_ID),
>  		       "CIE Identifier Tag");
>  
> @@ -1623,7 +1623,7 @@ loc_list_plus_const (dw_loc_list_ref lis
>  }
>  
>  #define DWARF_REF_SIZE	\
> -  (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
> +  (dwarf_version == 2 ? DWARF2_ADDR_SIZE : dwarf_offset_size)
>  
>  /* The number of bits that can be encoded by largest DW_FORM_dataN.
>     In DWARF4 and earlier it is DW_FORM_data8 with 64 bits, in DWARF5
> @@ -3229,33 +3229,33 @@ skeleton_chain_node;
>  
>  /* Fixed size portion of the DWARF compilation unit header.  */
>  #define DWARF_COMPILE_UNIT_HEADER_SIZE \
> -  (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE			\
> +  (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size			\
>     + (dwarf_version >= 5 ? 4 : 3))
>  
>  /* Fixed size portion of the DWARF comdat type unit header.  */
>  #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
>    (DWARF_COMPILE_UNIT_HEADER_SIZE					\
> -   + DWARF_TYPE_SIGNATURE_SIZE + DWARF_OFFSET_SIZE)
> +   + DWARF_TYPE_SIGNATURE_SIZE + dwarf_offset_size)
>  
>  /* Fixed size portion of the DWARF skeleton compilation unit header.  */
>  #define DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE \
>    (DWARF_COMPILE_UNIT_HEADER_SIZE + (dwarf_version >= 5 ? 8 : 0))
>  
>  /* Fixed size portion of public names info.  */
> -#define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
> +#define DWARF_PUBNAMES_HEADER_SIZE (2 * dwarf_offset_size + 2)
>  
>  /* Fixed size portion of the address range info.  */
>  #define DWARF_ARANGES_HEADER_SIZE					\
> -  (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4,	\
> +  (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4,	\
>  		DWARF2_ADDR_SIZE * 2)					\
>     - DWARF_INITIAL_LENGTH_SIZE)
>  
>  /* Size of padding portion in the address range info.  It must be
>     aligned to twice the pointer size.  */
>  #define DWARF_ARANGES_PAD_SIZE \
> -  (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
> +  (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4, \
>  		DWARF2_ADDR_SIZE * 2)				   \
> -   - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
> +   - (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4))
>  
>  /* Use assembler line directives if available.  */
>  #ifndef DWARF2_ASM_LINE_DEBUG_INFO
> @@ -4787,7 +4787,7 @@ find_string_form (struct indirect_string
>  
>    /* If the string is shorter or equal to the size of the reference, it is
>       always better to put it inline.  */
> -  if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
> +  if (len <= (unsigned) dwarf_offset_size || node->refcount == 0)
>      return node->form = DW_FORM_string;
>  
>    /* If we cannot expect the linker to merge strings in .debug_str
> @@ -4795,7 +4795,7 @@ find_string_form (struct indirect_string
>       single module.  */
>    if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
>        || ((debug_str_section->common.flags & SECTION_MERGE) == 0
> -	  && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
> +	  && (len - dwarf_offset_size) * node->refcount <= len))
>      return node->form = DW_FORM_string;
>  
>    set_indirect_string (node);
> @@ -8892,7 +8892,7 @@ output_loclists_offsets (dw_die_ref die)
>  	dw_loc_list_ref l = AT_loc_list (a);
>  	if (l->offset_emitted)
>  	  continue;
> -	dw2_asm_output_delta (DWARF_OFFSET_SIZE, l->ll_symbol,
> +	dw2_asm_output_delta (dwarf_offset_size, l->ll_symbol,
>  			      loc_section_label, NULL);
>  	gcc_assert (l->hash == loc_list_idx);
>  	loc_list_idx++;
> @@ -9400,7 +9400,7 @@ size_of_die (dw_die_ref die)
>              size += DWARF2_ADDR_SIZE;
>  	  break;
>  	case dw_val_class_offset:
> -	  size += DWARF_OFFSET_SIZE;
> +	  size += dwarf_offset_size;
>  	  break;
>  	case dw_val_class_loc:
>  	  {
> @@ -9421,10 +9421,10 @@ size_of_die (dw_die_ref die)
>  	      size += size_of_uleb128 (AT_loc_list (a)->hash);
>  	    }
>            else
> -            size += DWARF_OFFSET_SIZE;
> +            size += dwarf_offset_size;
>  	  break;
>  	case dw_val_class_view_list:
> -	  size += DWARF_OFFSET_SIZE;
> +	  size += dwarf_offset_size;
>  	  break;
>  	case dw_val_class_range_list:
>  	  if (value_format (a) == DW_FORM_rnglistx)
> @@ -9434,7 +9434,7 @@ size_of_die (dw_die_ref die)
>  	      size += size_of_uleb128 (r->idx);
>  	    }
>  	  else
> -	    size += DWARF_OFFSET_SIZE;
> +	    size += dwarf_offset_size;
>  	  break;
>  	case dw_val_class_const:
>  	  size += size_of_sleb128 (AT_int (a));
> @@ -9508,13 +9508,13 @@ size_of_die (dw_die_ref die)
>  	      else if (dwarf_version == 2)
>  		size += DWARF2_ADDR_SIZE;
>  	      else
> -		size += DWARF_OFFSET_SIZE;
> +		size += dwarf_offset_size;
>  	    }
>  	  else
> -	    size += DWARF_OFFSET_SIZE;
> +	    size += dwarf_offset_size;
>  	  break;
>  	case dw_val_class_fde_ref:
> -	  size += DWARF_OFFSET_SIZE;
> +	  size += dwarf_offset_size;
>  	  break;
>  	case dw_val_class_lbl_id:
>            if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
> @@ -9528,12 +9528,12 @@ size_of_die (dw_die_ref die)
>  	case dw_val_class_lineptr:
>  	case dw_val_class_macptr:
>  	case dw_val_class_loclistsptr:
> -	  size += DWARF_OFFSET_SIZE;
> +	  size += dwarf_offset_size;
>  	  break;
>  	case dw_val_class_str:
>            form = AT_string_form (a);
>  	  if (form == DW_FORM_strp || form == DW_FORM_line_strp)
> -	    size += DWARF_OFFSET_SIZE;
> +	    size += dwarf_offset_size;
>  	  else if (form == dwarf_FORM (DW_FORM_strx))
>  	    size += size_of_uleb128 (AT_index (a));
>  	  else
> @@ -9546,7 +9546,7 @@ size_of_die (dw_die_ref die)
>  	  size += 8;
>  	  break;
>  	case dw_val_class_vms_delta:
> -	  size += DWARF_OFFSET_SIZE;
> +	  size += dwarf_offset_size;
>  	  break;
>  	case dw_val_class_high_pc:
>  	  size += DWARF2_ADDR_SIZE;
> @@ -9724,9 +9724,9 @@ size_of_pubnames (vec<pubname_entry, va_
>    size = DWARF_PUBNAMES_HEADER_SIZE;
>    FOR_EACH_VEC_ELT (*names, i, p)
>      if (include_pubname_in_output (names, p))
> -      size += strlen (p->name) + DWARF_OFFSET_SIZE + 1 + space_for_flags;
> +      size += strlen (p->name) + dwarf_offset_size + 1 + space_for_flags;
>  
> -  size += DWARF_OFFSET_SIZE;
> +  size += dwarf_offset_size;
>    return size;
>  }
>  
> @@ -9823,7 +9823,7 @@ value_format (dw_attr_node *a)
>        /* FALLTHRU */
>      case dw_val_class_vms_delta:
>      case dw_val_class_offset:
> -      switch (DWARF_OFFSET_SIZE)
> +      switch (dwarf_offset_size)
>  	{
>  	case 4:
>  	  return DW_FORM_data4;
> @@ -10525,7 +10525,7 @@ output_range_list_offset (dw_attr_node *
>        if (dwarf_version >= 5)
>  	{
>  	  dw_ranges *r = &(*ranges_table)[a->dw_attr_val.v.val_offset];
> -	  dw2_asm_output_offset (DWARF_OFFSET_SIZE, r->label,
> +	  dw2_asm_output_offset (dwarf_offset_size, r->label,
>  				 debug_ranges_section, "%s", name);
>  	}
>        else
> @@ -10533,7 +10533,7 @@ output_range_list_offset (dw_attr_node *
>  	  char *p = strchr (ranges_section_label, '\0');
>  	  sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
>  		   a->dw_attr_val.v.val_offset * 2 * DWARF2_ADDR_SIZE);
> -	  dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
> +	  dw2_asm_output_offset (dwarf_offset_size, ranges_section_label,
>  				 debug_ranges_section, "%s", name);
>  	  *p = '\0';
>  	}
> @@ -10545,7 +10545,7 @@ output_range_list_offset (dw_attr_node *
>        dw2_asm_output_data_uleb128 (r->idx, "%s", name);
>      }
>    else
> -    dw2_asm_output_data (DWARF_OFFSET_SIZE,
> +    dw2_asm_output_data (dwarf_offset_size,
>  			 a->dw_attr_val.v.val_offset * 2 * DWARF2_ADDR_SIZE,
>                           "%s (offset from %s)", name, ranges_section_label);
>  }
> @@ -10559,7 +10559,7 @@ output_loc_list_offset (dw_attr_node *a)
>  
>    gcc_assert (sym);
>    if (!dwarf_split_debug_info)
> -    dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
> +    dw2_asm_output_offset (dwarf_offset_size, sym, debug_loc_section,
>                             "%s", dwarf_attr_name (a->dw_attr));
>    else if (dwarf_version >= 5)
>      {
> @@ -10569,7 +10569,7 @@ output_loc_list_offset (dw_attr_node *a)
>  				   sym);
>      }
>    else
> -    dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, loc_section_label,
> +    dw2_asm_output_delta (dwarf_offset_size, sym, loc_section_label,
>  			  "%s", dwarf_attr_name (a->dw_attr));
>  }
>  
> @@ -10582,10 +10582,10 @@ output_view_list_offset (dw_attr_node *a
>  
>    gcc_assert (sym);
>    if (dwarf_split_debug_info)
> -    dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, loc_section_label,
> +    dw2_asm_output_delta (dwarf_offset_size, sym, loc_section_label,
>                            "%s", dwarf_attr_name (a->dw_attr));
>    else
> -    dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
> +    dw2_asm_output_offset (dwarf_offset_size, sym, debug_loc_section,
>                             "%s", dwarf_attr_name (a->dw_attr));
>  }
>  
> @@ -10663,7 +10663,7 @@ output_die (dw_die_ref die)
>  	  break;
>  
>  	case dw_val_class_offset:
> -	  dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
> +	  dw2_asm_output_data (dwarf_offset_size, a->dw_attr_val.v.val_offset,
>  			       "%s", name);
>  	  break;
>  
> @@ -10857,7 +10857,7 @@ output_die (dw_die_ref die)
>  		  if (dwarf_version == 2)
>  		    size = DWARF2_ADDR_SIZE;
>  		  else
> -		    size = DWARF_OFFSET_SIZE;
> +		    size = dwarf_offset_size;
>  		  /* ???  We cannot unconditionally output die_offset if
>  		     non-zero - others might create references to those
>  		     DIEs via symbols.
> @@ -10877,7 +10877,7 @@ output_die (dw_die_ref die)
>  	  else
>  	    {
>  	      gcc_assert (AT_ref (a)->die_offset);
> -	      dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
> +	      dw2_asm_output_data (dwarf_offset_size, AT_ref (a)->die_offset,
>  				   "%s", name);
>  	    }
>  	  break;
> @@ -10888,18 +10888,18 @@ output_die (dw_die_ref die)
>  
>  	    ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
>  					 a->dw_attr_val.v.val_fde_index * 2);
> -	    dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
> +	    dw2_asm_output_offset (dwarf_offset_size, l1, debug_frame_section,
>  				   "%s", name);
>  	  }
>  	  break;
>  
>  	case dw_val_class_vms_delta:
>  #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
> -	  dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
> +	  dw2_asm_output_vms_delta (dwarf_offset_size,
>  				    AT_vms_delta2 (a), AT_vms_delta1 (a),
>  				    "%s", name);
>  #else
> -	  dw2_asm_output_delta (DWARF_OFFSET_SIZE,
> +	  dw2_asm_output_delta (dwarf_offset_size,
>  				AT_vms_delta2 (a), AT_vms_delta1 (a),
>  				"%s", name);
>  #endif
> @@ -10910,28 +10910,28 @@ output_die (dw_die_ref die)
>  	  break;
>  
>  	case dw_val_class_lineptr:
> -	  dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
> +	  dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
>  				 debug_line_section, "%s", name);
>  	  break;
>  
>  	case dw_val_class_macptr:
> -	  dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
> +	  dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
>  				 debug_macinfo_section, "%s", name);
>  	  break;
>  
>  	case dw_val_class_loclistsptr:
> -	  dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
> +	  dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
>  				 debug_loc_section, "%s", name);
>  	  break;
>  
>  	case dw_val_class_str:
>            if (a->dw_attr_val.v.val_str->form == DW_FORM_strp)
> -            dw2_asm_output_offset (DWARF_OFFSET_SIZE,
> +            dw2_asm_output_offset (dwarf_offset_size,
>                                     a->dw_attr_val.v.val_str->label,
>                                     debug_str_section,
>                                     "%s: \"%s\"", name, AT_string (a));
>  	  else if (a->dw_attr_val.v.val_str->form == DW_FORM_line_strp)
> -	    dw2_asm_output_offset (DWARF_OFFSET_SIZE,
> +	    dw2_asm_output_offset (dwarf_offset_size,
>  				   a->dw_attr_val.v.val_str->label,
>  				   debug_line_str_section,
>  				   "%s: \"%s\"", name, AT_string (a));
> @@ -11048,10 +11048,10 @@ output_compilation_unit_header (enum dwa
>  {
>    if (!XCOFF_DEBUGGING_INFO)
>      {
> -      if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
> +      if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
>  	dw2_asm_output_data (4, 0xffffffff,
>  	  "Initial length escape value indicating 64-bit DWARF extension");
> -      dw2_asm_output_data (DWARF_OFFSET_SIZE,
> +      dw2_asm_output_data (dwarf_offset_size,
>  			   next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
>  			   "Length of Compilation Unit Info");
>      }
> @@ -11071,7 +11071,7 @@ output_compilation_unit_header (enum dwa
>        dw2_asm_output_data (1, ut, "%s", name);
>        dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
>      }
> -  dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
> +  dw2_asm_output_offset (dwarf_offset_size, abbrev_section_label,
>  			 debug_abbrev_section,
>  			 "Offset Into Abbrev. Section");
>    if (dwarf_version < 5)
> @@ -11261,12 +11261,12 @@ output_skeleton_debug_sections (dw_die_r
>    /* Produce the skeleton compilation-unit header.  This one differs enough from
>       a normal CU header that it's better not to call output_compilation_unit
>       header.  */
> -  if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
> +  if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
>      dw2_asm_output_data (4, 0xffffffff,
>  			 "Initial length escape value indicating 64-bit "
>  			 "DWARF extension");
>  
> -  dw2_asm_output_data (DWARF_OFFSET_SIZE,
> +  dw2_asm_output_data (dwarf_offset_size,
>  		       DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
>                         - DWARF_INITIAL_LENGTH_SIZE
>                         + size_of_die (comp_unit),
> @@ -11277,7 +11277,7 @@ output_skeleton_debug_sections (dw_die_r
>        dw2_asm_output_data (1, DW_UT_skeleton, "DW_UT_skeleton");
>        dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
>      }
> -  dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_abbrev_section_label,
> +  dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_abbrev_section_label,
>  			 debug_skeleton_abbrev_section,
>                           "Offset Into Abbrev. Section");
>    if (dwarf_version < 5)
> @@ -11362,7 +11362,7 @@ output_comdat_type_unit (comdat_type_nod
>    output_compilation_unit_header (dwarf_split_debug_info
>  				  ? DW_UT_split_type : DW_UT_type);
>    output_signature (node->signature, "Type Signature");
> -  dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
> +  dw2_asm_output_data (dwarf_offset_size, node->type_die->die_offset,
>  		       "Offset to Type DIE");
>    output_die (node->root_die);
>  
> @@ -11491,7 +11491,7 @@ output_pubname (dw_offset die_offset, pu
>    dw_die_ref die = entry->die;
>    int is_static = get_AT_flag (die, DW_AT_external) ? 0 : 1;
>  
> -  dw2_asm_output_data (DWARF_OFFSET_SIZE, die_offset, "DIE offset");
> +  dw2_asm_output_data (dwarf_offset_size, die_offset, "DIE offset");
>  
>    if (debug_generate_pub_sections == 2)
>      {
> @@ -11565,10 +11565,10 @@ output_pubnames (vec<pubname_entry, va_g
>  
>    if (!XCOFF_DEBUGGING_INFO)
>      {
> -      if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
> +      if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
>  	dw2_asm_output_data (4, 0xffffffff,
>  	  "Initial length escape value indicating 64-bit DWARF extension");
> -      dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
> +      dw2_asm_output_data (dwarf_offset_size, pubnames_length,
>  			   "Pub Info Length");
>      }
>  
> @@ -11576,14 +11576,14 @@ output_pubnames (vec<pubname_entry, va_g
>    dw2_asm_output_data (2, 2, "DWARF pubnames/pubtypes version");
>  
>    if (dwarf_split_debug_info)
> -    dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_info_section_label,
> +    dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_info_section_label,
>                             debug_skeleton_info_section,
>                             "Offset of Compilation Unit Info");
>    else
> -    dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
> +    dw2_asm_output_offset (dwarf_offset_size, debug_info_section_label,
>                             debug_info_section,
>                             "Offset of Compilation Unit Info");
> -  dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
> +  dw2_asm_output_data (dwarf_offset_size, next_die_offset,
>  		       "Compilation Unit Length");
>  
>    FOR_EACH_VEC_ELT (*names, i, pub)
> @@ -11614,7 +11614,7 @@ output_pubnames (vec<pubname_entry, va_g
>  	}
>      }
>  
> -  dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
> +  dw2_asm_output_data (dwarf_offset_size, 0, NULL);
>  }
>  
>  /* Output public names and types tables if necessary.  */
> @@ -11647,21 +11647,21 @@ output_aranges (void)
>    
>    if (!XCOFF_DEBUGGING_INFO)
>      {
> -      if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
> +      if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
>  	dw2_asm_output_data (4, 0xffffffff,
>  	  "Initial length escape value indicating 64-bit DWARF extension");
> -      dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
> +      dw2_asm_output_data (dwarf_offset_size, aranges_length,
>  			   "Length of Address Ranges Info");
>      }
>  
>    /* Version number for aranges is still 2, even up to DWARF5.  */
>    dw2_asm_output_data (2, 2, "DWARF aranges version");
>    if (dwarf_split_debug_info)
> -    dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_info_section_label,
> +    dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_info_section_label,
>                             debug_skeleton_info_section,
>                             "Offset of Compilation Unit Info");
>    else
> -    dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
> +    dw2_asm_output_offset (dwarf_offset_size, debug_info_section_label,
>                             debug_info_section,
>                             "Offset of Compilation Unit Info");
>    dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
> @@ -11936,11 +11936,11 @@ output_rnglists (unsigned generation)
>  			       2 + generation * 4);
>    ASM_GENERATE_INTERNAL_LABEL (l2, DEBUG_RANGES_SECTION_LABEL,
>  			       3 + generation * 4);
> -  if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
> +  if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
>      dw2_asm_output_data (4, 0xffffffff,
>  			 "Initial length escape value indicating "
>  			 "64-bit DWARF extension");
> -  dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
> +  dw2_asm_output_delta (dwarf_offset_size, l2, l1,
>  			"Length of Range Lists");
>    ASM_OUTPUT_LABEL (asm_out_file, l1);
>    output_dwarf_version ();
> @@ -11959,7 +11959,7 @@ output_rnglists (unsigned generation)
>        ASM_OUTPUT_LABEL (asm_out_file, ranges_base_label);
>        FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
>  	if (r->label)
> -	  dw2_asm_output_delta (DWARF_OFFSET_SIZE, r->label,
> +	  dw2_asm_output_delta (dwarf_offset_size, r->label,
>  				ranges_base_label, NULL);
>      }
>  
> @@ -12219,7 +12219,7 @@ output_line_string (enum dwarf_form form
>        node = find_AT_string_in_table (str, debug_line_str_hash);
>        set_indirect_string (node);
>        node->form = form;
> -      dw2_asm_output_offset (DWARF_OFFSET_SIZE, node->label,
> +      dw2_asm_output_offset (dwarf_offset_size, node->label,
>  			     debug_line_str_section, "%s: %#x: \"%s\"",
>  			     entry_kind, 0, node->str);
>        break;
> @@ -12728,10 +12728,10 @@ output_line_info (bool prologue_only)
>  
>    if (!XCOFF_DEBUGGING_INFO)
>      {
> -      if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
> +      if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
>  	dw2_asm_output_data (4, 0xffffffff,
>  	  "Initial length escape value indicating 64-bit DWARF extension");
> -      dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
> +      dw2_asm_output_delta (dwarf_offset_size, l2, l1,
>  			    "Length of Source Line Info");
>      }
>  
> @@ -12743,7 +12743,7 @@ output_line_info (bool prologue_only)
>        dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Address Size");
>        dw2_asm_output_data (1, 0, "Segment Size");
>      }
> -  dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
> +  dw2_asm_output_delta (dwarf_offset_size, p2, p1, "Prolog Length");
>    ASM_OUTPUT_LABEL (asm_out_file, p1);
>  
>    /* Define the architecture-dependent minimum instruction length (in bytes).
> @@ -28306,7 +28306,7 @@ output_macinfo_op (macinfo_entry *ref)
>      case DW_MACINFO_undef:
>        len = strlen (ref->info) + 1;
>        if (!dwarf_strict
> -	  && len > DWARF_OFFSET_SIZE
> +	  && len > (size_t) dwarf_offset_size
>  	  && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
>  	  && (debug_str_section->common.flags & SECTION_MERGE) != 0)
>  	{
> @@ -28347,7 +28347,7 @@ output_macinfo_op (macinfo_entry *ref)
>        dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
>  				   (unsigned long) ref->lineno);
>        if (node->form == DW_FORM_strp)
> -        dw2_asm_output_offset (DWARF_OFFSET_SIZE, node->label,
> +        dw2_asm_output_offset (dwarf_offset_size, node->label,
>                                 debug_str_section, "The macro: \"%s\"",
>                                 ref->info);
>        else
> @@ -28359,7 +28359,7 @@ output_macinfo_op (macinfo_entry *ref)
>        ASM_GENERATE_INTERNAL_LABEL (label,
>  				   DEBUG_MACRO_SECTION_LABEL,
>  				   ref->lineno + macinfo_label_base);
> -      dw2_asm_output_offset (DWARF_OFFSET_SIZE, label, NULL, NULL);
> +      dw2_asm_output_offset (dwarf_offset_size, label, NULL, NULL);
>        break;
>      default:
>        fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
> @@ -28443,7 +28443,7 @@ optimize_macinfo_range (unsigned int idx
>    /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum>  */
>    grp_name = XALLOCAVEC (char, 4 + encoded_filename_len + linebuf_len + 1
>  			 + 16 * 2 + 1);
> -  memcpy (grp_name, DWARF_OFFSET_SIZE == 4 ? "wm4." : "wm8.", 4);
> +  memcpy (grp_name, dwarf_offset_size == 4 ? "wm4." : "wm8.", 4);
>    tail = grp_name + 4;
>    if (encoded_filename_len)
>      {
> @@ -28514,7 +28514,7 @@ save_macinfo_strings (void)
>            case DW_MACINFO_undef:
>              len = strlen (ref->info) + 1;
>              if (!dwarf_strict
> -                && len > DWARF_OFFSET_SIZE
> +                && len > (unsigned) dwarf_offset_size
>                  && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
>                  && (debug_str_section->common.flags & SECTION_MERGE) != 0)
>                set_indirect_string (find_AT_string (ref->info));
> @@ -28567,11 +28567,11 @@ output_macinfo (const char *debug_line_l
>      {
>        dw2_asm_output_data (2, dwarf_version >= 5 ? 5 : 4,
>  			   "DWARF macro version number");
> -      if (DWARF_OFFSET_SIZE == 8)
> +      if (dwarf_offset_size == 8)
>  	dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
>        else
>  	dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
> -      dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_line_label,
> +      dw2_asm_output_offset (dwarf_offset_size, debug_line_label,
>                               debug_line_section, NULL);
>      }
>  
> @@ -28660,7 +28660,7 @@ output_macinfo (const char *debug_line_l
>  	  ref->info = NULL;
>  	  dw2_asm_output_data (2, dwarf_version >= 5 ? 5 : 4,
>  			       "DWARF macro version number");
> -	  if (DWARF_OFFSET_SIZE == 8)
> +	  if (dwarf_offset_size == 8)
>  	    dw2_asm_output_data (1, 1, "Flags: 64-bit");
>  	  else
>  	    dw2_asm_output_data (1, 0, "Flags: 32-bit");
> @@ -28997,7 +28997,7 @@ output_index_string_offset (indirect_str
>        /* Assert that this node has been assigned an index.  */
>        gcc_assert (node->index != NO_INDEX_ASSIGNED
>                    && node->index != NOT_INDEXED);
> -      dw2_asm_output_data (DWARF_OFFSET_SIZE, *offset,
> +      dw2_asm_output_data (dwarf_offset_size, *offset,
>                             "indexed string 0x%x: %s", node->index, node->str);
>        *offset += strlen (node->str) + 1;
>      }
> @@ -29091,11 +29091,11 @@ output_indirect_strings (void)
>  
>  	  debug_str_hash->traverse_noresize
>  	    <unsigned int *, count_index_strings> (&last_idx);
> -	  str_offsets_length = last_idx * DWARF_OFFSET_SIZE + 4;
> -	  if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
> +	  str_offsets_length = last_idx * dwarf_offset_size + 4;
> +	  if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
>  	    dw2_asm_output_data (4, 0xffffffff,
>  				 "Escape value for 64-bit DWARF extension");
> -	  dw2_asm_output_data (DWARF_OFFSET_SIZE, str_offsets_length,
> +	  dw2_asm_output_data (dwarf_offset_size, str_offsets_length,
>  			       "Length of string offsets unit");
>  	  dw2_asm_output_data (2, 5, "DWARF string offsets version");
>  	  dw2_asm_output_data (2, 0, "Header zero padding");
> @@ -29185,10 +29185,10 @@ output_addr_table (void)
>  	<unsigned int *, count_index_addrs> (&last_idx);
>        addrs_length = last_idx * DWARF2_ADDR_SIZE + 4;
>  
> -      if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
> +      if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
>  	dw2_asm_output_data (4, 0xffffffff,
>  			     "Escape value for 64-bit DWARF extension");
> -      dw2_asm_output_data (DWARF_OFFSET_SIZE, addrs_length,
> +      dw2_asm_output_data (dwarf_offset_size, addrs_length,
>  			   "Length of Address Unit");
>        dw2_asm_output_data (2, 5, "DWARF addr version");
>        dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
> @@ -31747,11 +31747,11 @@ dwarf2out_finish (const char *filename)
>  	{
>  	  ASM_GENERATE_INTERNAL_LABEL (l1, DEBUG_LOC_SECTION_LABEL, 2);
>  	  ASM_GENERATE_INTERNAL_LABEL (l2, DEBUG_LOC_SECTION_LABEL, 3);
> -	  if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
> +	  if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
>  	    dw2_asm_output_data (4, 0xffffffff,
>  				 "Initial length escape value indicating "
>  				 "64-bit DWARF extension");
> -	  dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
> +	  dw2_asm_output_delta (dwarf_offset_size, l2, l1,
>  			    "Length of Location Lists");
>  	  ASM_OUTPUT_LABEL (asm_out_file, l1);
>  	  output_dwarf_version ();
> --- gcc/doc/invoke.texi.jj	2020-11-27 11:20:53.509334560 +0100
> +++ gcc/doc/invoke.texi	2020-12-01 11:23:01.743634441 +0100
> @@ -452,7 +452,7 @@ Objective-C and Objective-C++ Dialects}.
>  -gstabs  -gstabs+  -gstrict-dwarf  -gno-strict-dwarf @gol
>  -gas-loc-support  -gno-as-loc-support @gol
>  -gas-locview-support  -gno-as-locview-support @gol
> --gcolumn-info  -gno-column-info @gol
> +-gcolumn-info  -gno-column-info  -gdwarf32  -gdwarf64 @gol
>  -gstatement-frontiers  -gno-statement-frontiers @gol
>  -gvariable-location-views  -gno-variable-location-views @gol
>  -ginternal-reset-location-views  -gno-internal-reset-location-views @gol
> @@ -9569,6 +9569,18 @@ information as possible into a separate
>  debug information.  To be useful, this option requires a debugger capable of
>  reading @file{.dwo} files.
>  
> +@item -gdwarf32
> +@itemx -gdwarf64
> +@opindex gdwarf32
> +@opindex gdwarf64
> +If DWARF debugging information is enabled, the @option{-gdwarf32} selects
> +the 32-bit DWARF format and the @option{-gdwarf64} selects the 64-bit
> +DWARF format.  The default is target specific, on most targets it is
> +@option{-gdwarf32} though.  The 32-bit DWARF format is smaller, but
> +can't support more than 2GiB of debug information in any of the DWARF
> +debug information sections.  The 64-bit DWARF format allows larger debug
> +information and might not be well supported by all consumers yet.
> +
>  @item -gdescribe-dies
>  @opindex gdescribe-dies
>  Add description attributes to some DWARF DIEs that have no name attribute,
> 
> 	Jakub
> 
>
Jakub Jelinek Dec. 1, 2020, 11:15 a.m. UTC | #2
On Tue, Dec 01, 2020 at 11:49:43AM +0100, Richard Biener wrote:
> On Tue, 1 Dec 2020, Jakub Jelinek wrote:
> 
> > Hi!
> > 
> > The following patch makes the choice between 32-bit and 64-bit DWARF formats
> > selectable by command line switch, rather than being hardcoded through
> > DWARF_OFFSET_SIZE macro.
> > 
> > The options themselves don't turn on debug info themselves, so one needs
> > to use -g -gdwarf64 or similar.
> > 
> > Ok for trunk if it passes bootstrap/regtest?
> 
> OK.  Note there's
> 
> /* Various DIE's use offsets relative to the beginning of the
>    .debug_info section to refer to each other.  */
> 
> typedef long int dw_offset;
> 
> which on L32 hosts means we might not support dwarf64 generation
> for CUs that do not fit in 31bits?  Should we change that to
> int64_t?  Or should we sorry() for -gdwarf64 on 32bit hosts?
> 
> There's also
> 
>   unsigned long die_abbrev;
> 
> and other uses of '[unsigned] long' in dwarf2out.c.

One thing is 32-bit hosts vs. 64-bit targets, and we maybe should indeed use
HOST_WIDE_INT for dw_offset; not sure about die_abbrev, if the .debug_abbrev
section is over 4GiB in one TU, then that would be already massive amounts of debug
info (.debug_info is typically 10-100x times larger than .debug_abbrev).
Even the HOST_WIDE_INT dw_offset might not be immediately necessary, if a
32-bit host needs to emit 4GiB of .debug_info for one TU, then I'm pretty
sure we need at least 4 times that much of compile memory if not much more,
our in memory DIE representation isn't exactly compact.
The advantage of DWARF 64-bit is not (at least for the time being) a single
TU exceeding the limits, but when linking a shared library with tons of TUs
where we exceed those limits then (for some large libraries we are already
close to those limits or over them now).

Another thing is 32-bit targets.  For them the limitations of the object
file format (e.g. 32-bit ELF) will not allow > 2GiB debug info anyway,
and as I've just tested, e.g. on x86_64 with -m32 -gdwarf64 will not work
even on tiny testcases:
as: pr64716.o: unsupported relocation type: 0x1
pr64716.s: Assembler messages:
pr64716.s:6013: Error: cannot represent relocation type BFD_RELOC_64
as: pr64716.o: unsupported relocation type: 0x1
pr64716.s:6015: Error: cannot represent relocation type BFD_RELOC_64
as: pr64716.o: unsupported relocation type: 0x1
pr64716.s:6017: Error: cannot represent relocation type BFD_RELOC_64
So yes, we can either do a sorry, error, or could just avoid 64-bit
relocations (depending on endianity instead of emitting
.quad expression_that_needs_relocation
emit
.long expression_that_needs_relocation, 0
or
.long 0, expression_that_needs_relocation
So, which way do we want to go?

> Do dwarf32 and dwarf64 objects inter-operate just fine (as long as
> the linker can resolve all relocations w/o truncating)?

I think it should, but whether all debug info consumers and other tools
will be able to cope with it remains to be seen.  If they have bugs, those
should be fixed.  By adding the -gdwarf{32,64} switches we allow them to try
that.

	Jakub
Richard Biener Dec. 1, 2020, 12:03 p.m. UTC | #3
On Tue, 1 Dec 2020, Jakub Jelinek wrote:

> On Tue, Dec 01, 2020 at 11:49:43AM +0100, Richard Biener wrote:
> > On Tue, 1 Dec 2020, Jakub Jelinek wrote:
> > 
> > > Hi!
> > > 
> > > The following patch makes the choice between 32-bit and 64-bit DWARF formats
> > > selectable by command line switch, rather than being hardcoded through
> > > DWARF_OFFSET_SIZE macro.
> > > 
> > > The options themselves don't turn on debug info themselves, so one needs
> > > to use -g -gdwarf64 or similar.
> > > 
> > > Ok for trunk if it passes bootstrap/regtest?
> > 
> > OK.  Note there's
> > 
> > /* Various DIE's use offsets relative to the beginning of the
> >    .debug_info section to refer to each other.  */
> > 
> > typedef long int dw_offset;
> > 
> > which on L32 hosts means we might not support dwarf64 generation
> > for CUs that do not fit in 31bits?  Should we change that to
> > int64_t?  Or should we sorry() for -gdwarf64 on 32bit hosts?
> > 
> > There's also
> > 
> >   unsigned long die_abbrev;
> > 
> > and other uses of '[unsigned] long' in dwarf2out.c.
> 
> One thing is 32-bit hosts vs. 64-bit targets, and we maybe should indeed use
> HOST_WIDE_INT for dw_offset; not sure about die_abbrev, if the .debug_abbrev
> section is over 4GiB in one TU, then that would be already massive amounts of debug
> info (.debug_info is typically 10-100x times larger than .debug_abbrev).
> Even the HOST_WIDE_INT dw_offset might not be immediately necessary, if a
> 32-bit host needs to emit 4GiB of .debug_info for one TU, then I'm pretty
> sure we need at least 4 times that much of compile memory if not much more,
> our in memory DIE representation isn't exactly compact.
> The advantage of DWARF 64-bit is not (at least for the time being) a single
> TU exceeding the limits, but when linking a shared library with tons of TUs
> where we exceed those limits then (for some large libraries we are already
> close to those limits or over them now).
> 
> Another thing is 32-bit targets.  For them the limitations of the object
> file format (e.g. 32-bit ELF) will not allow > 2GiB debug info anyway,
> and as I've just tested, e.g. on x86_64 with -m32 -gdwarf64 will not work
> even on tiny testcases:
> as: pr64716.o: unsupported relocation type: 0x1
> pr64716.s: Assembler messages:
> pr64716.s:6013: Error: cannot represent relocation type BFD_RELOC_64
> as: pr64716.o: unsupported relocation type: 0x1
> pr64716.s:6015: Error: cannot represent relocation type BFD_RELOC_64
> as: pr64716.o: unsupported relocation type: 0x1
> pr64716.s:6017: Error: cannot represent relocation type BFD_RELOC_64
> So yes, we can either do a sorry, error, or could just avoid 64-bit
> relocations (depending on endianity instead of emitting
> .quad expression_that_needs_relocation
> emit
> .long expression_that_needs_relocation, 0
> or
> .long 0, expression_that_needs_relocation
> So, which way do we want to go?

64bit relocs are not required here?  That is, can one with
dwarf64 choose 32bit forms for select offsets (like could
dwz exploit this?)?

If so the above might be OK, otherwise I guess a sorry()
would be more to the point.

> > Do dwarf32 and dwarf64 objects inter-operate just fine (as long as
> > the linker can resolve all relocations w/o truncating)?
> 
> I think it should, but whether all debug info consumers and other tools
> will be able to cope with it remains to be seen.  If they have bugs, those
> should be fixed.  By adding the -gdwarf{32,64} switches we allow them to try
> that.
> 
> 	Jakub
> 
>
Jakub Jelinek Dec. 1, 2020, 12:48 p.m. UTC | #4
On Tue, Dec 01, 2020 at 01:03:07PM +0100, Richard Biener wrote:
> > So yes, we can either do a sorry, error, or could just avoid 64-bit
> > relocations (depending on endianity instead of emitting
> > .quad expression_that_needs_relocation
> > emit
> > .long expression_that_needs_relocation, 0
> > or
> > .long 0, expression_that_needs_relocation
> > So, which way do we want to go?
> 
> 64bit relocs are not required here?  That is, can one with
> dwarf64 choose 32bit forms for select offsets (like could
> dwz exploit this?)?

I guess it depends on whether for 32-bit target and -gdwarf64, when
calling dw2_assemble_integer with non-CONST_INT argument we only
need positive values or might need negative ones too.
Because positive ones can be easily emulated through that
.long expression, 0
or
.long 0, expression
depending on endianity, but I'm afraid there is no way to emit
0 or -1 depending on the sign of expression, when it needs relocations.
Looking through dw2_asm_output_delta calls, at least the vast majority
of the calls seem to guarantee being positive, not 100% sure about
one case in .debug_line views, but I'd hope it is ok too.
In most cases, the deltas are between two labels where the first one
in the arguments is later in the same section than the other one,
or where the second argument is the start of a section or another section
base.

This patch implements that, dunno if we need also configure tests for that
or not, maybe some 32-bit targets use 64-bit ELF and can handle such
relocations.

2020-12-01  Jakub Jelinek  <jakub@redhat.com>

	* dwarf2asm.c (dw2_assemble_integer): Handle size twice as large
	as DWARF2_ADDR_SIZE if x is not a scalar int by emitting it as
	two halves, one with x and the other with const0_rtx, ordered
	depending on endianity.

--- gcc/dwarf2asm.c.jj	2020-01-12 11:54:36.558411221 +0100
+++ gcc/dwarf2asm.c	2020-12-01 13:42:38.347298352 +0100
@@ -46,6 +46,52 @@ along with GCC; see the file COPYING3.
 void
 dw2_assemble_integer (int size, rtx x)
 {
+  if (size == 2 * DWARF2_ADDR_SIZE && !CONST_SCALAR_INT_P (x))
+    {
+      /* On 32-bit targets with -gdwarf64, DImode values with
+	 relocations usually result in assembler errors.  Assume
+	 all such values are positive and emit the relocation only
+	 in the least significant half.  */
+      const char *op = integer_asm_op (DWARF2_ADDR_SIZE, FALSE);
+      if (BYTES_BIG_ENDIAN)
+	{
+	  if (op)
+	    {
+	      fputs (op, asm_out_file);
+	      fprint_whex (asm_out_file, 0);
+	      fputs (", ", asm_out_file);
+	      output_addr_const (asm_out_file, x);
+	    }
+	  else
+	    {
+	      assemble_integer (const0_rtx, DWARF2_ADDR_SIZE,
+				BITS_PER_UNIT, 1);
+	      putc ('\n', asm_out_file);
+	      assemble_integer (x, DWARF2_ADDR_SIZE,
+				BITS_PER_UNIT, 1);
+	    }
+	}
+      else
+	{
+	  if (op)
+	    {
+	      fputs (op, asm_out_file);
+	      output_addr_const (asm_out_file, x);
+	      fputs (", ", asm_out_file);
+	      fprint_whex (asm_out_file, 0);
+	    }
+	  else
+	    {
+	      assemble_integer (x, DWARF2_ADDR_SIZE,
+				BITS_PER_UNIT, 1);
+	      putc ('\n', asm_out_file);
+	      assemble_integer (const0_rtx, DWARF2_ADDR_SIZE,
+				BITS_PER_UNIT, 1);
+	    }
+	}
+      return;
+    }
+
   const char *op = integer_asm_op (size, FALSE);
 
   if (op)


	Jakub
Jakub Jelinek Dec. 2, 2020, 1 p.m. UTC | #5
On Tue, Dec 01, 2020 at 01:48:31PM +0100, Jakub Jelinek via Gcc-patches wrote:
> I guess it depends on whether for 32-bit target and -gdwarf64, when
> calling dw2_assemble_integer with non-CONST_INT argument we only
> need positive values or might need negative ones too.
> Because positive ones can be easily emulated through that
> .long expression, 0
> or
> .long 0, expression
> depending on endianity, but I'm afraid there is no way to emit
> 0 or -1 depending on the sign of expression, when it needs relocations.
> Looking through dw2_asm_output_delta calls, at least the vast majority
> of the calls seem to guarantee being positive, not 100% sure about
> one case in .debug_line views, but I'd hope it is ok too.
> In most cases, the deltas are between two labels where the first one
> in the arguments is later in the same section than the other one,
> or where the second argument is the start of a section or another section
> base.

I went through dwarf2out.c dw2_asm_output_delta calls and I'm fairly
confident all of them are ok, represent sizes of .debug* sections or their
portions, or differences between symbols in the same section where the x
in x - y is later than y in the section (what I was worried about, something
like:
.text
.L1:
	...
.L2:
...
	.quad .L1 - .L2
doesn't appear to happen.
Additionally, seems the x32 ABI I've been worried about uses ELF32 rather
than ELF64, so it must suffer from the same limitation, if address size is
32-bit, one can't apply 64-bit relocations.

Patch has been bootstrapped/regtested on x86_64-linux and i686-linux.
Ok for trunk together with the -gdwarf{32,64} patch?

> 2020-12-01  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* dwarf2asm.c (dw2_assemble_integer): Handle size twice as large
> 	as DWARF2_ADDR_SIZE if x is not a scalar int by emitting it as
> 	two halves, one with x and the other with const0_rtx, ordered
> 	depending on endianity.

	Jakub
diff mbox series

Patch

--- gcc/common.opt.jj	2020-11-26 01:14:47.444082913 +0100
+++ gcc/common.opt	2020-12-01 11:07:33.088093473 +0100
@@ -3178,6 +3178,14 @@  gdwarf-
 Common Driver Joined UInteger Var(dwarf_version) Init(4) Negative(gstabs)
 Generate debug information in DWARF v2 (or later) format.
 
+gdwarf32
+Common Driver Var(dwarf_offset_size,4) Init(4) RejectNegative
+Use 32-bit DWARF format when emitting DWARF debug information.
+
+gdwarf64
+Common Driver Var(dwarf_offset_size,8) RejectNegative
+Use 64-bit DWARF format when emitting DWARF debug information.
+
 ggdb
 Common Driver JoinedOrMissing
 Generate debug information in default extended format.
--- gcc/config/rs6000/rs6000.c.jj	2020-11-27 11:20:53.484334843 +0100
+++ gcc/config/rs6000/rs6000.c	2020-12-01 11:12:31.618731395 +0100
@@ -3863,6 +3863,12 @@  rs6000_option_override_internal (bool gl
   if (TARGET_DEBUG_REG || TARGET_DEBUG_TARGET)
     rs6000_print_isa_options (stderr, 0, "before defaults", rs6000_isa_flags);
 
+#ifdef XCOFF_DEBUGGING_INFO
+  /* For AIX default to 64-bit DWARF.  */
+  if (!global_options_set.x_dwarf_offset_size)
+    dwarf_offset_size = 8;
+#endif
+
   /* Handle explicit -mno-{altivec,vsx,power8-vector,power9-vector} and turn
      off all of the options that depend on those flags.  */
   ignore_masks = rs6000_disable_incompatible_switches ();
--- gcc/dwarf2out.c.jj	2020-12-01 09:41:07.223490914 +0100
+++ gcc/dwarf2out.c	2020-12-01 11:03:04.692115667 +0100
@@ -182,14 +182,14 @@  static GTY(()) section *debug_frame_sect
    bytes.
 
    However, the SGI/MIPS ABI uses an initial length which is equal to
-   DWARF_OFFSET_SIZE.  It is defined (elsewhere) accordingly.  */
+   dwarf_offset_size.  It is defined (elsewhere) accordingly.  */
 
 #ifndef DWARF_INITIAL_LENGTH_SIZE
-#define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
+#define DWARF_INITIAL_LENGTH_SIZE (dwarf_offset_size == 4 ? 4 : 12)
 #endif
 
 #ifndef DWARF_INITIAL_LENGTH_SIZE_STR
-#define DWARF_INITIAL_LENGTH_SIZE_STR (DWARF_OFFSET_SIZE == 4 ? "-4" : "-12")
+#define DWARF_INITIAL_LENGTH_SIZE_STR (dwarf_offset_size == 4 ? "-4" : "-12")
 #endif
 
 /* Round SIZE up to the nearest BOUNDARY.  */
@@ -199,7 +199,7 @@  static GTY(()) section *debug_frame_sect
 /* CIE identifier.  */
 #if HOST_BITS_PER_WIDE_INT >= 64
 #define DWARF_CIE_ID \
-  (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
+  (unsigned HOST_WIDE_INT) (dwarf_offset_size == 4 ? DW_CIE_ID : DW64_CIE_ID)
 #else
 #define DWARF_CIE_ID DW_CIE_ID
 #endif
@@ -287,8 +287,8 @@  static GTY(()) bool do_eh_frame = false;
 static unsigned int rnglist_idx;
 
 /* Data and reference forms for relocatable data.  */
-#define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
-#define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
+#define DW_FORM_data (dwarf_offset_size == 8 ? DW_FORM_data8 : DW_FORM_data4)
+#define DW_FORM_ref (dwarf_offset_size == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
 
 #ifndef DEBUG_FRAME_SECTION
 #define DEBUG_FRAME_SECTION	".debug_frame"
@@ -602,10 +602,10 @@  output_fde (dw_fde_ref fde, bool for_eh,
   ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
   if (!XCOFF_DEBUGGING_INFO || for_eh)
     {
-      if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
+      if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4 && !for_eh)
 	dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
 			     " indicating 64-bit DWARF extension");
-      dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
+      dw2_asm_output_delta (for_eh ? 4 : dwarf_offset_size, l2, l1,
 			    "FDE Length");
     }
   ASM_OUTPUT_LABEL (asm_out_file, l1);
@@ -613,7 +613,7 @@  output_fde (dw_fde_ref fde, bool for_eh,
   if (for_eh)
     dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
   else
-    dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
+    dw2_asm_output_offset (dwarf_offset_size, section_start_label,
 			   debug_frame_section, "FDE CIE offset");
 
   begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
@@ -806,17 +806,17 @@  output_call_frame_info (int for_eh)
   ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
   if (!XCOFF_DEBUGGING_INFO || for_eh)
     {
-      if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
+      if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4 && !for_eh)
 	dw2_asm_output_data (4, 0xffffffff,
 	  "Initial length escape value indicating 64-bit DWARF extension");
-      dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
+      dw2_asm_output_delta (for_eh ? 4 : dwarf_offset_size, l2, l1,
 			    "Length of Common Information Entry");
     }
   ASM_OUTPUT_LABEL (asm_out_file, l1);
 
   /* Now that the CIE pointer is PC-relative for EH,
      use 0 to identify the CIE.  */
-  dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
+  dw2_asm_output_data ((for_eh ? 4 : dwarf_offset_size),
 		       (for_eh ? 0 : DWARF_CIE_ID),
 		       "CIE Identifier Tag");
 
@@ -1623,7 +1623,7 @@  loc_list_plus_const (dw_loc_list_ref lis
 }
 
 #define DWARF_REF_SIZE	\
-  (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
+  (dwarf_version == 2 ? DWARF2_ADDR_SIZE : dwarf_offset_size)
 
 /* The number of bits that can be encoded by largest DW_FORM_dataN.
    In DWARF4 and earlier it is DW_FORM_data8 with 64 bits, in DWARF5
@@ -3229,33 +3229,33 @@  skeleton_chain_node;
 
 /* Fixed size portion of the DWARF compilation unit header.  */
 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
-  (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE			\
+  (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size			\
    + (dwarf_version >= 5 ? 4 : 3))
 
 /* Fixed size portion of the DWARF comdat type unit header.  */
 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
   (DWARF_COMPILE_UNIT_HEADER_SIZE					\
-   + DWARF_TYPE_SIGNATURE_SIZE + DWARF_OFFSET_SIZE)
+   + DWARF_TYPE_SIGNATURE_SIZE + dwarf_offset_size)
 
 /* Fixed size portion of the DWARF skeleton compilation unit header.  */
 #define DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE \
   (DWARF_COMPILE_UNIT_HEADER_SIZE + (dwarf_version >= 5 ? 8 : 0))
 
 /* Fixed size portion of public names info.  */
-#define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
+#define DWARF_PUBNAMES_HEADER_SIZE (2 * dwarf_offset_size + 2)
 
 /* Fixed size portion of the address range info.  */
 #define DWARF_ARANGES_HEADER_SIZE					\
-  (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4,	\
+  (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4,	\
 		DWARF2_ADDR_SIZE * 2)					\
    - DWARF_INITIAL_LENGTH_SIZE)
 
 /* Size of padding portion in the address range info.  It must be
    aligned to twice the pointer size.  */
 #define DWARF_ARANGES_PAD_SIZE \
-  (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
+  (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4, \
 		DWARF2_ADDR_SIZE * 2)				   \
-   - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
+   - (DWARF_INITIAL_LENGTH_SIZE + dwarf_offset_size + 4))
 
 /* Use assembler line directives if available.  */
 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
@@ -4787,7 +4787,7 @@  find_string_form (struct indirect_string
 
   /* If the string is shorter or equal to the size of the reference, it is
      always better to put it inline.  */
-  if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
+  if (len <= (unsigned) dwarf_offset_size || node->refcount == 0)
     return node->form = DW_FORM_string;
 
   /* If we cannot expect the linker to merge strings in .debug_str
@@ -4795,7 +4795,7 @@  find_string_form (struct indirect_string
      single module.  */
   if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
       || ((debug_str_section->common.flags & SECTION_MERGE) == 0
-	  && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
+	  && (len - dwarf_offset_size) * node->refcount <= len))
     return node->form = DW_FORM_string;
 
   set_indirect_string (node);
@@ -8892,7 +8892,7 @@  output_loclists_offsets (dw_die_ref die)
 	dw_loc_list_ref l = AT_loc_list (a);
 	if (l->offset_emitted)
 	  continue;
-	dw2_asm_output_delta (DWARF_OFFSET_SIZE, l->ll_symbol,
+	dw2_asm_output_delta (dwarf_offset_size, l->ll_symbol,
 			      loc_section_label, NULL);
 	gcc_assert (l->hash == loc_list_idx);
 	loc_list_idx++;
@@ -9400,7 +9400,7 @@  size_of_die (dw_die_ref die)
             size += DWARF2_ADDR_SIZE;
 	  break;
 	case dw_val_class_offset:
-	  size += DWARF_OFFSET_SIZE;
+	  size += dwarf_offset_size;
 	  break;
 	case dw_val_class_loc:
 	  {
@@ -9421,10 +9421,10 @@  size_of_die (dw_die_ref die)
 	      size += size_of_uleb128 (AT_loc_list (a)->hash);
 	    }
           else
-            size += DWARF_OFFSET_SIZE;
+            size += dwarf_offset_size;
 	  break;
 	case dw_val_class_view_list:
-	  size += DWARF_OFFSET_SIZE;
+	  size += dwarf_offset_size;
 	  break;
 	case dw_val_class_range_list:
 	  if (value_format (a) == DW_FORM_rnglistx)
@@ -9434,7 +9434,7 @@  size_of_die (dw_die_ref die)
 	      size += size_of_uleb128 (r->idx);
 	    }
 	  else
-	    size += DWARF_OFFSET_SIZE;
+	    size += dwarf_offset_size;
 	  break;
 	case dw_val_class_const:
 	  size += size_of_sleb128 (AT_int (a));
@@ -9508,13 +9508,13 @@  size_of_die (dw_die_ref die)
 	      else if (dwarf_version == 2)
 		size += DWARF2_ADDR_SIZE;
 	      else
-		size += DWARF_OFFSET_SIZE;
+		size += dwarf_offset_size;
 	    }
 	  else
-	    size += DWARF_OFFSET_SIZE;
+	    size += dwarf_offset_size;
 	  break;
 	case dw_val_class_fde_ref:
-	  size += DWARF_OFFSET_SIZE;
+	  size += dwarf_offset_size;
 	  break;
 	case dw_val_class_lbl_id:
           if (dwarf_split_debug_info && AT_index (a) != NOT_INDEXED)
@@ -9528,12 +9528,12 @@  size_of_die (dw_die_ref die)
 	case dw_val_class_lineptr:
 	case dw_val_class_macptr:
 	case dw_val_class_loclistsptr:
-	  size += DWARF_OFFSET_SIZE;
+	  size += dwarf_offset_size;
 	  break;
 	case dw_val_class_str:
           form = AT_string_form (a);
 	  if (form == DW_FORM_strp || form == DW_FORM_line_strp)
-	    size += DWARF_OFFSET_SIZE;
+	    size += dwarf_offset_size;
 	  else if (form == dwarf_FORM (DW_FORM_strx))
 	    size += size_of_uleb128 (AT_index (a));
 	  else
@@ -9546,7 +9546,7 @@  size_of_die (dw_die_ref die)
 	  size += 8;
 	  break;
 	case dw_val_class_vms_delta:
-	  size += DWARF_OFFSET_SIZE;
+	  size += dwarf_offset_size;
 	  break;
 	case dw_val_class_high_pc:
 	  size += DWARF2_ADDR_SIZE;
@@ -9724,9 +9724,9 @@  size_of_pubnames (vec<pubname_entry, va_
   size = DWARF_PUBNAMES_HEADER_SIZE;
   FOR_EACH_VEC_ELT (*names, i, p)
     if (include_pubname_in_output (names, p))
-      size += strlen (p->name) + DWARF_OFFSET_SIZE + 1 + space_for_flags;
+      size += strlen (p->name) + dwarf_offset_size + 1 + space_for_flags;
 
-  size += DWARF_OFFSET_SIZE;
+  size += dwarf_offset_size;
   return size;
 }
 
@@ -9823,7 +9823,7 @@  value_format (dw_attr_node *a)
       /* FALLTHRU */
     case dw_val_class_vms_delta:
     case dw_val_class_offset:
-      switch (DWARF_OFFSET_SIZE)
+      switch (dwarf_offset_size)
 	{
 	case 4:
 	  return DW_FORM_data4;
@@ -10525,7 +10525,7 @@  output_range_list_offset (dw_attr_node *
       if (dwarf_version >= 5)
 	{
 	  dw_ranges *r = &(*ranges_table)[a->dw_attr_val.v.val_offset];
-	  dw2_asm_output_offset (DWARF_OFFSET_SIZE, r->label,
+	  dw2_asm_output_offset (dwarf_offset_size, r->label,
 				 debug_ranges_section, "%s", name);
 	}
       else
@@ -10533,7 +10533,7 @@  output_range_list_offset (dw_attr_node *
 	  char *p = strchr (ranges_section_label, '\0');
 	  sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
 		   a->dw_attr_val.v.val_offset * 2 * DWARF2_ADDR_SIZE);
-	  dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
+	  dw2_asm_output_offset (dwarf_offset_size, ranges_section_label,
 				 debug_ranges_section, "%s", name);
 	  *p = '\0';
 	}
@@ -10545,7 +10545,7 @@  output_range_list_offset (dw_attr_node *
       dw2_asm_output_data_uleb128 (r->idx, "%s", name);
     }
   else
-    dw2_asm_output_data (DWARF_OFFSET_SIZE,
+    dw2_asm_output_data (dwarf_offset_size,
 			 a->dw_attr_val.v.val_offset * 2 * DWARF2_ADDR_SIZE,
                          "%s (offset from %s)", name, ranges_section_label);
 }
@@ -10559,7 +10559,7 @@  output_loc_list_offset (dw_attr_node *a)
 
   gcc_assert (sym);
   if (!dwarf_split_debug_info)
-    dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
+    dw2_asm_output_offset (dwarf_offset_size, sym, debug_loc_section,
                            "%s", dwarf_attr_name (a->dw_attr));
   else if (dwarf_version >= 5)
     {
@@ -10569,7 +10569,7 @@  output_loc_list_offset (dw_attr_node *a)
 				   sym);
     }
   else
-    dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, loc_section_label,
+    dw2_asm_output_delta (dwarf_offset_size, sym, loc_section_label,
 			  "%s", dwarf_attr_name (a->dw_attr));
 }
 
@@ -10582,10 +10582,10 @@  output_view_list_offset (dw_attr_node *a
 
   gcc_assert (sym);
   if (dwarf_split_debug_info)
-    dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, loc_section_label,
+    dw2_asm_output_delta (dwarf_offset_size, sym, loc_section_label,
                           "%s", dwarf_attr_name (a->dw_attr));
   else
-    dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
+    dw2_asm_output_offset (dwarf_offset_size, sym, debug_loc_section,
                            "%s", dwarf_attr_name (a->dw_attr));
 }
 
@@ -10663,7 +10663,7 @@  output_die (dw_die_ref die)
 	  break;
 
 	case dw_val_class_offset:
-	  dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
+	  dw2_asm_output_data (dwarf_offset_size, a->dw_attr_val.v.val_offset,
 			       "%s", name);
 	  break;
 
@@ -10857,7 +10857,7 @@  output_die (dw_die_ref die)
 		  if (dwarf_version == 2)
 		    size = DWARF2_ADDR_SIZE;
 		  else
-		    size = DWARF_OFFSET_SIZE;
+		    size = dwarf_offset_size;
 		  /* ???  We cannot unconditionally output die_offset if
 		     non-zero - others might create references to those
 		     DIEs via symbols.
@@ -10877,7 +10877,7 @@  output_die (dw_die_ref die)
 	  else
 	    {
 	      gcc_assert (AT_ref (a)->die_offset);
-	      dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
+	      dw2_asm_output_data (dwarf_offset_size, AT_ref (a)->die_offset,
 				   "%s", name);
 	    }
 	  break;
@@ -10888,18 +10888,18 @@  output_die (dw_die_ref die)
 
 	    ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
 					 a->dw_attr_val.v.val_fde_index * 2);
-	    dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
+	    dw2_asm_output_offset (dwarf_offset_size, l1, debug_frame_section,
 				   "%s", name);
 	  }
 	  break;
 
 	case dw_val_class_vms_delta:
 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
-	  dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
+	  dw2_asm_output_vms_delta (dwarf_offset_size,
 				    AT_vms_delta2 (a), AT_vms_delta1 (a),
 				    "%s", name);
 #else
-	  dw2_asm_output_delta (DWARF_OFFSET_SIZE,
+	  dw2_asm_output_delta (dwarf_offset_size,
 				AT_vms_delta2 (a), AT_vms_delta1 (a),
 				"%s", name);
 #endif
@@ -10910,28 +10910,28 @@  output_die (dw_die_ref die)
 	  break;
 
 	case dw_val_class_lineptr:
-	  dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
+	  dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
 				 debug_line_section, "%s", name);
 	  break;
 
 	case dw_val_class_macptr:
-	  dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
+	  dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
 				 debug_macinfo_section, "%s", name);
 	  break;
 
 	case dw_val_class_loclistsptr:
-	  dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
+	  dw2_asm_output_offset (dwarf_offset_size, AT_lbl (a),
 				 debug_loc_section, "%s", name);
 	  break;
 
 	case dw_val_class_str:
           if (a->dw_attr_val.v.val_str->form == DW_FORM_strp)
-            dw2_asm_output_offset (DWARF_OFFSET_SIZE,
+            dw2_asm_output_offset (dwarf_offset_size,
                                    a->dw_attr_val.v.val_str->label,
                                    debug_str_section,
                                    "%s: \"%s\"", name, AT_string (a));
 	  else if (a->dw_attr_val.v.val_str->form == DW_FORM_line_strp)
-	    dw2_asm_output_offset (DWARF_OFFSET_SIZE,
+	    dw2_asm_output_offset (dwarf_offset_size,
 				   a->dw_attr_val.v.val_str->label,
 				   debug_line_str_section,
 				   "%s: \"%s\"", name, AT_string (a));
@@ -11048,10 +11048,10 @@  output_compilation_unit_header (enum dwa
 {
   if (!XCOFF_DEBUGGING_INFO)
     {
-      if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
+      if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
 	dw2_asm_output_data (4, 0xffffffff,
 	  "Initial length escape value indicating 64-bit DWARF extension");
-      dw2_asm_output_data (DWARF_OFFSET_SIZE,
+      dw2_asm_output_data (dwarf_offset_size,
 			   next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
 			   "Length of Compilation Unit Info");
     }
@@ -11071,7 +11071,7 @@  output_compilation_unit_header (enum dwa
       dw2_asm_output_data (1, ut, "%s", name);
       dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
     }
-  dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
+  dw2_asm_output_offset (dwarf_offset_size, abbrev_section_label,
 			 debug_abbrev_section,
 			 "Offset Into Abbrev. Section");
   if (dwarf_version < 5)
@@ -11261,12 +11261,12 @@  output_skeleton_debug_sections (dw_die_r
   /* Produce the skeleton compilation-unit header.  This one differs enough from
      a normal CU header that it's better not to call output_compilation_unit
      header.  */
-  if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
+  if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
     dw2_asm_output_data (4, 0xffffffff,
 			 "Initial length escape value indicating 64-bit "
 			 "DWARF extension");
 
-  dw2_asm_output_data (DWARF_OFFSET_SIZE,
+  dw2_asm_output_data (dwarf_offset_size,
 		       DWARF_COMPILE_UNIT_SKELETON_HEADER_SIZE
                        - DWARF_INITIAL_LENGTH_SIZE
                        + size_of_die (comp_unit),
@@ -11277,7 +11277,7 @@  output_skeleton_debug_sections (dw_die_r
       dw2_asm_output_data (1, DW_UT_skeleton, "DW_UT_skeleton");
       dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
     }
-  dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_abbrev_section_label,
+  dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_abbrev_section_label,
 			 debug_skeleton_abbrev_section,
                          "Offset Into Abbrev. Section");
   if (dwarf_version < 5)
@@ -11362,7 +11362,7 @@  output_comdat_type_unit (comdat_type_nod
   output_compilation_unit_header (dwarf_split_debug_info
 				  ? DW_UT_split_type : DW_UT_type);
   output_signature (node->signature, "Type Signature");
-  dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
+  dw2_asm_output_data (dwarf_offset_size, node->type_die->die_offset,
 		       "Offset to Type DIE");
   output_die (node->root_die);
 
@@ -11491,7 +11491,7 @@  output_pubname (dw_offset die_offset, pu
   dw_die_ref die = entry->die;
   int is_static = get_AT_flag (die, DW_AT_external) ? 0 : 1;
 
-  dw2_asm_output_data (DWARF_OFFSET_SIZE, die_offset, "DIE offset");
+  dw2_asm_output_data (dwarf_offset_size, die_offset, "DIE offset");
 
   if (debug_generate_pub_sections == 2)
     {
@@ -11565,10 +11565,10 @@  output_pubnames (vec<pubname_entry, va_g
 
   if (!XCOFF_DEBUGGING_INFO)
     {
-      if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
+      if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
 	dw2_asm_output_data (4, 0xffffffff,
 	  "Initial length escape value indicating 64-bit DWARF extension");
-      dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
+      dw2_asm_output_data (dwarf_offset_size, pubnames_length,
 			   "Pub Info Length");
     }
 
@@ -11576,14 +11576,14 @@  output_pubnames (vec<pubname_entry, va_g
   dw2_asm_output_data (2, 2, "DWARF pubnames/pubtypes version");
 
   if (dwarf_split_debug_info)
-    dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_info_section_label,
+    dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_info_section_label,
                            debug_skeleton_info_section,
                            "Offset of Compilation Unit Info");
   else
-    dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
+    dw2_asm_output_offset (dwarf_offset_size, debug_info_section_label,
                            debug_info_section,
                            "Offset of Compilation Unit Info");
-  dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
+  dw2_asm_output_data (dwarf_offset_size, next_die_offset,
 		       "Compilation Unit Length");
 
   FOR_EACH_VEC_ELT (*names, i, pub)
@@ -11614,7 +11614,7 @@  output_pubnames (vec<pubname_entry, va_g
 	}
     }
 
-  dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
+  dw2_asm_output_data (dwarf_offset_size, 0, NULL);
 }
 
 /* Output public names and types tables if necessary.  */
@@ -11647,21 +11647,21 @@  output_aranges (void)
   
   if (!XCOFF_DEBUGGING_INFO)
     {
-      if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
+      if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
 	dw2_asm_output_data (4, 0xffffffff,
 	  "Initial length escape value indicating 64-bit DWARF extension");
-      dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
+      dw2_asm_output_data (dwarf_offset_size, aranges_length,
 			   "Length of Address Ranges Info");
     }
 
   /* Version number for aranges is still 2, even up to DWARF5.  */
   dw2_asm_output_data (2, 2, "DWARF aranges version");
   if (dwarf_split_debug_info)
-    dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_info_section_label,
+    dw2_asm_output_offset (dwarf_offset_size, debug_skeleton_info_section_label,
                            debug_skeleton_info_section,
                            "Offset of Compilation Unit Info");
   else
-    dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
+    dw2_asm_output_offset (dwarf_offset_size, debug_info_section_label,
                            debug_info_section,
                            "Offset of Compilation Unit Info");
   dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
@@ -11936,11 +11936,11 @@  output_rnglists (unsigned generation)
 			       2 + generation * 4);
   ASM_GENERATE_INTERNAL_LABEL (l2, DEBUG_RANGES_SECTION_LABEL,
 			       3 + generation * 4);
-  if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
+  if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
     dw2_asm_output_data (4, 0xffffffff,
 			 "Initial length escape value indicating "
 			 "64-bit DWARF extension");
-  dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
+  dw2_asm_output_delta (dwarf_offset_size, l2, l1,
 			"Length of Range Lists");
   ASM_OUTPUT_LABEL (asm_out_file, l1);
   output_dwarf_version ();
@@ -11959,7 +11959,7 @@  output_rnglists (unsigned generation)
       ASM_OUTPUT_LABEL (asm_out_file, ranges_base_label);
       FOR_EACH_VEC_SAFE_ELT (ranges_table, i, r)
 	if (r->label)
-	  dw2_asm_output_delta (DWARF_OFFSET_SIZE, r->label,
+	  dw2_asm_output_delta (dwarf_offset_size, r->label,
 				ranges_base_label, NULL);
     }
 
@@ -12219,7 +12219,7 @@  output_line_string (enum dwarf_form form
       node = find_AT_string_in_table (str, debug_line_str_hash);
       set_indirect_string (node);
       node->form = form;
-      dw2_asm_output_offset (DWARF_OFFSET_SIZE, node->label,
+      dw2_asm_output_offset (dwarf_offset_size, node->label,
 			     debug_line_str_section, "%s: %#x: \"%s\"",
 			     entry_kind, 0, node->str);
       break;
@@ -12728,10 +12728,10 @@  output_line_info (bool prologue_only)
 
   if (!XCOFF_DEBUGGING_INFO)
     {
-      if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
+      if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
 	dw2_asm_output_data (4, 0xffffffff,
 	  "Initial length escape value indicating 64-bit DWARF extension");
-      dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
+      dw2_asm_output_delta (dwarf_offset_size, l2, l1,
 			    "Length of Source Line Info");
     }
 
@@ -12743,7 +12743,7 @@  output_line_info (bool prologue_only)
       dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Address Size");
       dw2_asm_output_data (1, 0, "Segment Size");
     }
-  dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
+  dw2_asm_output_delta (dwarf_offset_size, p2, p1, "Prolog Length");
   ASM_OUTPUT_LABEL (asm_out_file, p1);
 
   /* Define the architecture-dependent minimum instruction length (in bytes).
@@ -28306,7 +28306,7 @@  output_macinfo_op (macinfo_entry *ref)
     case DW_MACINFO_undef:
       len = strlen (ref->info) + 1;
       if (!dwarf_strict
-	  && len > DWARF_OFFSET_SIZE
+	  && len > (size_t) dwarf_offset_size
 	  && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
 	  && (debug_str_section->common.flags & SECTION_MERGE) != 0)
 	{
@@ -28347,7 +28347,7 @@  output_macinfo_op (macinfo_entry *ref)
       dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
 				   (unsigned long) ref->lineno);
       if (node->form == DW_FORM_strp)
-        dw2_asm_output_offset (DWARF_OFFSET_SIZE, node->label,
+        dw2_asm_output_offset (dwarf_offset_size, node->label,
                                debug_str_section, "The macro: \"%s\"",
                                ref->info);
       else
@@ -28359,7 +28359,7 @@  output_macinfo_op (macinfo_entry *ref)
       ASM_GENERATE_INTERNAL_LABEL (label,
 				   DEBUG_MACRO_SECTION_LABEL,
 				   ref->lineno + macinfo_label_base);
-      dw2_asm_output_offset (DWARF_OFFSET_SIZE, label, NULL, NULL);
+      dw2_asm_output_offset (dwarf_offset_size, label, NULL, NULL);
       break;
     default:
       fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
@@ -28443,7 +28443,7 @@  optimize_macinfo_range (unsigned int idx
   /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum>  */
   grp_name = XALLOCAVEC (char, 4 + encoded_filename_len + linebuf_len + 1
 			 + 16 * 2 + 1);
-  memcpy (grp_name, DWARF_OFFSET_SIZE == 4 ? "wm4." : "wm8.", 4);
+  memcpy (grp_name, dwarf_offset_size == 4 ? "wm4." : "wm8.", 4);
   tail = grp_name + 4;
   if (encoded_filename_len)
     {
@@ -28514,7 +28514,7 @@  save_macinfo_strings (void)
           case DW_MACINFO_undef:
             len = strlen (ref->info) + 1;
             if (!dwarf_strict
-                && len > DWARF_OFFSET_SIZE
+                && len > (unsigned) dwarf_offset_size
                 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
                 && (debug_str_section->common.flags & SECTION_MERGE) != 0)
               set_indirect_string (find_AT_string (ref->info));
@@ -28567,11 +28567,11 @@  output_macinfo (const char *debug_line_l
     {
       dw2_asm_output_data (2, dwarf_version >= 5 ? 5 : 4,
 			   "DWARF macro version number");
-      if (DWARF_OFFSET_SIZE == 8)
+      if (dwarf_offset_size == 8)
 	dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
       else
 	dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
-      dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_line_label,
+      dw2_asm_output_offset (dwarf_offset_size, debug_line_label,
                              debug_line_section, NULL);
     }
 
@@ -28660,7 +28660,7 @@  output_macinfo (const char *debug_line_l
 	  ref->info = NULL;
 	  dw2_asm_output_data (2, dwarf_version >= 5 ? 5 : 4,
 			       "DWARF macro version number");
-	  if (DWARF_OFFSET_SIZE == 8)
+	  if (dwarf_offset_size == 8)
 	    dw2_asm_output_data (1, 1, "Flags: 64-bit");
 	  else
 	    dw2_asm_output_data (1, 0, "Flags: 32-bit");
@@ -28997,7 +28997,7 @@  output_index_string_offset (indirect_str
       /* Assert that this node has been assigned an index.  */
       gcc_assert (node->index != NO_INDEX_ASSIGNED
                   && node->index != NOT_INDEXED);
-      dw2_asm_output_data (DWARF_OFFSET_SIZE, *offset,
+      dw2_asm_output_data (dwarf_offset_size, *offset,
                            "indexed string 0x%x: %s", node->index, node->str);
       *offset += strlen (node->str) + 1;
     }
@@ -29091,11 +29091,11 @@  output_indirect_strings (void)
 
 	  debug_str_hash->traverse_noresize
 	    <unsigned int *, count_index_strings> (&last_idx);
-	  str_offsets_length = last_idx * DWARF_OFFSET_SIZE + 4;
-	  if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
+	  str_offsets_length = last_idx * dwarf_offset_size + 4;
+	  if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
 	    dw2_asm_output_data (4, 0xffffffff,
 				 "Escape value for 64-bit DWARF extension");
-	  dw2_asm_output_data (DWARF_OFFSET_SIZE, str_offsets_length,
+	  dw2_asm_output_data (dwarf_offset_size, str_offsets_length,
 			       "Length of string offsets unit");
 	  dw2_asm_output_data (2, 5, "DWARF string offsets version");
 	  dw2_asm_output_data (2, 0, "Header zero padding");
@@ -29185,10 +29185,10 @@  output_addr_table (void)
 	<unsigned int *, count_index_addrs> (&last_idx);
       addrs_length = last_idx * DWARF2_ADDR_SIZE + 4;
 
-      if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
+      if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
 	dw2_asm_output_data (4, 0xffffffff,
 			     "Escape value for 64-bit DWARF extension");
-      dw2_asm_output_data (DWARF_OFFSET_SIZE, addrs_length,
+      dw2_asm_output_data (dwarf_offset_size, addrs_length,
 			   "Length of Address Unit");
       dw2_asm_output_data (2, 5, "DWARF addr version");
       dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
@@ -31747,11 +31747,11 @@  dwarf2out_finish (const char *filename)
 	{
 	  ASM_GENERATE_INTERNAL_LABEL (l1, DEBUG_LOC_SECTION_LABEL, 2);
 	  ASM_GENERATE_INTERNAL_LABEL (l2, DEBUG_LOC_SECTION_LABEL, 3);
-	  if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
+	  if (DWARF_INITIAL_LENGTH_SIZE - dwarf_offset_size == 4)
 	    dw2_asm_output_data (4, 0xffffffff,
 				 "Initial length escape value indicating "
 				 "64-bit DWARF extension");
-	  dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
+	  dw2_asm_output_delta (dwarf_offset_size, l2, l1,
 			    "Length of Location Lists");
 	  ASM_OUTPUT_LABEL (asm_out_file, l1);
 	  output_dwarf_version ();
--- gcc/doc/invoke.texi.jj	2020-11-27 11:20:53.509334560 +0100
+++ gcc/doc/invoke.texi	2020-12-01 11:23:01.743634441 +0100
@@ -452,7 +452,7 @@  Objective-C and Objective-C++ Dialects}.
 -gstabs  -gstabs+  -gstrict-dwarf  -gno-strict-dwarf @gol
 -gas-loc-support  -gno-as-loc-support @gol
 -gas-locview-support  -gno-as-locview-support @gol
--gcolumn-info  -gno-column-info @gol
+-gcolumn-info  -gno-column-info  -gdwarf32  -gdwarf64 @gol
 -gstatement-frontiers  -gno-statement-frontiers @gol
 -gvariable-location-views  -gno-variable-location-views @gol
 -ginternal-reset-location-views  -gno-internal-reset-location-views @gol
@@ -9569,6 +9569,18 @@  information as possible into a separate
 debug information.  To be useful, this option requires a debugger capable of
 reading @file{.dwo} files.
 
+@item -gdwarf32
+@itemx -gdwarf64
+@opindex gdwarf32
+@opindex gdwarf64
+If DWARF debugging information is enabled, the @option{-gdwarf32} selects
+the 32-bit DWARF format and the @option{-gdwarf64} selects the 64-bit
+DWARF format.  The default is target specific, on most targets it is
+@option{-gdwarf32} though.  The 32-bit DWARF format is smaller, but
+can't support more than 2GiB of debug information in any of the DWARF
+debug information sections.  The 64-bit DWARF format allows larger debug
+information and might not be well supported by all consumers yet.
+
 @item -gdescribe-dies
 @opindex gdescribe-dies
 Add description attributes to some DWARF DIEs that have no name attribute,