[patch] gas cfi support for hppa

Randolph Chung randolph@tausq.org
Mon Feb 28 16:22:00 GMT 2005


Carlos asked about cfi support for hppa, so here's a lightly tested
patch. Please apply if ok. Passes the testsuite.

randolph

2005-02-28  Randolph Chung  <tausq@debian.org>

	* config/tc-hppa.c: Include "dw2gencfi.h".
	(tc_hppa_regname_to_dw2regnum, tc_hppa_frame_initial_instructions):
	New functions.
	* config/tc-hppa.h (TARGET_USE_CFIPOP, DWARF2_DEFAULT_RETURN_COLUMN)
	(DWARF2_CIE_DATA_ALIGNMENT, tc_regname_to_dw2regnum)
	(tc_cfi_frame_initial_instructions): Define.
	(tc_hppa_regname_to_dw2regnum, tc_hppa_frame_initial_instructions):
	Add prototypes.

testsuite/
	* gas/cfi/cfi-hppa-1.d, gas/cfi/cfi-hppa-1.s: New files.
	* gas/cfi/cfi.exp: Run cfi-hppa-1 test.

Index: config/tc-hppa.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-hppa.c,v
retrieving revision 1.114
diff -u -p -r1.114 tc-hppa.c
--- config/tc-hppa.c	20 Jul 2004 03:07:08 -0000	1.114
+++ config/tc-hppa.c	28 Feb 2005 14:30:16 -0000
@@ -42,6 +42,7 @@ error only one of OBJ_ELF and OBJ_SOM ca
    then we want to use the assembler support for compact line numbers.  */
 #ifdef OBJ_ELF
 #include "dwarf2dbg.h"
+#include "dw2gencfi.h"
 
 /* A "convenient" place to put object file dependencies which do
    not need to be seen outside of tc-hppa.c.  */
@@ -8732,4 +8733,47 @@ pa_vtable_inherit (ignore)
       new_fix->fx_r_type = (int) R_PARISC_GNU_VTINHERIT;
     }
 }
+
+/* Convert REGNAME to a DWARF-2 register number.  */
+
+int
+tc_hppa_regname_to_dw2regnum (const char *regname)
+{
+  unsigned int regnum = -1;
+  const char *p = regname;
+
+  if (p[0] == 'r')
+    {
+      regnum = strtoul (p + 1, 0, 10);
+    }
+  else if (p[0] == 'f')
+    {
+      regnum = strtoul (p + 1, 0, 10);
+      regnum = (regnum - 4) * 2 + 32;;
+      if (p[strlen (p) - 1] == 'R')
+        regnum++;
+    }
+  else if (strcmp (p, "rp") == 0)
+    {
+      regnum = 2;
+    }
+  else if (strcmp (p, "sp") == 0)
+    {
+      regnum = 30;
+    }
+  else if (strcmp (p, "sar") == 0)
+    {
+      regnum = 32 + (32 - 4) * 2 + 1;
+    }
+
+  return regnum;
+}
+
+/* Initialize the DWARF-2 unwind information for this procedure.  */
+
+void
+tc_hppa_frame_initial_instructions (void)
+{
+  cfi_add_CFA_def_cfa (30, 0);
+}
 #endif
Index: config/tc-hppa.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-hppa.h,v
retrieving revision 1.27
diff -u -p -r1.27 tc-hppa.h
--- config/tc-hppa.h	19 Feb 2005 08:56:08 -0000	1.27
+++ config/tc-hppa.h	28 Feb 2005 14:30:16 -0000
@@ -187,6 +187,23 @@ int hppa_fix_adjustable PARAMS((struct f
 void elf_hppa_final_processing PARAMS ((void));
 
 #define DWARF2_LINE_MIN_INSN_LENGTH 4
+
+/* We want .cfi_* pseudo-ops for generating unwind info.  */
+#define TARGET_USE_CFIPOP              1
+
+/* The rp register is r2.  */
+#define DWARF2_DEFAULT_RETURN_COLUMN	2
+
+/* Registers are generally saved at negative offsets to the CFA.  */
+#define DWARF2_CIE_DATA_ALIGNMENT     -4
+
+/* CFI hooks.  */
+extern int tc_hppa_regname_to_dw2regnum (const char *regname);
+extern void tc_hppa_frame_initial_instructions (void);
+
+#define tc_regname_to_dw2regnum            tc_hppa_regname_to_dw2regnum
+#define tc_cfi_frame_initial_instructions  tc_hppa_frame_initial_instructions
+
 #endif /* OBJ_ELF */
 
 #define md_operand(x)
Index: testsuite/gas/cfi/cfi.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/cfi/cfi.exp,v
retrieving revision 1.13
diff -u -p -r1.13 cfi.exp
--- testsuite/gas/cfi/cfi.exp	25 Oct 2004 12:26:04 -0000	1.13
+++ testsuite/gas/cfi/cfi.exp	28 Feb 2005 14:30:17 -0000
@@ -59,6 +59,9 @@ if [istarget "x86_64-*"] then {
 } elseif { [istarget "arm*-*"] || [istarget "xscale*-*"] } then {
     run_dump_test "cfi-arm-1"
 
+} elseif { [istarget "hppa*-*"] } then {
+    run_dump_test "cfi-hppa-1"
+
 } else {
     return
 }
--- testsuite/gas/cfi/cfi-hppa-1.s	2005-02-28 06:22:35.000000000 -0800
+++ testsuite/gas/cfi/cfi-hppa-1.s	2005-02-28 06:22:35.000000000 -0800
@@ -0,0 +1,38 @@
+	.file	"a.c"
+	.version	"01.01"
+	.LEVEL 1.1
+
+	.file "a.c"
+	.text
+	.align 4
+.globl foo
+	.type	foo, @function
+foo:
+	.PROC
+	.CALLINFO FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=3
+	.ENTRY
+	.cfi_startproc
+	stw %r2,-20(%r30)
+	.cfi_rel_offset r2, -20
+	copy %r3,%r1
+	copy %r30,%r3
+	.cfi_def_cfa_register r3
+	stwm %r1,64(%r30)
+	stw %r26,-36(%r3)
+	.cfi_rel_offset r26, -36
+	stw %r25,-40(%r3)
+	.cfi_rel_offset r25, -40
+	ldw -36(%r3),%r26
+	ldw -40(%r3),%r25
+	bl bar,%r2
+	nop
+	copy %r28,%r19
+	copy %r19,%r28
+	ldw -20(%r3),%r2
+	ldo 64(%r3),%r30
+	ldwm -64(%r30),%r3
+	bv,n %r0(%r2)
+	.cfi_endproc
+	.EXIT
+	.PROCEND
+	.size	foo, .-foo
--- testsuite/gas/cfi/cfi-hppa-1.d	2005-02-28 06:23:15.000000000 -0800
+++ testsuite/gas/cfi/cfi-hppa-1.d	2005-02-28 06:23:15.000000000 -0800
@@ -0,0 +1,28 @@
+#readelf: -wf
+#name: CFI on HPPA
+
+The section .eh_frame contains:
+
+00000000 00000010 00000000 CIE
+  Version:               1
+  Augmentation:          "zR"
+  Code alignment factor: 4
+  Data alignment factor: -4
+  Return address column: 2
+  Augmentation data:     1b
+
+  DW_CFA_def_cfa: r30 ofs 0
+
+00000014 0000001c 00000018 FDE cie=00000000 pc=00000000..00000040
+  DW_CFA_advance_loc: 4 to 00000004
+  DW_CFA_offset: r2 at cfa-20
+  DW_CFA_advance_loc: 8 to 0000000c
+  DW_CFA_def_cfa_reg: r3
+  DW_CFA_advance_loc: 8 to 00000014
+  DW_CFA_offset: r26 at cfa-36
+  DW_CFA_advance_loc: 4 to 00000018
+  DW_CFA_offset: r25 at cfa-40
+  DW_CFA_nop
+  DW_CFA_nop
+  DW_CFA_nop
+

-- 
Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports
http://www.tausq.org/



More information about the Binutils mailing list