This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

Re: PPC code generation question


On Mon, Feb 25, 2008 at 09:03:58PM +1030, Alan Modra wrote:
> I'd say it is a bug.  Fixup processing accesses ppc_cpu (*), so gets
> the value at the end of the file.  We probably ought to save the
> current value of ppc_cpu in the fixup and use that.
> 
> *) md_apply_fix calls ppc_insert_operand which uses ppc_cpu.

	* config/tc-ppc.h (struct _ppc_fix_extra): New.
	(ppc_cpu): Declare.
	(TC_FIX_TYPE, TC_INIT_FIX_DATA): Define.
	* config/tc-ppc.c (ppu_cpu): Make global.
	(ppc_insert_operand): Add ppu_cpu parameter.
	(md_assemble): Adjust for above change.
	(md_apply_fix): Pass tc_fix_data.ppc_cpu to ppc_insert_operand.

Index: gas/config/tc-ppc.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-ppc.c,v
retrieving revision 1.133
diff -u -p -r1.133 tc-ppc.c
--- gas/config/tc-ppc.c	4 Jan 2008 14:53:50 -0000	1.133
+++ gas/config/tc-ppc.c	1 Mar 2008 06:53:35 -0000
@@ -178,6 +178,10 @@ const char ppc_symbol_chars[] = "%[";
 
 /* The dwarf2 data alignment, adjusted for 32 or 64 bit.  */
 int ppc_cie_data_alignment;
+
+/* The type of processor we are assembling for.  This is one or more
+   of the PPC_OPCODE flags defined in opcode/ppc.h.  */
+unsigned long ppc_cpu = 0;
 
 /* The target specific pseudo-ops which we support.  */
 
@@ -699,10 +703,6 @@ ppc_parse_name (const char *name, expres
 
 /* Local variables.  */
 
-/* The type of processor we are assembling for.  This is one or more
-   of the PPC_OPCODE flags defined in opcode/ppc.h.  */
-static unsigned long ppc_cpu = 0;
-
 /* Whether to target xcoff64/elf64.  */
 static unsigned int ppc_obj64 = BFD_DEFAULT_TARGET_SIZE == 64;
 
@@ -1528,6 +1528,7 @@ static unsigned long
 ppc_insert_operand (unsigned long insn,
 		    const struct powerpc_operand *operand,
 		    offsetT val,
+		    unsigned long ppc_cpu,
 		    char *file,
 		    unsigned int line)
 {
@@ -2484,7 +2485,7 @@ md_assemble (char *str)
       else if (ex.X_op == O_register)
 	{
 	  insn = ppc_insert_operand (insn, operand, ex.X_add_number,
-				     (char *) NULL, 0);
+				     ppc_cpu, (char *) NULL, 0);
 	}
       else if (ex.X_op == O_constant)
 	{
@@ -2553,7 +2554,7 @@ md_assemble (char *str)
 	      }
 #endif /* OBJ_ELF */
 	  insn = ppc_insert_operand (insn, operand, ex.X_add_number,
-				     (char *) NULL, 0);
+				     ppc_cpu, (char *) NULL, 0);
 	}
 #ifdef OBJ_ELF
       else if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
@@ -2565,7 +2566,7 @@ md_assemble (char *str)
 	      break;
 	    case BFD_RELOC_PPC_TLS:
 	      insn = ppc_insert_operand (insn, operand, ppc_obj64 ? 13 : 2,
-					 (char *) NULL, 0);
+					 ppc_cpu, (char *) NULL, 0);
 	      break;
 	  /* We'll only use the 32 (or 64) bit form of these relocations
 	     in constants.  Instructions get the 16 bit form.  */
@@ -5632,6 +5633,7 @@ md_apply_fix (fixS *fixP, valueT *valP, 
       else
 	insn = bfd_getl32 ((unsigned char *) where);
       insn = ppc_insert_operand (insn, operand, (offsetT) value,
+				 fixP->tc_fix_data.ppc_cpu,
 				 fixP->fx_file, fixP->fx_line);
       if (target_big_endian)
 	bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
Index: gas/config/tc-ppc.h
===================================================================
RCS file: /cvs/src/src/gas/config/tc-ppc.h,v
retrieving revision 1.35
diff -u -p -r1.35 tc-ppc.h
--- gas/config/tc-ppc.h	3 Jul 2007 11:01:04 -0000	1.35
+++ gas/config/tc-ppc.h	1 Mar 2008 06:53:35 -0000
@@ -90,6 +90,19 @@ extern void ppc_handle_align (struct fra
       && (((FRAGP)->fr_address + (FRAGP)->insn_addr) & 3) != 0)		\
     as_bad_where ((FRAGP)->fr_file, (FRAGP)->fr_line,			\
 		  _("instruction address is not a multiple of 4"));
+
+/* Arrange to store the value of ppc_cpu at the site of a fixup
+   for later use in md_apply_fix.  */
+struct _ppc_fix_extra
+{
+  unsigned long ppc_cpu;
+};
+
+extern unsigned long ppc_cpu;
+
+#define TC_FIX_TYPE struct _ppc_fix_extra
+#define TC_INIT_FIX_DATA(FIXP) \
+  do { (FIXP)->tc_fix_data.ppc_cpu = ppc_cpu; } while (0)
 
 #ifdef TE_PE
 

-- 
Alan Modra
Australia Development Lab, IBM


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