patch sparc problems in egcs

Dan Nicolaescu dann@godzilla.ics.uci.edu
Mon Feb 15 22:38:00 GMT 1999


Hi!

I wanted to get the basic block profiling (gcc -ax) working on
sparc-sun-solaris2.5.1, right now it is broken, a program compiled
with gcc -ax will not link because of some mismatched symbols. 

sparc.h uses in all the *PROFILER macros ___bb* for the basic block
function calls and sysv4.h uses __bb* 
The functions in libgcc.a are named __bb*
solaris2.5.1 gets some of *PROFILER macros from sparc.h some from
sysv4.h, hence the mismatched symbols. 

The *PROFILER macros from sysv4.h are incorrect, because they don't
follow what the documentation says: take into consideration the value
of profile_block_flag.

The patch solves all these problems.

I think it could be applied to the egcs-1.1.2 branch, as on
sparc-solaris any program compiled with -ax will not link. 


Tue Feb  9 00:11:17 1999  Dan Nicolaescu  <dann@ics.uci.edu>

	* config/sparc/sparc.h (FUNCTION_BLOCK_PROFILER): Add a nop after
	call. 

	* config/sparc/sol2.h (HAVE_POPEN): Add define, needed so
	libgcc2.c can produce compressed trace files. 

	* config/sparc/sysv4.h (BLOCK_PROFILER, FUNCTION_BLOCK_PROFILER):
	if 0. They are incorrect according to the documentation, should
	check the profile_block_flag.
        (FUNCTION_BLOCK_PROFILER):
	(BLOCK_PROFILER):
	(FUNCTION_BLOCK_PROFILER_EXIT): New macros, copied from sparc.h
	modified the labels to start with a "." and changed the ___bb*
	functions to __bb*.


*** sparc.h.orig	Mon Feb  8 14:47:18 1999
--- sparc.h	Mon Feb  8 23:54:37 1999
***************
*** 1954,1960 ****
      switch (profile_block_flag)				\
        {							\
        case 2:						\
!         fprintf (FILE, "\tsethi %%hi(LPBX0),%%o0\n\tor %%o0,%%lo(LPBX0),%%o0\n\tsethi %%hi(%d),%%o1\n\tcall ___bb_init_trace_func\n\tor %%o1,%%lo(%d),%%o1\n",\
                   bol, bol);				\
          break;						\
        default:						\
--- 1954,1960 ----
      switch (profile_block_flag)				\
        {							\
        case 2:						\
!         fprintf (FILE, "\tsethi %%hi(LPBX0),%%o0\n\tor %%o0,%%lo(LPBX0),%%o0\n\tsethi %%hi(%d),%%o1\n\tcall ___bb_init_trace_func\n\tnop\n\tor %%o1,%%lo(%d),%%o1\n",\
                   bol, bol);				\
          break;						\
        default:						\
*** sparc.h.orig	Mon Feb  8 14:47:18 1999
--- sparc.h	Mon Feb  8 23:54:37 1999
***************
*** 1954,1960 ****
      switch (profile_block_flag)				\
        {							\
        case 2:						\
!         fprintf (FILE, "\tsethi %%hi(LPBX0),%%o0\n\tor %%o0,%%lo(LPBX0),%%o0\n\tsethi %%hi(%d),%%o1\n\tcall ___bb_init_trace_func\n\tor %%o1,%%lo(%d),%%o1\n",\
                   bol, bol);				\
          break;						\
        default:						\
--- 1954,1960 ----
      switch (profile_block_flag)				\
        {							\
        case 2:						\
!         fprintf (FILE, "\tsethi %%hi(LPBX0),%%o0\n\tor %%o0,%%lo(LPBX0),%%o0\n\tsethi %%hi(%d),%%o1\n\tcall ___bb_init_trace_func\n\tnop\n\tor %%o1,%%lo(%d),%%o1\n",\
                   bol, bol);				\
          break;						\
        default:						\
*** sysv4.h.orig	Mon Feb  8 14:47:38 1999
--- sysv4.h	Tue Feb  9 00:05:24 1999
***************
*** 204,209 ****
--- 204,210 ----
  /* Output assembler code to FILE to initialize this source file's
     basic block profiling info, if that has not already been done.  */
  
+ #if 0
  #undef FUNCTION_BLOCK_PROFILER
  #define FUNCTION_BLOCK_PROFILER(FILE, LABELNO)  \
    do { \
***************
*** 228,233 ****
--- 229,306 ----
     NAME whose size is SIZE bytes and alignment is ALIGN bytes.
     Try to use asm_output_aligned_bss to implement this macro.  */
  
+ #endif
+ 
+ /* See the comments in sparc.h about what the FUNCTION_BLOCK_PROFILER,
+    BLOCK_PROFILER and FUNCTION_BLOCK_PROFILER_EXIT macros are supposed
+    to do. */
+ 
+ #undef FUNCTION_BLOCK_PROFILER
+ #define FUNCTION_BLOCK_PROFILER(FILE, BLOCK_OR_LABEL)	\
+ do							\
+   {							\
+     int bol = (BLOCK_OR_LABEL);				\
+     switch (profile_block_flag)				\
+       {							\
+       case 2:						\
+         fprintf (FILE, "\tsethi %%hi(.LLPBX0),%%o0\n\tor %%o0,%%lo(.LLPBX0),%%o0\n\tsethi %%hi(%d),%%o1\n\tcall __bb_init_trace_func\n\tnop\n\tor %%o1,%%lo(%d),%%o1\n",\
+                  bol, bol);				\
+         break;						\
+       default:						\
+         fprintf (FILE, "\tsethi %%hi(.LLPBX0),%%o0\n\tld [%%lo(.LLPBX0)+%%o0],%%o1\n\ttst %%o1\n\tbne .LPY%d\n\tadd %%o0,%%lo(.LLPBX0),%%o0\n\tcall __bb_init_func\n\tnop\n.LPY%d:\n",\
+                  bol, bol);				\
+         break;						\
+       }							\
+   }							\
+ while (0)
+ 
+ #undef BLOCK_PROFILER
+ #define BLOCK_PROFILER(FILE, BLOCKNO)	\
+ do					\
+   {					\
+     int blockn = (BLOCKNO);		\
+     switch (profile_block_flag)		\
+       {					\
+       case 2:				\
+         fprintf (FILE, "\tsethi %%hi(__bb),%%g1\n\tsethi %%hi(%d),%%g2\n\tor %%g2,%%lo(%d),%%g2\n\tst %%g2,[%%lo(__bb)+%%g1]\n\tsethi %%hi(.LLPBX0),%%g2\n\tor %%g2,%%lo(.LLPBX0),%%g2\n\tadd 4,%%g1,%%g1\n\tst %%g2,[%%lo(__bb)+%%g1]\n\tmov %%o7,%%g2\n\tcall __bb_trace_func\n\tnop\n\tmov %%g2,%%o7\n",\
+                  blockn, blockn); \
+         break;				\
+       default:				\
+         fprintf (FILE, "\tsethi %%hi(.LLPBX2+%d),%%g1\n\tld [%%lo(.LLPBX2+%d)+%%g1],%%g2\n\
+ \tadd %%g2,1,%%g2\n\tst %%g2,[%%lo(.LLPBX2+%d)+%%g1]\n", \
+                  4 * blockn, 4 * blockn, 4 * blockn); \
+         break;				\
+       }					\
+   }					\
+ while(0)
+ 
+ /* The following macro shall output assembler code to FILE
+    to indicate a return from function during basic-block profiling.
+ 
+    If profiling_block_flag == 2:
+ 
+ 	Output assembler code to call function `__bb_trace_ret'.
+ 
+ 	Note that function `__bb_trace_ret' must not change the
+ 	machine state, especially the flag register. To grant
+ 	this, you must output code to save and restore registers
+ 	either in this macro or in the macros MACHINE_STATE_SAVE_RET
+ 	and MACHINE_STATE_RESTORE_RET. The last two macros will be
+ 	used in the function `__bb_trace_ret', so you must make
+ 	sure that the function prologue does not change any 
+ 	register prior to saving it with MACHINE_STATE_SAVE_RET.
+ 
+    else if profiling_block_flag != 0:
+ 
+ 	The macro will not be used, so it need not distinguish
+ 	these cases.
+ */
+ 
+ #undef FUNCTION_BLOCK_PROFILER_EXIT
+ #define FUNCTION_BLOCK_PROFILER_EXIT(FILE) \
+   fprintf (FILE, "\tcall __bb_trace_ret\n\tnop\n" );
+ 
+ 
  #undef ASM_OUTPUT_ALIGNED_BSS
  #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
    asm_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)


More information about the Gcc-patches mailing list