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]

[patch] Add arm .object_arch directive


Under some circumstances it's desirable to have the assembler accept one set 
of instructions, but mark the object file as using a different (older) 
architecture.

Current there is no way to achieve this. An object is marked as requiring an 
architecture if either insns from that architecture are used, or if the user 
requests a specific architecture.

My motivation for this is libgcc. It contains unwinding code for several 
different CPUs, with the appropriate code being selected at runtime. Some of 
these routines contain armv5 code. However marking the object as armv5 is 
wrong because that will make the linker think it can use armv5 instructions 
in the rest of the application.

The attached patch adds a .object_arch directive which allows the user to 
override the architecture recorded in the object file.

Ok?

Paul

2006-09-08  Paul Brook  <paul@codesourcery.com>

	gas/
	* config/tc-arm.c (object_arch): New variable.
	(s_arm_object_arch): New function.
	(md_pseudo_table): Add object_arch.
	(aeabi_set_public_attributes): Obey object_arch.
	* doc/c-arm.texi: Document .object_arch.
Index: gas/config/tc-arm.c
===================================================================
RCS file: /var/cvsroot/src-cvs/src/gas/config/tc-arm.c,v
retrieving revision 1.250.2.31
diff -u -p -r1.250.2.31 tc-arm.c
--- gas/config/tc-arm.c	7 Sep 2006 20:02:44 -0000	1.250.2.31
+++ gas/config/tc-arm.c	8 Sep 2006 17:04:44 -0000
@@ -161,6 +161,7 @@ static const arm_feature_set *mcpu_fpu_o
 static const arm_feature_set *march_cpu_opt = NULL;
 static const arm_feature_set *march_fpu_opt = NULL;
 static const arm_feature_set *mfpu_opt = NULL;
+static const arm_feature_set *object_arch = NULL;
 
 /* Constants for known architecture features.  */
 static const arm_feature_set fpu_default = FPU_DEFAULT;
@@ -3880,6 +3881,7 @@ bad:
 }
 
 static void s_arm_arch (int);
+static void s_arm_object_arch (int);
 static void s_arm_cpu (int);
 static void s_arm_fpu (int);
 #endif /* OBJ_ELF */
@@ -3928,6 +3930,7 @@ const pseudo_typeS md_pseudo_table[] =
   { "unwind_raw",	s_arm_unwind_raw,	0 },
   { "cpu",		s_arm_cpu,		0 },
   { "arch",		s_arm_arch,		0 },
+  { "object_arch",	s_arm_object_arch,	0 },
   { "fpu",		s_arm_fpu,		0 },
   { "eabi_attribute",	s_arm_eabi_attribute,	0 },
 #else
@@ -19938,7 +19941,13 @@ aeabi_set_public_attributes (void)
   ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
   ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
   ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
-    
+  /*Allow the user to override the reported architecture.  */
+  if (object_arch)
+    {
+      ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
+      ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
+    }
+
   tmp = flags;
   arch = 0;
   for (p = cpu_arch_ver; p->val; p++)
@@ -20101,6 +20110,37 @@ s_arm_arch (int ignored ATTRIBUTE_UNUSED
 }
 
 
+/* Parse a .object_arch directive.  */
+
+static void
+s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
+{
+  const struct arm_arch_option_table *opt;
+  char saved_char;
+  char *name;
+
+  name = input_line_pointer;
+  while (*input_line_pointer && !ISSPACE(*input_line_pointer))
+    input_line_pointer++;
+  saved_char = *input_line_pointer;
+  *input_line_pointer = 0;
+
+  /* Skip the first "all" entry.  */
+  for (opt = arm_archs + 1; opt->name != NULL; opt++)
+    if (streq (opt->name, name))
+      {
+	object_arch = &opt->value;
+	*input_line_pointer = saved_char;
+	demand_empty_rest_of_line ();
+	return;
+      }
+
+  as_bad (_("unknown architecture `%s'\n"), name);
+  *input_line_pointer = saved_char;
+  ignore_rest_of_line ();
+}
+
+
 /* Parse a .fpu directive.  */
 
 static void
Index: gas/doc/c-arm.texi
===================================================================
RCS file: /var/cvsroot/src-cvs/src/gas/doc/c-arm.texi,v
retrieving revision 1.37.2.3
diff -u -p -r1.37.2.3 c-arm.texi
--- gas/doc/c-arm.texi	15 Aug 2006 10:50:40 -0000	1.37.2.3
+++ gas/doc/c-arm.texi	8 Sep 2006 17:03:09 -0000
@@ -612,6 +612,12 @@ for the @option{-mcpu} commandline optio
 Select the target architecture.  Valid values for @var{name} are the same as
 for the @option{-march} commandline option.
 
+@cindex @code{.object_arch} directive, ARM
+@item .object_arch @var{name}
+Override the architecture recorded in the EABI object attribute section.
+Valid values for @var{name} are the same as for the @code{.arch} directive.
+Typically this is useful when code uses runtime detection of CPU features.
+
 @cindex @code{.fpu} directive, ARM
 @item .fpu @var{name}
 Select the floating point unit to assemble for.  Valid values for @var{name}

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