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]

[GOLD] [PATCH 2/3] aarch64.cc:Stub_template: add array ref constructor


Add array ref constructor to catch problems like:
  https://sourceware.org/ml/binutils/2017-01/msg00282.html
at compile time.

gold/ChangeLog:
2017-01-24  Pedro Alves  <palves@redhat.com>

	* aarch64.cc (struct Stub_template) <Insntype>: New typedef.
	<insns>: Use it.
	<Stub_template>: New array and default construtors.
	(Stub_template_repertoire): Delete ST_NONE_INSNS and create
	corresponding empty template instead of calling
	install_insn_template.  Adjust install_insn_template_insns to call
	array constructor.
---
 gold/aarch64.cc | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/gold/aarch64.cc b/gold/aarch64.cc
index bd9500e..c2531f3 100644
--- a/gold/aarch64.cc
+++ b/gold/aarch64.cc
@@ -703,7 +703,18 @@ enum
 template<bool big_endian>
 struct Stub_template
 {
-  const typename AArch64_insn_utilities<big_endian>::Insntype* insns;
+  typedef typename AArch64_insn_utilities<big_endian>::Insntype Insntype;
+
+  Stub_template ()
+    : insns(NULL), insn_num(0)
+  { }
+
+  template<size_t insn_num_>
+  Stub_template(const Insntype (&insns_)[insn_num_])
+    : insns(insns_), insn_num(insn_num_)
+  { }
+
+  const Insntype* insns;
   const int insn_num;
 };
 
@@ -746,8 +757,6 @@ template<bool big_endian>
 Stub_template_repertoire<big_endian>::Stub_template_repertoire()
 {
   // Insn array definitions.
-  const static Insntype ST_NONE_INSNS[] = {};
-
   const static Insntype ST_ADRP_BRANCH_INSNS[] =
     {
       0x90000010,	/*	adrp	ip0, X		   */
@@ -784,14 +793,15 @@ Stub_template_repertoire<big_endian>::Stub_template_repertoire()
       0x14000000,    /* b <label> */
     };
 
-#define install_insn_template_insns(T, I) \
-  const static Stub_template<big_endian> template_##T = {  \
-    I##_INSNS, sizeof(I##_INSNS) / sizeof(I##_INSNS[0]) }; \
+  const static Stub_template<big_endian> T_ST_NONE_INSNS;
+  this->stub_templates_[ST_NONE] = &T_ST_NONE_INSNS;
+
+#define install_insn_template_insns(T, I)				\
+  const static Stub_template<big_endian> template_##T (I##_INSNS);	\
   this->stub_templates_[T] = &template_##T
 #define install_insn_template(T)		\
   install_insn_template_insns(T, T)
 
-  install_insn_template(ST_NONE);
   install_insn_template(ST_ADRP_BRANCH);
   install_insn_template(ST_LONG_BRANCH_ABS);
   install_insn_template(ST_LONG_BRANCH_PCREL);
-- 
2.5.5



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