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]

ARM long branch stubs: cleanup


Hi all,

With the attached small patch, I propose to remove an error-prone switch statement to get the correct stub template and size in arm_size_one_stub().
It is replaced by an (error-prone :-) array defined next to the stub themselves.


Maybe it would save some maintenance issues.

This is a subjective and cosmetic patch :-)

Christophe.
2009-03-06  Christophe lyon  <christophe.lyon@st.com>
	bfd/
	* elf32-arm.c (stub_def): New type.
	(stub_definition): New array, containing stub template pointers
	and sizes.
	(arm_size_one_stub): Make use of stub_definitions.
Index: bfd/elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.180
diff -u -p -r1.180 elf32-arm.c
--- bfd/elf32-arm.c	6 Mar 2009 08:57:57 -0000	1.180
+++ bfd/elf32-arm.c	6 Mar 2009 17:02:57 -0000
@@ -2155,6 +2155,31 @@ enum elf32_arm_stub_type
   arm_stub_long_branch_thumb_only_pic,
 };
 
+typedef struct
+{
+  const insn_sequence* template;
+  int template_size;
+}  stub_def;
+
+#define STUB_DEF(A) {(A), ARRAY_SIZE(A)}
+
+/* Caution: this array has to be kept in sync with the above stub
+   definitions.  */
+static const stub_def stub_definitions[] =
+  {
+    {NULL, 0},
+    STUB_DEF(elf32_arm_stub_long_branch_any_any),
+    STUB_DEF(elf32_arm_stub_long_branch_v4t_arm_thumb),
+    STUB_DEF(elf32_arm_stub_long_branch_thumb_only),
+    STUB_DEF(elf32_arm_stub_long_branch_v4t_thumb_arm),
+    STUB_DEF(elf32_arm_stub_short_branch_v4t_thumb_arm),
+    STUB_DEF(elf32_arm_stub_long_branch_any_arm_pic),
+    STUB_DEF(elf32_arm_stub_long_branch_any_thumb_pic),
+    STUB_DEF(elf32_arm_stub_long_branch_v4t_arm_thumb_pic),
+    STUB_DEF(elf32_arm_stub_long_branch_v4t_thumb_arm_pic),
+    STUB_DEF(elf32_arm_stub_long_branch_thumb_only_pic)
+  };
+
 struct elf32_arm_stub_hash_entry
 {
   /* Base hash table entry structure.  */
@@ -3322,52 +3358,11 @@ arm_size_one_stub (struct bfd_hash_entry
   stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
   htab = (struct elf32_arm_link_hash_table *) in_arg;
 
-  switch (stub_entry->stub_type)
-    {
-    case arm_stub_long_branch_any_any:
-      template =  elf32_arm_stub_long_branch_any_any;
-      template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_any);
-      break;
-    case arm_stub_long_branch_v4t_arm_thumb:
-      template =  elf32_arm_stub_long_branch_v4t_arm_thumb;
-      template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_arm_thumb);
-      break;
-    case arm_stub_long_branch_thumb_only:
-      template =  elf32_arm_stub_long_branch_thumb_only;
-      template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_thumb_only);
-      break;
-    case arm_stub_long_branch_v4t_thumb_arm:
-      template =  elf32_arm_stub_long_branch_v4t_thumb_arm;
-      template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_arm);
-      break;
-    case arm_stub_short_branch_v4t_thumb_arm:
-      template =  elf32_arm_stub_short_branch_v4t_thumb_arm;
-      template_size = ARRAY_SIZE (elf32_arm_stub_short_branch_v4t_thumb_arm);
-      break;
-    case arm_stub_long_branch_any_arm_pic:
-      template = elf32_arm_stub_long_branch_any_arm_pic;
-      template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_arm_pic);
-      break;
-    case arm_stub_long_branch_any_thumb_pic:
-      template = elf32_arm_stub_long_branch_any_thumb_pic;
-      template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_thumb_pic);
-      break;
-    case arm_stub_long_branch_v4t_arm_thumb_pic:
-      template = elf32_arm_stub_long_branch_v4t_arm_thumb_pic;
-      template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_arm_thumb_pic);
-      break;
-    case arm_stub_long_branch_v4t_thumb_arm_pic:
-      template = elf32_arm_stub_long_branch_v4t_thumb_arm_pic;
-      template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_arm_pic);
-      break;
-    case arm_stub_long_branch_thumb_only_pic:
-      template = elf32_arm_stub_long_branch_thumb_only_pic;
-      template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_thumb_only_pic);
-      break;
-    default:
-      BFD_FAIL ();
-      return FALSE;
-    }
+  BFD_ASSERT((stub_entry->stub_type > arm_stub_none)
+	     && stub_entry->stub_type < ARRAY_SIZE(stub_definitions));
+
+  template = stub_definitions[stub_entry->stub_type].template;
+  template_size = stub_definitions[stub_entry->stub_type].template_size;
 
   size = 0;
   for (i = 0; i < template_size; i++)

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