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]
Other format: [Raw text]

Fix PR 5933 -- Definition of ASM_OUTPUT_MI_THUNK on PA


The enclosed patch fixes the testcase supplied with PR 5933.  Thunks didn't
work with pic code because the linker inserts a stub between the thunk and
target function.  Since the same frame is used for the indirect call to
the thunk and for the jump to the target function, the same location is
used by both to save the return pointer and an infinite loops results in
the return path.

The patch changes the definition of ASM_OUTPUT_MI_THUNK to use an indirect
jump to the target function when we are generating 32-bit pic code.  The code
used is similar to that in $$dyncall except that we don't save the return
pointer.

The patch has been bootstrapped and regtested on:

hppa-linux gcc-3.2
hppa2.0-hp-hpux11.00 gcc-3.1
hppa2.0-hp-hpux11.11 gcc-3.1
hppa64-hp-hpux11.11 gcc-3.1

The testcase has been checked with and without "-g", with "-fPIC" and
the thunk being in a shared library, without "-fPIC" and direct linkage.
The reason for the "-g" testing is that there is some additional debug
output in the function section after the thunk under hppa-linux.

Applied to the 3.1 branch and trunk.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)

2002-04-07  John David Anglin  <dave@hiauly1.hia.nrc.ca>

	PR 5933
	* pa.h (ASM_OUTPUT_MI_THUNK): Use indirect jump to target function when
	generating 32-bit pic code.

Index: pa.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/pa/pa.h,v
retrieving revision 1.145
diff -u -3 -p -r1.145 pa.h
--- pa.h	4 Apr 2002 02:48:18 -0000	1.145
+++ pa.h	7 Apr 2002 04:22:23 -0000
@@ -861,23 +861,76 @@ extern enum cmp_type hppa_branch_type;
 
 #define ASM_OUTPUT_MI_THUNK(FILE, THUNK_FNDECL, DELTA, FUNCTION) \
 { const char *target_name = XSTR (XEXP (DECL_RTL (FUNCTION), 0), 0); \
+  static unsigned int current_thunk_number; \
+  char label[16]; \
+  char *lab; \
+  ASM_GENERATE_INTERNAL_LABEL (label, "LTHN", current_thunk_number); \
+  STRIP_NAME_ENCODING (lab, label); \
   STRIP_NAME_ENCODING (target_name, target_name); \
+  /* FIXME: total_code_bytes is not handled correctly in files with \
+     mi thunks.  */ \
   pa_output_function_prologue (FILE, 0); \
   if (VAL_14_BITS_P (DELTA)) \
     { \
-      fprintf (FILE, "\tb %s\n\tldo ", target_name); \
-      fprintf (FILE, HOST_WIDE_INT_PRINT_DEC, DELTA); \
-      fprintf (FILE, "(%%r26),%%r26\n"); \
+      if (! TARGET_64BIT && ! TARGET_PORTABLE_RUNTIME && flag_pic) \
+	{ \
+	  fprintf (FILE, "\taddil LT%%%s,%%r19\n", lab); \
+	  fprintf (FILE, "\tldw RT%%%s(%%r1),%%r22\n", lab); \
+	  fprintf (FILE, "\tldw 0(%%sr0,%%r22),%%r22\n"); \
+	  fprintf (FILE, "\tbb,>=,n %%r22,30,.+16\n"); \
+	  fprintf (FILE, "\tdepi 0,31,2,%%r22\n"); \
+	  fprintf (FILE, "\tldw 4(%%sr0,%%r22),%%r19\n"); \
+	  fprintf (FILE, "\tldw 0(%%sr0,%%r22),%%r22\n"); \
+	  fprintf (FILE, "\tldsid (%%sr0,%%r22),%%r1\n\tmtsp %%r1,%%sr0\n"); \
+	  fprintf (FILE, "\tbe 0(%%sr0,%%r22)\n\tldo "); \
+	  fprintf (FILE, HOST_WIDE_INT_PRINT_DEC, DELTA); \
+	  fprintf (FILE, "(%%r26),%%r26\n"); \
+	} \
+      else \
+	{ \
+	  fprintf (FILE, "\tb %s\n\tldo ", target_name); \
+	  fprintf (FILE, HOST_WIDE_INT_PRINT_DEC, DELTA); \
+	  fprintf (FILE, "(%%r26),%%r26\n"); \
+	} \
     } \
   else \
     { \
-      fprintf (FILE, "\taddil L%%"); \
-      fprintf (FILE, HOST_WIDE_INT_PRINT_DEC, DELTA); \
-      fprintf (FILE, ",%%r26\n\tb %s\n\tldo R%%", target_name); \
-      fprintf (FILE, HOST_WIDE_INT_PRINT_DEC, DELTA); \
-      fprintf (FILE, "(%%r1),%%r26\n"); \
+      if (! TARGET_64BIT && ! TARGET_PORTABLE_RUNTIME && flag_pic) \
+	{ \
+	  fprintf (FILE, "\taddil L%%"); \
+	  fprintf (FILE, HOST_WIDE_INT_PRINT_DEC, DELTA); \
+	  fprintf (FILE, ",%%r26\n\tldo R%%"); \
+	  fprintf (FILE, HOST_WIDE_INT_PRINT_DEC, DELTA); \
+	  fprintf (FILE, "(%%r1),%%r26\n"); \
+	  fprintf (FILE, "\taddil LT%%%s,%%r19\n", lab); \
+	  fprintf (FILE, "\tldw RT%%%s(%%r1),%%r22\n", lab); \
+	  fprintf (FILE, "\tldw 0(%%sr0,%%r22),%%r22\n"); \
+	  fprintf (FILE, "\tbb,>=,n %%r22,30,.+16\n"); \
+	  fprintf (FILE, "\tdepi 0,31,2,%%r22\n"); \
+	  fprintf (FILE, "\tldw 4(%%sr0,%%r22),%%r19\n"); \
+	  fprintf (FILE, "\tldw 0(%%sr0,%%r22),%%r22\n"); \
+	  fprintf (FILE, "\tldsid (%%sr0,%%r22),%%r1\n\tmtsp %%r1,%%sr0\n"); \
+	  fprintf (FILE, "\tbe,n 0(%%sr0,%%r22)\n"); \
+	} \
+      else \
+	{ \
+	  fprintf (FILE, "\taddil L%%"); \
+	  fprintf (FILE, HOST_WIDE_INT_PRINT_DEC, DELTA); \
+	  fprintf (FILE, ",%%r26\n\tb %s\n\tldo R%%", target_name); \
+	  fprintf (FILE, HOST_WIDE_INT_PRINT_DEC, DELTA); \
+	  fprintf (FILE, "(%%r1),%%r26\n"); \
+	} \
     } \
-  fprintf (FILE, "\n\t.EXIT\n\t.PROCEND\n"); \
+  fprintf (FILE, "\t.EXIT\n\t.PROCEND\n"); \
+  if (! TARGET_64BIT && ! TARGET_PORTABLE_RUNTIME && flag_pic) \
+    { \
+      data_section (); \
+      fprintf (FILE, "\t.align 4\n"); \
+      ASM_OUTPUT_INTERNAL_LABEL (FILE, "LTHN", current_thunk_number); \
+      fprintf (FILE, "\t.word P%%%s\n", target_name); \
+      function_section (THUNK_FNDECL); \
+    } \
+  current_thunk_number++; \
 }
 
 /* On HPPA, we emit profiling code as rtl via PROFILE_HOOK rather than


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