[PATCH/RFC] SH64 EH with pic (3/4)

Kaz Kojima kkojima@rr.iij4u.or.jp
Sat Sep 4 11:32:00 GMT 2004


This is part 3 of the patch to get rid of some problems on sh64
which prevent EH with pic working on this target.

This may be an SHmedia specific issue, though it seems a small
change of the generic part is needed.
The current sh64-unkonwn-linux-gnu c++ compiler outputs an dwarf2
exception related indirect constant as a datalabel reference:

	.hidden DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.gnu.linkonce.d.DW.ref.__gxx_personality_v0,"aw",@progbits
	.align 2
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 4
DW.ref.__gxx_personality_v0:
	.long	datalabel __gxx_personality_v0
		^^^^^^^^^
for the PIC case.  It should be non-datalabel reference.
The above last asm line is witten by dw2_output_indirect_constant_1
for the symbol recoded at dw2_force_const_mem.  The SHmedia backend
uses SYMBOL_FLAG_FUNCTION flag of the symbol_ref rtx to distinguish
the "datalabel" reference from the other one.  Unfortunately,
dw2_force_const_mem recodes the name of the symbol only and
the attributes of the original symbol are missing.  The appended
patch uses 2 new macros ASM_MAYBE_RECORD_DWARF_ADDR_RTX and
ASM_MAYBE_MODIFY_DWARF_ADDR_RTX to solve it.  In SHmedia case, the
formar recodes the original symbol rtx itself in dw2_force_const_mem
and the later copies the SYMBOL_REF_FLAGS of the original symbol to
that of the symbol created in dw2_output_indirect_constant_1, though
I'm unsure that it's a valid way to store such information.
I'd like to get the comments from the experts.

The patch is tested with bootstrap and the toplevel make -k check
on i686-pc-linux-gnu with no new failure.  It is regtested on
i686-linux cross sh64-unknown-linux-gnu.

Regards,
	kaz
--
	* config/sh/sh.h (ASM_MAYBE_RECORD_DWARF_ADDR_RTX): Define.
	(ASM_MAYBE_MODIFY_DWARF_ADDR_RTX): Likewise.
	* dwarf2asm.c (dw2_force_const_mem): Use
	ASM_MAYBE_RECORD_DWARF_ADDR_RTX if defined.
	(dw2_output_indirect_constant_1): Use
	ASM_MAYBE_MODIFY_DWARF_ADDR_RTX if defined.
	* doc/tm.texi (ASM_MAYBE_RECORD_DWARF_ADDR_RTX): Document.
	(ASM_MAYBE_MODIFY_DWARF_ADDR_RTX): Likewise.

diff -uprN ORIG/gcc/gcc/config/sh/sh.h LOCAL/gcc/gcc/config/sh/sh.h
--- ORIG/gcc/gcc/config/sh/sh.h	2004-08-19 09:46:07.000000000 +0900
+++ LOCAL/gcc/gcc/config/sh/sh.h	2004-08-26 09:50:34.000000000 +0900
@@ -3556,6 +3556,33 @@ extern int rtx_equal_function_value_matt
       } \
   } while (0)
 
+/* Recode ADDR as the DECL_RTL of the DECL_VALUE_EXPR of DECL tree.  */
+#define ASM_MAYBE_RECORD_DWARF_ADDR_RTX(DECL, STR, ADDR) \
+  do { \
+    if (TARGET_SHMEDIA) \
+      { \
+	tree val = build_decl (VAR_DECL, get_identifier ((STR)), \
+			       ptr_type_node); \
+	DECL_ARTIFICIAL (val) = 1; \
+	DECL_INITIAL (val) = val; \
+	SET_DECL_RTL (val, (ADDR)); \
+	DECL_VALUE_EXPR ((DECL)) = val; \
+      } \
+  } while (0)
+
+/* Set SYMBOL_REF_FLAGS of SYM to that of the recoded symbol_ref rtx
+   with ASM_MAYBE_RECORD_DWARF_ADDR_RTX so as to handle datalabel
+   properly.  */
+#define ASM_MAYBE_MODIFY_DWARF_ADDR_RTX(DECL, SYM) \
+  do { \
+    if (TARGET_SHMEDIA) \
+      { \
+	tree val = DECL_VALUE_EXPR ((DECL)); \
+	if (val) \
+	  SYMBOL_REF_FLAGS ((SYM)) = SYMBOL_REF_FLAGS (DECL_RTL (val)); \
+      } \
+  } while (0)
+
 #if (defined CRT_BEGIN || defined CRT_END) && ! __SHMEDIA__
 /* SH constant pool breaks the devices in crtstuff.c to control section
    in where code resides.  We have to write it as asm code.  */
diff -uprN ORIG/gcc/gcc/dwarf2asm.c LOCAL/gcc/gcc/dwarf2asm.c
--- ORIG/gcc/gcc/dwarf2asm.c	2004-05-14 10:06:07.000000000 +0900
+++ LOCAL/gcc/gcc/dwarf2asm.c	2004-08-26 09:50:34.000000000 +0900
@@ -725,6 +725,11 @@ dw2_force_const_mem (rtx x)
 	  DECL_ARTIFICIAL (decl) = 1;
 	  TREE_PUBLIC (decl) = 1;
 	  DECL_INITIAL (decl) = decl;
+	  /* Allow the target to recode something more than just the name
+	     of the original symbol.  */
+#ifdef ASM_MAYBE_RECORD_DWARF_ADDR_RTX
+	  ASM_MAYBE_RECORD_DWARF_ADDR_RTX(decl, str, x);
+#endif
 	  make_decl_one_only (decl);
 	}
       else
@@ -763,6 +768,12 @@ dw2_output_indirect_constant_1 (splay_tr
 
   sym = (const char *) node->key;
   sym_ref = gen_rtx_SYMBOL_REF (Pmode, sym);
+  /* Allow the target to modify this.  For example, some target has
+     the address capabilities which are controlled with SYMBOL_REF_FLAGS
+     and it should be set here properly.  */
+#ifdef ASM_MAYBE_MODIFY_DWARF_ADDR_RTX
+  ASM_MAYBE_MODIFY_DWARF_ADDR_RTX((tree) node->value, sym_ref);
+#endif
   if (USE_LINKONCE_INDIRECT)
     fprintf (asm_out_file, "\t.hidden %sDW.ref.%s\n", user_label_prefix, sym);
   assemble_variable ((tree) node->value, 1, 1, 1);
diff -uprN ORIG/gcc/gcc/doc/tm.texi LOCAL/gcc/gcc/doc/tm.texi
--- ORIG/gcc/gcc/doc/tm.texi	2004-08-19 09:46:20.000000000 +0900
+++ LOCAL/gcc/gcc/doc/tm.texi	2004-08-26 09:50:34.000000000 +0900
@@ -3100,6 +3100,24 @@ of bytes that the format occupies, @var{
 to be emitted.
 @end defmac
 
+@defmac ASM_MAYBE_RECORD_DWARF_ADDR_RTX (@var{decl}, @var{name}, @var{addr})
+This macro allows the target to recode whatever special magic is required
+to represent the referenced address properly.
+
+This macro is called from @code{dw2_force_const_mem} in @file{dwarf2asm.c}.
+@var{decl} is the variable which reffers to the address whose name is
+@var{name} and @var{addr} is the @code{SYMBOL_REF} of this address.
+@end defmac
+
+@defmac ASM_MAYBE_MODIFY_DWARF_ADDR_RTX (@var{decl}, @var{addr})
+This macro allows the target to set whatever special magic is required
+to represent the referenced address properly.
+
+This macro is called from @code{dw2_output_indirect_constant_1} in
+@file{dwarf2asm.c}.  @var{decl} is the variable which might have additional
+information for the address which is represented by @var{addr}.
+@end defmac
+
 @defmac MD_FALLBACK_FRAME_STATE_FOR (@var{context}, @var{fs}, @var{success})
 This macro allows the target to add cpu and operating system specific
 code to the call-frame unwinder for use when there is no unwind data



More information about the Gcc-patches mailing list