This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

dwarf2 offsets vs program addresses


This clears up some confusion I introduced on March 2 wrt
offsets in debug information vs addresses in the program.

No one noticed the mistake so far because no platform currently
treats these differently in the assembly.  But I'm about to 
make the @secrel changes to IA-64 that HP/UX requires, and there
the difference does matter.


r~


        * dwarf2asm.c (dw2_asm_output_offset): Use ASM_OUTPUT_DWARF_OFFSET
        if provided by the target.
        (dw2_asm_output_pcrel): Likewise with ASM_OUTPUT_DWARF_PCREL.
        (dw2_asm_output_addr): New.
        * dwarf2asm.h (dw2_asm_output_addr): Declare.
        * dwarf2out.c (output_cfi): Use it for program addresses.
        (output_call_frame_info, output_die): Likewise.
        (output_aranges, output_line_info): Likewise.

Index: dwarf2asm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dwarf2asm.c,v
retrieving revision 1.2
diff -c -p -d -r1.2 dwarf2asm.c
*** dwarf2asm.c	2001/03/06 23:29:30	1.2
--- dwarf2asm.c	2001/03/16 01:10:25
*************** unaligned_integer_asm_op (size)
*** 91,96 ****
--- 91,98 ----
  }
  #endif /* UNALIGNED_INT_ASM_OP */
  
+ /* Output an immediate constant in a given size.  */
+ 
  void
  dw2_asm_output_data VPARAMS ((int size, unsigned HOST_WIDE_INT value,
  			      const char *comment, ...))
*************** dw2_asm_output_data VPARAMS ((int size, 
*** 127,132 ****
--- 129,140 ----
    va_end (ap);
  }
  
+ /* Output the difference between two symbols in a given size.  */
+ /* ??? There appear to be assemblers that do not like such
+    subtraction, but do support ASM_SET_OP.  It's unfortunately
+    impossible to do here, since the ASM_SET_OP for the difference
+    symbol must appear after both symbols are defined.  */
+ 
  void
  dw2_asm_output_delta VPARAMS ((int size, const char *lab1, const char *lab2,
  			       const char *comment, ...))
*************** dw2_asm_output_delta VPARAMS ((int size,
*** 169,174 ****
--- 177,188 ----
    va_end (ap);
  }
  
+ /* Output a section-relative reference to a label.  In general this
+    can only be done for debugging symbols.  E.g. on most targets with
+    the GNU linker, this is accomplished with a direct reference and
+    the knowledge that the debugging section will be placed at VMA 0.
+    Some targets have special relocations for this that we must use.  */
+ 
  void
  dw2_asm_output_offset VPARAMS ((int size, const char *label,
  			       const char *comment, ...))
*************** dw2_asm_output_offset VPARAMS ((int size
*** 188,199 ****
--- 202,217 ----
    comment = va_arg (ap, const char *);
  #endif
  
+ #ifdef ASM_OUTPUT_DWARF_OFFSET
+   ASM_OUTPUT_DWARF_OFFSET (asm_out_file, size, label);
+ #else
  #ifdef UNALIGNED_INT_ASM_OP
    fputs (unaligned_integer_asm_op (size), asm_out_file);
    assemble_name (asm_out_file, label);
  #else
    assemble_integer (gen_rtx_SYMBOL_REF (Pmode, label), size, 1);
  #endif
+ #endif
  
    if (flag_debug_asm && comment)
      {
*************** dw2_asm_output_offset VPARAMS ((int size
*** 205,210 ****
--- 223,231 ----
    va_end (ap);
  }
  
+ /* Output a self-relative reference to a label, possibly in a
+    different section or object file.  */
+ 
  void
  dw2_asm_output_pcrel VPARAMS ((int size, const char *label,
  			       const char *comment, ...))
*************** dw2_asm_output_pcrel VPARAMS ((int size,
*** 224,241 ****
    comment = va_arg (ap, const char *);
  #endif
  
  #ifdef UNALIGNED_INT_ASM_OP
    fputs (unaligned_integer_asm_op (size), asm_out_file);
- 
-   /* ??? This needs target conditionalization.  E.g. the solaris
-      assembler uses %r_disp32(label).  Others don't like "." and
-      we need to generate a temporary label here.  */
    assemble_name (asm_out_file, label);
    fputc ('-', asm_out_file);
    fputc ('.', asm_out_file);
  #else
    abort ();
  #endif
  
    if (flag_debug_asm && comment)
      {
--- 245,262 ----
    comment = va_arg (ap, const char *);
  #endif
  
+ #ifdef ASM_OUTPUT_DWARF_PCREL
+   ASM_OUTPUT_DWARF_PCREL (asm_out_file, size, label);
+ #else
  #ifdef UNALIGNED_INT_ASM_OP
    fputs (unaligned_integer_asm_op (size), asm_out_file);
    assemble_name (asm_out_file, label);
    fputc ('-', asm_out_file);
    fputc ('.', asm_out_file);
  #else
    abort ();
  #endif
+ #endif
  
    if (flag_debug_asm && comment)
      {
*************** dw2_asm_output_pcrel VPARAMS ((int size,
*** 246,251 ****
--- 267,312 ----
  
    va_end (ap);
  }
+ 
+ /* Output an absolute reference to a label.  */
+ 
+ void
+ dw2_asm_output_addr VPARAMS ((int size, const char *label,
+ 			      const char *comment, ...))
+ {
+ #ifndef ANSI_PROTOTYPES
+   int size;
+   const char *label;
+   const char *comment;
+ #endif
+   va_list ap;
+ 
+   VA_START (ap, comment);
+ 
+ #ifndef ANSI_PROTOTYPES
+   size = va_arg (ap, int);
+   label = va_arg (ap, const char *);
+   comment = va_arg (ap, const char *);
+ #endif
+ 
+ #ifdef UNALIGNED_INT_ASM_OP
+   fputs (unaligned_integer_asm_op (size), asm_out_file);
+   assemble_name (asm_out_file, label);
+ #else
+   assemble_integer (gen_rtx_SYMBOL_REF (Pmode, label), size, 1);
+ #endif
+ 
+   if (flag_debug_asm && comment)
+     {
+       fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START);
+       vfprintf (asm_out_file, comment, ap);
+     }
+   fputc ('\n', asm_out_file);
+ 
+   va_end (ap);
+ }
+ 
+ /* Similar, but use an RTX expression instead of a text label.  */
  
  void
  dw2_asm_output_addr_rtx VPARAMS ((int size, rtx addr,
Index: dwarf2asm.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dwarf2asm.h,v
retrieving revision 1.1
diff -c -p -d -r1.1 dwarf2asm.h
*** dwarf2asm.h	2001/03/03 02:17:04	1.1
--- dwarf2asm.h	2001/03/16 01:10:25
*************** extern void dw2_asm_output_pcrel	PARAMS 
*** 40,45 ****
--- 40,49 ----
  						 const char *, ...))
       /* ATTRIBUTE_PRINTF_3 */;
  
+ extern void dw2_asm_output_addr		PARAMS ((int, const char *,
+ 						 const char *, ...))
+      /* ATTRIBUTE_PRINTF_3 */;
+ 
  extern void dw2_asm_output_addr_rtx	PARAMS ((int, rtx,
  						 const char *, ...))
       /* ATTRIBUTE_PRINTF_3 */;
Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dwarf2out.c,v
retrieving revision 1.249
diff -c -p -d -r1.249 dwarf2out.c
*** dwarf2out.c	2001/03/10 16:33:56	1.249
--- dwarf2out.c	2001/03/16 01:10:25
*************** output_cfi (cfi, fde)
*** 1546,1553 ****
        switch (cfi->dw_cfi_opc)
  	{
  	case DW_CFA_set_loc:
! 	  dw2_asm_output_offset (DWARF2_ADDR_SIZE, 
! 				   cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
  	  break;
  	case DW_CFA_advance_loc1:
  	  dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
--- 1546,1553 ----
        switch (cfi->dw_cfi_opc)
  	{
  	case DW_CFA_set_loc:
! 	  dw2_asm_output_addr (DWARF2_ADDR_SIZE, 
! 			       cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
  	  break;
  	case DW_CFA_advance_loc1:
  	  dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
*************** output_call_frame_info (for_eh)
*** 1679,1686 ****
           trailing null) so the pointer is 4-byte aligned.  The Solaris ld
           can't handle unaligned relocs.  */
        dw2_asm_output_nstring ("eh", -1, "CIE Augmentation");
!       dw2_asm_output_offset (DWARF2_ADDR_SIZE, "__EXCEPTION_TABLE__",
! 			     "pointer to exception region info");
      }
    else
      {
--- 1679,1686 ----
           trailing null) so the pointer is 4-byte aligned.  The Solaris ld
           can't handle unaligned relocs.  */
        dw2_asm_output_nstring ("eh", -1, "CIE Augmentation");
!       dw2_asm_output_addr (DWARF2_ADDR_SIZE, "__EXCEPTION_TABLE__",
! 			   "pointer to exception region info");
      }
    else
      {
*************** output_call_frame_info (for_eh)
*** 1743,1750 ****
  			       stripattributes (FRAME_SECTION),
  			       "FDE CIE offset");
  
!       dw2_asm_output_offset (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
! 			     "FDE initial location");
  
        dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
  			    fde->dw_fde_begin, "FDE address range");
--- 1743,1750 ----
  			       stripattributes (FRAME_SECTION),
  			       "FDE CIE offset");
  
!       dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
! 			   "FDE initial location");
  
        dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
  			    fde->dw_fde_begin, "FDE address range");
*************** output_die (die)
*** 5724,5730 ****
  	  break;
  
  	case dw_val_class_lbl_id:
! 	  dw2_asm_output_offset (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
  	  break;
  
  	case dw_val_class_lbl_offset:
--- 5724,5730 ----
  	  break;
  
  	case dw_val_class_lbl_id:
! 	  dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
  	  break;
  
  	case dw_val_class_lbl_offset:
*************** output_aranges ()
*** 5938,5944 ****
  	dw2_asm_output_data (2, 0, NULL);
      }
  
!   dw2_asm_output_offset (DWARF2_ADDR_SIZE, text_section_label, "Address");
    dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
  			text_section_label, "Length");
  
--- 5938,5944 ----
  	dw2_asm_output_data (2, 0, NULL);
      }
  
!   dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
    dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
  			text_section_label, "Length");
  
*************** output_aranges ()
*** 5952,5958 ****
  
        if (die->die_tag == DW_TAG_subprogram)
  	{
! 	  dw2_asm_output_offset (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
  				 "Address");
  	  dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
  				get_AT_low_pc (die), "Length");
--- 5952,5958 ----
  
        if (die->die_tag == DW_TAG_subprogram)
  	{
! 	  dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
  				 "Address");
  	  dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
  				get_AT_low_pc (die), "Length");
*************** output_line_info ()
*** 6440,6446 ****
  	  dw2_asm_output_data (1, 0, "DW_LNE_set_address");
  	  dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
  	  dw2_asm_output_data (1, DW_LNE_set_address, NULL);
! 	  dw2_asm_output_offset (DWARF2_ADDR_SIZE, line_label, NULL);
  	}
        strcpy (prev_line_label, line_label);
  
--- 6440,6446 ----
  	  dw2_asm_output_data (1, 0, "DW_LNE_set_address");
  	  dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
  	  dw2_asm_output_data (1, DW_LNE_set_address, NULL);
! 	  dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
  	}
        strcpy (prev_line_label, line_label);
  
*************** output_line_info ()
*** 6451,6457 ****
  	  current_file = line_info->dw_file_num;
  	  dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
  	  dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
! 				       line_file_table.table[current_file]);
  	}
  
        /* Emit debug info for the current line number, choosing the encoding
--- 6451,6457 ----
  	  current_file = line_info->dw_file_num;
  	  dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
  	  dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
! 				       file_table.table[current_file]);
  	}
  
        /* Emit debug info for the current line number, choosing the encoding
*************** output_line_info ()
*** 6498,6504 ****
        dw2_asm_output_data (1, 0, "DW_LNE_set_address");
        dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
        dw2_asm_output_data (1, DW_LNE_set_address, NULL);
!       dw2_asm_output_offset (DWARF2_ADDR_SIZE, text_end_label, NULL);
      }
  
    dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
--- 6498,6504 ----
        dw2_asm_output_data (1, 0, "DW_LNE_set_address");
        dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
        dw2_asm_output_data (1, DW_LNE_set_address, NULL);
!       dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
      }
  
    dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
*************** output_line_info ()
*** 6534,6540 ****
  	  dw2_asm_output_data (1, 0, "DW_LNE_set_address");
  	  dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
  	  dw2_asm_output_data (1, DW_LNE_set_address, NULL);
! 	  dw2_asm_output_offset (DWARF2_ADDR_SIZE, line_label, NULL);
  	}
        else
  	{
--- 6534,6540 ----
  	  dw2_asm_output_data (1, 0, "DW_LNE_set_address");
  	  dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
  	  dw2_asm_output_data (1, DW_LNE_set_address, NULL);
! 	  dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
  	}
        else
  	{
*************** output_line_info ()
*** 6550,6556 ****
  	      dw2_asm_output_data (1, 0, "DW_LNE_set_address");
  	      dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
  	      dw2_asm_output_data (1, DW_LNE_set_address, NULL);
! 	      dw2_asm_output_offset (DWARF2_ADDR_SIZE, line_label, NULL);
  	    }
  	}
        strcpy (prev_line_label, line_label);
--- 6550,6556 ----
  	      dw2_asm_output_data (1, 0, "DW_LNE_set_address");
  	      dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
  	      dw2_asm_output_data (1, DW_LNE_set_address, NULL);
! 	      dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
  	    }
  	}
        strcpy (prev_line_label, line_label);
*************** output_line_info ()
*** 6562,6568 ****
  	  current_file = line_info->dw_file_num;
  	  dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
  	  dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
! 				       line_file_table.table[current_file]);
  	}
  
        /* Emit debug info for the current line number, choosing the encoding
--- 6562,6568 ----
  	  current_file = line_info->dw_file_num;
  	  dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
  	  dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
! 				       file_table.table[current_file]);
  	}
  
        /* Emit debug info for the current line number, choosing the encoding
*************** output_line_info ()
*** 6611,6617 ****
  	      dw2_asm_output_data (1, 0, "DW_LNE_set_address");
  	      dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
  	      dw2_asm_output_data (1, DW_LNE_set_address, NULL);
! 	      dw2_asm_output_offset (DWARF2_ADDR_SIZE, line_label, NULL);
  	    }
  
  	  /* Output the marker for the end of this sequence.  */
--- 6611,6617 ----
  	      dw2_asm_output_data (1, 0, "DW_LNE_set_address");
  	      dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
  	      dw2_asm_output_data (1, DW_LNE_set_address, NULL);
! 	      dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
  	    }
  
  	  /* Output the marker for the end of this sequence.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]