This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


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

Re: Clean up platform-specific code in gas/write.c


On Aug 19, 2000, Geoff Keating <geoffk@cygnus.com> wrote:

>> From: Alexandre Oliva <aoliva@redhat.com>
>> Date: 19 Aug 2000 14:06:50 -0300

>> Presumably, PC-relative relocations should not be deferred to the
>> linker, since they may be limited in range.

> This is target-dependent (the 'may be', the 'since', and the 'should
> not', all different on different platforms).

Yep.  How about this patch, then?  I figured out how to fix SH to do
what I wanted without having to tweak anything in the generic tree.
But, by then, it was too late, and I had already converted all the
ports I had changed yesterday to use the more flexible and
better-looking approach of TC_FIX_ADJUSTABLE(fixP) instead of
TC_DONT_FIX_NON_ADJUSTABLE (which, by itself, is hard to read because
of the multiple negations).

Also note that TC_FIX_ADJUSTABLE(fixP) is now defined within #ifdefs,
to match the original code.  But maybe I should #define them to 0
instead of `{obj,tc}_fix_adjustable(fixP)', so that the behavior would
indeed be identical to the original?

Here's the patch.  Ok to install?

Index: gas/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* write.c (TC_FIX_ADJUSTABLE): Define to 1, if not defined.
	(fixup_segment) Use it instead of TC_DONT_FIX_NON_ADJUSTABLE.
	* config/tc-i386.h (TC_DONT_FIX_NON_ADJUSTABLE): Remove.
	<OBJ_ELF, OBJ_COFF, TE_PE> (TC_FIX_ADJUSTABLE): Define.
	* config/tc-arm.h (TC_DONT_FIX_NON_ADJUSTABLE): Remove.
	<OBJ_ELF> (TC_FIX_ADJUSTABLE): Define.
	* config/tc-i960.h, config/tc-m68k.h, config/tc-v850.h:
	Likewise.

Index: gas/write.c
===================================================================
RCS file: /cvs/src/src/gas/write.c,v
retrieving revision 1.16
diff -u -p -r1.16 write.c
--- gas/write.c	2000/08/18 18:45:05	1.16
+++ gas/write.c	2000/08/19 22:02:18
@@ -48,6 +48,10 @@
 #define TC_FORCE_RELOCATION_SECTION(FIXP,SEG) TC_FORCE_RELOCATION(FIXP)
 #endif
 
+#ifndef TC_FIX_ADJUSTABLE
+#define TC_FIX_ADJUSTABLE(fix) 1
+#endif
+		  
 #ifndef	MD_PCREL_FROM_SECTION
 #define MD_PCREL_FROM_SECTION(FIXP, SEC) md_pcrel_from(FIXP)
 #endif
@@ -2706,16 +2710,7 @@ fixup_segment (fixP, this_segment_type)
 	      else
 		{
 		  seg_reloc_count++;
-#ifdef TC_DONT_FIX_NON_ADJUSTABLE
-		  if (1
-#ifdef obj_fix_adjustable
-		      && obj_fix_adjustable (fixP)
-#endif
-#ifdef tc_fix_adjustable
-		      && tc_fix_adjustable (fixP)
-#endif
-		      )
-#endif
+		  if (TC_FIX_ADJUSTABLE (fixP))
 		    add_number += S_GET_VALUE (add_symbolP);
 		}
 	    }
Index: gas/config/tc-arm.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-arm.h,v
retrieving revision 1.6
diff -u -p -r1.6 tc-arm.h
--- gas/config/tc-arm.h	2000/08/18 18:45:05	1.6
+++ gas/config/tc-arm.h	2000/08/19 22:02:18
@@ -116,14 +116,14 @@
 #define TC_FIX_TYPE PTR
 #define TC_INIT_FIX_DATA(FIXP) ((FIXP)->tc_fix_data = NULL)
 
-/* This arranges for gas/write.c to not apply a relocation if
-   obj_fix_adjustable() says it is not adjustable.  */
-#define TC_DONT_FIX_NON_ADJUSTABLE 1
-
 #ifdef OBJ_ELF
 #include "write.h"        /* For definition of fixS */
 #define obj_fix_adjustable(fixP) arm_fix_adjustable (fixP)
 boolean arm_fix_adjustable PARAMS ((fixS *));
+
+/* This arranges for gas/write.c to not apply a relocation if
+   obj_fix_adjustable() says it is not adjustable.  */
+#define TC_FIX_ADJUSTABLE(fixP) obj_fix_adjustable (fixP)
 #else
 #define obj_fix_adjustable(fixP) 0
 #endif
Index: gas/config/tc-i386.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-i386.h,v
retrieving revision 1.12
diff -u -p -r1.12 tc-i386.h
--- gas/config/tc-i386.h	2000/08/18 18:45:05	1.12
+++ gas/config/tc-i386.h	2000/08/19 22:02:18
@@ -38,12 +38,14 @@ struct fix;
    type.  The idea is that if the original type is already some kind of PIC
    relocation, we leave it alone, otherwise we give it the desired type */
 
-/* This arranges for gas/write.c to not apply a relocation if
-   tc_fix_adjustable() says it is not adjustable.  */
-#define TC_DONT_FIX_NON_ADJUSTABLE 1
-
 #define tc_fix_adjustable(X)  tc_i386_fix_adjustable(X)
 extern int tc_i386_fix_adjustable PARAMS ((struct fix *));
+
+#if defined (OBJ_ELF) || defined (OBJ_COFF) || defined (TE_PE)
+/* This arranges for gas/write.c to not apply a relocation if
+   tc_fix_adjustable() says it is not adjustable.  */
+#define TC_FIX_ADJUSTABLE(fixP) tc_fix_adjustable (fixP)
+#endif
 
 /* This is the relocation type for direct references to GLOBAL_OFFSET_TABLE.
  * It comes up in complicated expressions such as 
Index: gas/config/tc-i960.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-i960.h,v
retrieving revision 1.4
diff -u -p -r1.4 tc-i960.h
--- gas/config/tc-i960.h	2000/08/18 18:45:05	1.4
+++ gas/config/tc-i960.h	2000/08/19 22:02:18
@@ -153,12 +153,11 @@ extern int i960_validate_fix PARAMS ((st
        && ! S_IS_COMMON ((FIX)->fx_addsy)))
 #endif
 
-/* This arranges for gas/write.c to not apply a relocation if
-   tc_fix_adjustable() says it is not adjustable.  */
-#define TC_DONT_FIX_NON_ADJUSTABLE 1
-
 #ifndef OBJ_ELF
 #define tc_fix_adjustable(FIXP)		((FIXP)->fx_bsr == 0)
+/* This arranges for gas/write.c to not apply a relocation if
+   tc_fix_adjustable() says it is not adjustable.  */
+#define TC_FIX_ADJUSTABLE(fixP) tc_fix_adjustable (fixP)
 #else
 #define tc_fix_adjustable(FIXP)						\
   ((FIXP)->fx_bsr == 0							\
Index: gas/config/tc-m68k.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-m68k.h,v
retrieving revision 1.5
diff -u -p -r1.5 tc-m68k.h
--- gas/config/tc-m68k.h	2000/08/18 18:45:05	1.5
+++ gas/config/tc-m68k.h	2000/08/19 22:02:18
@@ -173,12 +173,15 @@ while (0)
 	     && S_IS_DEFINED ((FIX)->fx_addsy)		\
 	     && ! S_IS_COMMON ((FIX)->fx_addsy)))
 
+#define tc_fix_adjustable(X) tc_m68k_fix_adjustable(X)
+extern int tc_m68k_fix_adjustable PARAMS ((struct fix *));
+
+#ifdef OBJ_ELF
 /* This arranges for gas/write.c to not apply a relocation if
    tc_fix_adjustable() says it is not adjustable.  */
-#define TC_DONT_FIX_NON_ADJUSTABLE 1
+#define TC_FIX_ADJUSTABLE(fixP) tc_fix_adjustable (fixP)
+#endif
 
-#define tc_fix_adjustable(X) tc_m68k_fix_adjustable(X)
-extern int tc_m68k_fix_adjustable PARAMS ((struct fix *));
 #define elf_tc_final_processing m68k_elf_final_processing
 extern void m68k_elf_final_processing PARAMS ((void));
 #endif
Index: gas/config/tc-v850.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-v850.h,v
retrieving revision 1.2
diff -u -p -r1.2 tc-v850.h
--- gas/config/tc-v850.h	2000/08/18 18:45:05	1.2
+++ gas/config/tc-v850.h	2000/08/19 22:02:19
@@ -37,12 +37,15 @@
 #define MD_APPLY_FIX3
 #define md_operand(x)
 
+#define obj_fix_adjustable(fixP) v850_fix_adjustable(fixP)
+#define TC_FORCE_RELOCATION(fixp) v850_force_relocation(fixp)
+
+#ifdef OBJ_ELF
 /* This arranges for gas/write.c to not apply a relocation if
    obj_fix_adjustable() says it is not adjustable.  */
-#define TC_DONT_FIX_NON_ADJUSTABLE 1
+#define TC_FIX_ADJUSTABLE(fixP) obj_fix_adjustable (fixP)
+#endif
 
-#define obj_fix_adjustable(fixP) v850_fix_adjustable(fixP)
-#define TC_FORCE_RELOCATION(fixp) v850_force_relocation(fixp)
 extern int v850_force_relocation PARAMS ((struct fix *));
 
 /* Permit temporary numeric labels.  */

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

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