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]

Patch for mn10300 cleaned up


Checked in with approval from nickc.

-eric

2000-08-22  Eric Christopher  <echristo@cygnus.com>

	* config/tc-mn10300.c: (md_apply_fix): New function.
	(mn10300_force_relocation): New function.
	(mn10300_fix_adjustable): New function.

	* config/tc-mn10300.h: (TC_FORCE_RELOCATION): Define.
	(TC_HANDLES_FX_DONE): Define.
	(obj_fix_adjustable): Define.
	(MD_APPLY_FIX3): Define.
	(TC_LINKRELAX_FIXUP): Define.

	* write.c: (TC_LINKRELAX_FIXUP):  Define if not
	previously defined.
	(fixup_segment): Use TC_LINKRELAX_FIXUP.

	* doc/internals.texi: Document TC_LINKRELAX_FIXUP.
Index: write.c
===================================================================
RCS file: /cvs/src/src/gas/write.c,v
retrieving revision 1.16
diff -u -p -w -r1.16 write.c
--- write.c	2000/08/18 18:45:05	1.16
+++ write.c	2000/08/22 01:03:35
@@ -48,6 +48,10 @@
 #define TC_FORCE_RELOCATION_SECTION(FIXP,SEG) TC_FORCE_RELOCATION(FIXP)
 #endif
 
+#ifndef TC_LINKRELAX_FIXUP
+#define TC_LINKRELAX_FIXUP(SEG) 1
+#endif
+
 #ifndef	MD_PCREL_FROM_SECTION
 #define MD_PCREL_FROM_SECTION(FIXP, SEC) md_pcrel_from(FIXP)
 #endif
@@ -2461,7 +2465,7 @@ fixup_segment (fixP, this_segment_type)
      i960 (the only machine for which we've got a relaxing linker right now),
      we might be able to turn callx/callj into bal anyways in cases where we
      know the maximum displacement.  */
-  if (linkrelax)
+  if (linkrelax && TC_LINKRELAX_FIXUP (this_segment_type))
     {
       for (; fixP; fixP = fixP->fx_next)
 	seg_reloc_count++;
Index: config/tc-mn10300.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mn10300.c,v
retrieving revision 1.9
diff -u -p -w -r1.9 tc-mn10300.c
--- tc-mn10300.c	2000/07/28 03:33:32	1.9
+++ tc-mn10300.c	2000/08/22 01:03:35
@@ -1920,10 +1920,90 @@ md_apply_fix3 (fixp, valuep, seg)
      valueT *valuep;
      segT seg;
 {
-  /* We shouldn't ever get here because linkrelax is nonzero.  */
+
+  valueT value = *valuep;
+  char *fixpos = fixp->fx_where + fixp->fx_frag->fr_literal;
+  int size = 0;
+
+  assert (fixp->fx_r_type < BFD_RELOC_UNUSED);
+
+  /* This should never happen.  */
+  if (seg->flags & SEC_ALLOC)
   abort ();
+
+  /* If the fix is relative to a symbol which is not defined, or not
+     in the same segment as the fix, we cannot resolve it here.  */
+  if (fixp->fx_addsy != NULL
+      && (! S_IS_DEFINED (fixp->fx_addsy)
+	  || (S_GET_SEGMENT (fixp->fx_addsy) != seg)))
+    {
+      fixp->fx_done = 0;
+      return 0;
+    }
+
+  switch (fixp->fx_r_type)
+    {
+    case BFD_RELOC_8:
+      size = 1;
+      break;
+
+    case BFD_RELOC_16:
+      size = 2;
+      break;
+
+    case BFD_RELOC_32:
+      size = 4;
+      break;
+
+    case BFD_RELOC_VTABLE_INHERIT:
+    case BFD_RELOC_VTABLE_ENTRY:
+      fixp->fx_done = 0;
+      return 1;
+
+    case BFD_RELOC_NONE:
+    default:
+      as_bad_where (fixp->fx_file, fixp->fx_line,
+                   _("Bad relocation fixup type (%d)"), fixp->fx_r_type);
+    }
+
+  md_number_to_chars (fixpos, fixp->fx_offset, size);
+
   fixp->fx_done = 1;
   return 0;
+
+}
+
+/* Return nonzero if the fixup in FIXP will require a relocation,
+   even it if appears that the fixup could be completely handled
+   within GAS.  */
+
+int
+mn10300_force_relocation (fixp)
+     struct fix *fixp;
+{
+  if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
+      || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
+    return 1;
+
+  return 0;
+}
+
+/* Return zero if the fixup in fixp should be left alone and not
+   adjusted.  */
+
+boolean
+mn10300_fix_adjustable (fixp)
+     struct fix *fixp;
+{
+  /* Prevent all adjustments to global symbols.  */
+  if (S_IS_EXTERN (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy))
+    return 0;
+
+  if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
+      || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
+    return 0;
+
+  return 1;
 }
 
 /* Insert an operand value into an instruction.  */
Index: config/tc-mn10300.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mn10300.h,v
retrieving revision 1.3
diff -u -p -w -r1.3 tc-mn10300.h
--- tc-mn10300.h	2000/08/14 17:49:55	1.3
+++ tc-mn10300.h	2000/08/22 01:03:35
@@ -31,7 +31,21 @@
 
 #define TARGET_FORMAT "elf32-mn10300"
 
-#define MD_APPLY_FIX3
+/* For fixup and relocation handling.  */
+#define TC_FORCE_RELOCATION(fixp) mn10300_force_relocation (fixp)
+extern int mn10300_force_relocation PARAMS ((struct fix *));
+
+#define TC_HANDLES_FX_DONE
+
+#define obj_fix_adjustable(fixP) mn10300_fix_adjustable (fixP)
+extern boolean mn10300_fix_adjustable PARAMS ((struct fix *));
+
+#define MD_APPLY_FIX3 md_apply_fix3
+
+/* Fixup debug sections since we will never relax them.  */
+#define TC_LINKRELAX_FIXUP(seg) (seg->flags & SEC_ALLOC)
+
+
 #define md_operand(x)
 
 /* Permit temporary numeric labels.  */
Index: doc/internals.texi
===================================================================
RCS file: /cvs/src/src/gas/doc/internals.texi,v
retrieving revision 1.16
diff -u -p -w -r1.16 internals.texi
--- internals.texi	2000/07/08 22:07:54	1.16
+++ internals.texi	2000/08/22 01:03:35
@@ -1183,6 +1183,15 @@ If you define this macro, and the global
 @samp{.align} directive will cause extra space to be allocated.  The linker can
 then discard this space when relaxing the section.
 
+@item TC_LINKRELAX_FIXUP ($var{segT})
+@cindex TC_LINKRELAX_FIXUP
+If defined, this macro allows control over whether fixups for a
+given section will be processed when the @var{linkrelax} variable is
+set.  The macro is given the N_TYPE bits for the section in its
+@var{segT} argument.  If the macro evaluates to a non-zero value
+then the fixups will be converted into relocs, otherwise they will
+be passed to @var{md_apply_fix3} as normal.
+
 @item md_convert_frag
 @cindex md_convert_frag
 GAS will call this for each rs_machine_dependent fragment.

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