[PATCH] Make debug info section relative on IA64

Steve Ellcey sje@cup.hp.com
Fri Mar 7 01:16:00 GMT 2003
Richard (or anyone on binutils),

I tried to make a patch like you suggested to fix the debug RELOC
problem I am having but I can't seem to get it right.  Can you (or
someone else on the binutils list) look at the following patch and see
if anything looks wrong?  I think it should do what my original patch
does but it just doesn't work.

Originally (no patch) I would start the HP gdb on a C program containing
a floating point divide (causing it to include __divdf3, which is
written in ASM) and get:

	Dwarf Error: bad offset (0xd6) in compilation unit header (offset 0x68 + 6).

Now with this patch I can start gdb fine but if I set a breakpoint on
main, I get:

	warning: (Internal error: pc 0x4000720 in read in psymtab, but not in symtab.)

0x4000720 is the start of main in my 32 bit program, a 64 bit version of
the program has the same problem.

With my original patch, I could start gdb fine and got no warnings when
I set a breakpoint on main and things seemed to work just fine.

Attached is my current attempt to fix this "the right way" and which
gives me the warnings.

Steve Ellcey
sje@cup.hp.com


*** src.orig/gas/dwarf2dbg.c	Thu Mar  6 16:19:02 2003
--- src/gas/dwarf2dbg.c	Thu Mar  6 17:02:52 2003
***************
*** 44,49 ****
--- 44,54 ----
  #include "dwarf2dbg.h"
  #include <filenames.h>
  
+ #ifndef TC_DWARF2_EMIT_OFFSET
+ # define TC_DWARF2_EMIT_OFFSET(SYMBOL,SIZE) \
+    (generic_dwarf2_emit_offset (SYMBOL, SIZE))
+ #endif
+ 
  #ifndef DWARF2_FORMAT
  # define DWARF2_FORMAT() dwarf2_format_32bit
  #endif
*************** static char const fake_label_name[] = ".
*** 160,165 ****
--- 165,171 ----
  /* The size of an address on the target.  */
  static unsigned int sizeof_address;
  
+ static void generic_dwarf2_emit_offset PARAMS((symbolS *, unsigned int));
  static struct line_subseg *get_line_subseg PARAMS ((segT, subsegT));
  static unsigned int get_filenum PARAMS ((const char *, unsigned int));
  static struct frag *first_frag_for_seg PARAMS ((segT));
*************** static void out_debug_aranges PARAMS ((s
*** 186,191 ****
--- 192,212 ----
  static void out_debug_abbrev PARAMS ((segT));
  static void out_debug_info PARAMS ((segT, segT, segT));
  
+ /* Create an offset to .dwarf2_*.  */
+ 
+ static void
+ generic_dwarf2_emit_offset (symbol, size)
+      symbolS *symbol;
+      unsigned int size;
+ {
+   expressionS expr;
+ 
+   expr.X_op = O_symbol;
+   expr.X_add_symbol = symbol;
+   expr.X_add_number = 0;
+   emit_expr (&expr, size);
+ }
+ 
  /* Find or create an entry for SEG+SUBSEG in ALL_SEGS.  */
  
  static struct line_subseg *
*************** out_debug_aranges (aranges_seg, info_seg
*** 1209,1218 ****
    out_two (2);
  
    /* Offset to .debug_info.  */
!   expr.X_op = O_symbol;
!   expr.X_add_symbol = section_symbol (info_seg);
!   expr.X_add_number = 0;
!   emit_expr (&expr, 4);
  
    /* Size of an address (offset portion).  */
    out_byte (addr_size);
--- 1230,1236 ----
    out_two (2);
  
    /* Offset to .debug_info.  */
!   TC_DWARF2_EMIT_OFFSET (section_symbol (info_seg), 4);
  
    /* Size of an address (offset portion).  */
    out_byte (addr_size);
*************** out_debug_info (info_seg, abbrev_seg, li
*** 1339,1348 ****
    out_two (2);
  
    /* .debug_abbrev offset */
!   expr.X_op = O_symbol;
!   expr.X_add_symbol = section_symbol (abbrev_seg);
!   expr.X_add_number = 0;
!   emit_expr (&expr, sizeof_offset);
  
    /* Target address size.  */
    out_byte (sizeof_address);
--- 1357,1363 ----
    out_two (2);
  
    /* .debug_abbrev offset */
!   TC_DWARF2_EMIT_OFFSET (section_symbol (abbrev_seg), sizeof_offset);
  
    /* Target address size.  */
    out_byte (sizeof_address);
*************** out_debug_info (info_seg, abbrev_seg, li
*** 1351,1360 ****
    out_uleb128 (1);
  
    /* DW_AT_stmt_list */
!   expr.X_op = O_symbol;
!   expr.X_add_symbol = section_symbol (line_seg);
!   expr.X_add_number = 0;
!   emit_expr (&expr, 4);
  
    /* These two attributes may only be emitted if all of the code is
       contiguous.  Multiple sections are not that.  */
--- 1366,1372 ----
    out_uleb128 (1);
  
    /* DW_AT_stmt_list */
!   TC_DWARF2_EMIT_OFFSET (section_symbol (line_seg), 4);
  
    /* These two attributes may only be emitted if all of the code is
       contiguous.  Multiple sections are not that.  */
*** src.orig/gas/config/tc-ia64.h	Thu Mar  6 16:17:21 2003
--- src/gas/config/tc-ia64.h	Thu Mar  6 16:17:11 2003
*************** extern long ia64_pcrel_from_section PARA
*** 89,94 ****
--- 89,95 ----
  extern void ia64_md_do_align PARAMS ((int, const char *, int, int));
  extern void ia64_handle_align PARAMS ((fragS *f));
  extern void ia64_after_parse_args PARAMS ((void));
+ extern void ia64_dwarf2_emit_offset PARAMS ((symbolS *, unsigned int));
  
  #define md_end()       			ia64_end_of_source ()
  #define md_start_line_hook()		ia64_start_line ()
*************** extern void ia64_after_parse_args PARAMS
*** 119,124 ****
--- 120,127 ----
  #define HANDLE_ALIGN(f)			ia64_handle_align (f)
  #define md_elf_section_type(str,len)	ia64_elf_section_type (str, len)
  #define md_after_parse_args()		ia64_after_parse_args ()
+ #define TC_DWARF2_EMIT_OFFSET(symbol,size) \
+ 					ia64_dwarf2_emit_offset (symbol, size)
  
  #define MAX_MEM_FOR_RS_ALIGN_CODE  (15 + 16)
  
*** src.orig/gas/config/tc-ia64.c	Thu Feb 27 12:56:58 2003
--- src/gas/config/tc-ia64.c	Thu Mar  6 16:17:01 2003
*************** ia64_after_parse_args ()
*** 6472,6477 ****
--- 6472,6489 ----
      as_fatal (_("--gstabs is not supported for ia64"));
  }
  
+ void
+ ia64_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
+ {
+   expressionS expr;
+ 
+   expr.X_op = O_pseudo_fixup;
+   expr.X_op_symbol = pseudo_func[FUNC_SEC_RELATIVE].u.sym;
+   expr.X_add_number = 0;
+   expr.X_add_symbol = symbol;
+   emit_expr (&expr, size);
+ }
+ 
  /* Return true if TYPE fits in TEMPL at SLOT.  */
  
  static int
*************** ia64_cons_fix_new (f, where, nbytes, exp
*** 10054,10064 ****
      case 1: code = BFD_RELOC_8; break;
      case 2: code = BFD_RELOC_16; break;
      case 4:
!       if (target_big_endian)
! 	code = BFD_RELOC_IA64_DIR32MSB;
        else
! 	code = BFD_RELOC_IA64_DIR32LSB;
!       break;
  
      case 8:
        /* In 32-bit mode, data8 could mean function descriptors too.  */
--- 10066,10090 ----
      case 1: code = BFD_RELOC_8; break;
      case 2: code = BFD_RELOC_16; break;
      case 4:
!       if (exp->X_op == O_pseudo_fixup
! 	  && exp->X_op_symbol
! 	  && S_GET_VALUE (exp->X_op_symbol) == FUNC_SEC_RELATIVE)
!         {
! 	  if (target_big_endian)
! 	    code = BFD_RELOC_IA64_SECREL32MSB;
! 	  else
! 	    code = BFD_RELOC_IA64_SECREL32LSB;
! 	  exp->X_op = O_symbol;
! 	  break;
! 	}
        else
! 	{
! 	  if (target_big_endian)
! 	    code = BFD_RELOC_IA64_DIR32MSB;
! 	  else
! 	    code = BFD_RELOC_IA64_DIR32LSB;
! 	  break;
! 	}
  
      case 8:
        /* In 32-bit mode, data8 could mean function descriptors too.  */
*************** ia64_cons_fix_new (f, where, nbytes, exp
*** 10082,10087 ****
--- 10108,10124 ----
  	    code = BFD_RELOC_IA64_DTPREL64MSB;
  	  else
  	    code = BFD_RELOC_IA64_DTPREL64LSB;
+ 	  break;
+ 	}
+       else if (exp->X_op == O_pseudo_fixup
+ 	       && exp->X_op_symbol
+ 	       && S_GET_VALUE (exp->X_op_symbol) == FUNC_SEC_RELATIVE)
+ 	{
+ 	  if (target_big_endian)
+ 	    code = BFD_RELOC_IA64_SECREL64MSB;
+ 	  else
+ 	    code = BFD_RELOC_IA64_SECREL64LSB;
+ 	  exp->X_op = O_symbol;
  	  break;
  	}
        else



More information about the Binutils mailing list