diff --git a/sim/arm/ChangeLog b/sim/arm/ChangeLog
index 2ce94292420c..488178a5df93 100644
--- a/sim/arm/ChangeLog
+++ b/sim/arm/ChangeLog
@@ -1,3 +1,11 @@
+2017-02-13  Mike Frysinger  <vapier@gentoo.org>
+
+	* armos.c: Include libiberty.h.
+	(SWIopen): Use ARRAY_SIZE.
+	* armsupp.c: Include libiberty.h.
+	(ModeToBank): Use ARRAY_SIZE.
+	* wrapper.c (sim_target_parse_command_line): Likewise.
+
 2016-07-14  Nick Clifton  <nickc@redhat.com>
 
 	* armemu.c (Multiply64): Only issue error messages about invalid
diff --git a/sim/arm/armos.c b/sim/arm/armos.c
index ea3d22979ac8..76c449b73d0f 100644
--- a/sim/arm/armos.c
+++ b/sim/arm/armos.c
@@ -23,6 +23,7 @@
 
 #include "config.h"
 #include "ansidecl.h"
+#include "libiberty.h"
 
 #include <time.h>
 #include <errno.h>
@@ -260,7 +261,7 @@ SWIopen (ARMul_State * state, ARMword name, ARMword SWIflags)
     return;
 
   /* Now we need to decode the Demon open mode.  */
-  if (SWIflags >= sizeof (translate_open_mode) / sizeof (translate_open_mode[0]))
+  if (SWIflags >= ARRAY_SIZE (translate_open_mode))
     flags = 0;
   else
     flags = translate_open_mode[SWIflags];
diff --git a/sim/arm/armsupp.c b/sim/arm/armsupp.c
index 3ff4bf9a6b05..11bb53c5b704 100644
--- a/sim/arm/armsupp.c
+++ b/sim/arm/armsupp.c
@@ -17,6 +17,7 @@
 #include "armdefs.h"
 #include "armemu.h"
 #include "ansidecl.h"
+#include "libiberty.h"
 #include <math.h>
 
 /* Definitions for the support routines.  */
@@ -373,7 +374,7 @@ ModeToBank (ARMword mode)
     DUMMYBANK, DUMMYBANK, DUMMYBANK, SYSTEMBANK
   };
 
-  if (mode >= (sizeof (bankofmode) / sizeof (bankofmode[0])))
+  if (mode >= ARRAY_SIZE (bankofmode))
     return DUMMYBANK;
 
   return bankofmode[mode];
diff --git a/sim/arm/wrapper.c b/sim/arm/wrapper.c
index efbeef943bce..01f88d11e57c 100644
--- a/sim/arm/wrapper.c
+++ b/sim/arm/wrapper.c
@@ -740,7 +740,7 @@ sim_target_parse_command_line (int argc, char ** argv)
 	{
 	  int i;
 
-	  for (i = sizeof options / sizeof options[0]; i--;)
+	  for (i = ARRAY_SIZE (options); i--;)
 	    if (strncmp (ptr, options[i].swi_option,
 			 strlen (options[i].swi_option)) == 0)
 	      {
diff --git a/sim/cris/ChangeLog b/sim/cris/ChangeLog
index ef96ec7faa0f..1257a9e4fe5c 100644
--- a/sim/cris/ChangeLog
+++ b/sim/cris/ChangeLog
@@ -1,3 +1,9 @@
+2017-02-13  Mike Frysinger  <vapier@gentoo.org>
+
+	* decodev10.c (crisv10f_init_idesc_table): Use ARRAY_SIZE.
+	* decodev32.c (crisv32f_init_idesc_table): Likewise.
+	* sim-if.c (sim_open): Likewise.
+
 2016-01-10  Mike Frysinger  <vapier@gentoo.org>
 
 	* config.in, configure: Regenerate.
diff --git a/sim/cris/decodev10.c b/sim/cris/decodev10.c
index c4c174f3c405..d9242e35415c 100644
--- a/sim/cris/decodev10.c
+++ b/sim/cris/decodev10.c
@@ -302,7 +302,7 @@ crisv10f_init_idesc_table (SIM_CPU *cpu)
     init_idesc (cpu, id, t);
 
   /* Now fill in the values for the chosen cpu.  */
-  for (t = crisv10f_insn_sem, tend = t + sizeof (crisv10f_insn_sem) / sizeof (*t);
+  for (t = crisv10f_insn_sem, tend = t + ARRAY_SIZE (crisv10f_insn_sem);
        t != tend; ++t)
     {
       init_idesc (cpu, & table[t->index], t);
diff --git a/sim/cris/decodev32.c b/sim/cris/decodev32.c
index 4ea146d2501d..10162e883690 100644
--- a/sim/cris/decodev32.c
+++ b/sim/cris/decodev32.c
@@ -306,7 +306,7 @@ crisv32f_init_idesc_table (SIM_CPU *cpu)
     init_idesc (cpu, id, t);
 
   /* Now fill in the values for the chosen cpu.  */
-  for (t = crisv32f_insn_sem, tend = t + sizeof (crisv32f_insn_sem) / sizeof (*t);
+  for (t = crisv32f_insn_sem, tend = t + ARRAY_SIZE (crisv32f_insn_sem);
        t != tend; ++t)
     {
       init_idesc (cpu, & table[t->index], t);
diff --git a/sim/cris/sim-if.c b/sim/cris/sim-if.c
index 8e3b6677fa1a..2ccb5289bdb4 100644
--- a/sim/cris/sim-if.c
+++ b/sim/cris/sim-if.c
@@ -786,7 +786,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
       /* Note that the linux kernel does not correctly compute the storage
 	 needs for the static-exe AUX vector.  */
 
-      csp -= sizeof (auxv_entries) / sizeof (auxv_entries[0]) * 4 * 2;
+      csp -= ARRAY_SIZE (auxv_entries) * 4 * 2;
 
       csp -= (envc + 1) * 4;
       csp -= (my_argc + 1) * 4;
@@ -874,7 +874,7 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
 	goto abandon_chip;
 
       if (bfd_get_flavour (abfd) == bfd_target_elf_flavour)
-	for (i = 0; i < sizeof (auxv_entries) / sizeof (auxv_entries[0]); i++)
+	for (i = 0; i < ARRAY_SIZE (auxv_entries); i++)
 	  {
 	    write_dword (csp, auxv_entries[i].id);
 	    write_dword (csp + 4,
diff --git a/sim/frv/ChangeLog b/sim/frv/ChangeLog
index 1642a26d0539..68bf3886dbed 100644
--- a/sim/frv/ChangeLog
+++ b/sim/frv/ChangeLog
@@ -1,3 +1,7 @@
+2017-02-13  Mike Frysinger  <vapier@gentoo.org>
+
+	* decode.c (frvbf_init_idesc_table): Use ARRAY_SIZE.
+
 2016-01-10  Mike Frysinger  <vapier@gentoo.org>
 
 	* config.in, configure: Regenerate.
diff --git a/sim/frv/decode.c b/sim/frv/decode.c
index 6ce49a8d8655..69c155ead61f 100644
--- a/sim/frv/decode.c
+++ b/sim/frv/decode.c
@@ -841,7 +841,7 @@ frvbf_init_idesc_table (SIM_CPU *cpu)
     init_idesc (cpu, id, t);
 
   /* Now fill in the values for the chosen cpu.  */
-  for (t = frvbf_insn_sem, tend = t + sizeof (frvbf_insn_sem) / sizeof (*t);
+  for (t = frvbf_insn_sem, tend = t + ARRAY_SIZE (frvbf_insn_sem);
        t != tend; ++t)
     {
       init_idesc (cpu, & table[t->index], t);
diff --git a/sim/iq2000/ChangeLog b/sim/iq2000/ChangeLog
index 5e91cbd2243a..e2290ec02969 100644
--- a/sim/iq2000/ChangeLog
+++ b/sim/iq2000/ChangeLog
@@ -1,3 +1,7 @@
+2017-02-13  Mike Frysinger  <vapier@gentoo.org>
+
+	* decode.c (iq2000bf_init_idesc_table): Use ARRAY_SIZE.
+
 2016-01-10  Mike Frysinger  <vapier@gentoo.org>
 
 	* config.in, configure: Regenerate.
diff --git a/sim/iq2000/decode.c b/sim/iq2000/decode.c
index 7d6bd2d911a4..d3d4dfa97280 100644
--- a/sim/iq2000/decode.c
+++ b/sim/iq2000/decode.c
@@ -242,7 +242,7 @@ iq2000bf_init_idesc_table (SIM_CPU *cpu)
     init_idesc (cpu, id, t);
 
   /* Now fill in the values for the chosen cpu.  */
-  for (t = iq2000bf_insn_sem, tend = t + sizeof (iq2000bf_insn_sem) / sizeof (*t);
+  for (t = iq2000bf_insn_sem, tend = t + ARRAY_SIZE (iq2000bf_insn_sem);
        t != tend; ++t)
     {
       init_idesc (cpu, & table[t->index], t);
diff --git a/sim/lm32/ChangeLog b/sim/lm32/ChangeLog
index 51869baa1b14..b724a46b3f57 100644
--- a/sim/lm32/ChangeLog
+++ b/sim/lm32/ChangeLog
@@ -1,3 +1,7 @@
+2017-02-13  Mike Frysinger  <vapier@gentoo.org>
+
+	* decode.c (lm32bf_init_idesc_table): Use ARRAY_SIZE.
+
 2016-08-15  Mike Frysinger  <vapier@gentoo.org>
 
 	* sim-if.c (find_limit): Change prototype to take a SIM_DESC.
diff --git a/sim/lm32/decode.c b/sim/lm32/decode.c
index 207c9c7386de..52e7d8428129 100644
--- a/sim/lm32/decode.c
+++ b/sim/lm32/decode.c
@@ -160,7 +160,7 @@ lm32bf_init_idesc_table (SIM_CPU *cpu)
     init_idesc (cpu, id, t);
 
   /* Now fill in the values for the chosen cpu.  */
-  for (t = lm32bf_insn_sem, tend = t + sizeof (lm32bf_insn_sem) / sizeof (*t);
+  for (t = lm32bf_insn_sem, tend = t + ARRAY_SIZE (lm32bf_insn_sem);
        t != tend; ++t)
     {
       init_idesc (cpu, & table[t->index], t);
diff --git a/sim/m32c/ChangeLog b/sim/m32c/ChangeLog
index 4205507addcb..8f62fc30f907 100644
--- a/sim/m32c/ChangeLog
+++ b/sim/m32c/ChangeLog
@@ -1,3 +1,8 @@
+2017-02-13  Mike Frysinger  <vapier@gentoo.org>
+
+	* srcdest.c: Include libiberty.h.
+	(decode_sd23): Use ARRAY_SIZE.
+
 2016-01-10  Mike Frysinger  <vapier@gentoo.org>
 
 	* config.in, configure: Regenerate.
diff --git a/sim/m32c/srcdest.c b/sim/m32c/srcdest.c
index 8dfe9d0f19ce..937779b442ee 100644
--- a/sim/m32c/srcdest.c
+++ b/sim/m32c/srcdest.c
@@ -22,6 +22,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "libiberty.h"
 #include "cpu.h"
 #include "mem.h"
 
@@ -354,7 +355,7 @@ decode_sd23 (int bbb, int bb, int bytes, int ind, int add)
   srcdest sd;
   int code = (bbb << 2) | bb;
 
-  if (code >= sizeof (modes23) / sizeof (modes23[0]))
+  if (code >= ARRAY_SIZE (modes23))
     abort ();
 
   if (trace)
diff --git a/sim/m32r/ChangeLog b/sim/m32r/ChangeLog
index a0be81e29642..6a9a85c6650c 100644
--- a/sim/m32r/ChangeLog
+++ b/sim/m32r/ChangeLog
@@ -1,3 +1,9 @@
+2017-02-13  Mike Frysinger  <vapier@gentoo.org>
+
+	* decode.c (m32rbf_init_idesc_table): Use ARRAY_SIZE.
+	* decode2.c (m32r2f_init_idesc_table): Likewise.
+	* decodex.c (m32rxf_init_idesc_table): Likewise.
+
 2016-01-10  Mike Frysinger  <vapier@gentoo.org>
 
 	* config.in, configure: Regenerate.
diff --git a/sim/m32r/decode.c b/sim/m32r/decode.c
index 9f7998e0a45d..70494bccef85 100644
--- a/sim/m32r/decode.c
+++ b/sim/m32r/decode.c
@@ -202,7 +202,7 @@ m32rbf_init_idesc_table (SIM_CPU *cpu)
     init_idesc (cpu, id, t);
 
   /* Now fill in the values for the chosen cpu.  */
-  for (t = m32rbf_insn_sem, tend = t + sizeof (m32rbf_insn_sem) / sizeof (*t);
+  for (t = m32rbf_insn_sem, tend = t + ARRAY_SIZE (m32rbf_insn_sem);
        t != tend; ++t)
     {
       init_idesc (cpu, & table[t->index], t);
diff --git a/sim/m32r/decode2.c b/sim/m32r/decode2.c
index a8833dbb8f09..f138d7cb21d0 100644
--- a/sim/m32r/decode2.c
+++ b/sim/m32r/decode2.c
@@ -235,7 +235,7 @@ m32r2f_init_idesc_table (SIM_CPU *cpu)
     init_idesc (cpu, id, t);
 
   /* Now fill in the values for the chosen cpu.  */
-  for (t = m32r2f_insn_sem, tend = t + sizeof (m32r2f_insn_sem) / sizeof (*t);
+  for (t = m32r2f_insn_sem, tend = t + ARRAY_SIZE (m32r2f_insn_sem);
        t != tend; ++t)
     {
       init_idesc (cpu, & table[t->index], t);
diff --git a/sim/m32r/decodex.c b/sim/m32r/decodex.c
index 4274b523ec57..0b695cc28ce9 100644
--- a/sim/m32r/decodex.c
+++ b/sim/m32r/decodex.c
@@ -228,7 +228,7 @@ m32rxf_init_idesc_table (SIM_CPU *cpu)
     init_idesc (cpu, id, t);
 
   /* Now fill in the values for the chosen cpu.  */
-  for (t = m32rxf_insn_sem, tend = t + sizeof (m32rxf_insn_sem) / sizeof (*t);
+  for (t = m32rxf_insn_sem, tend = t + ARRAY_SIZE (m32rxf_insn_sem);
        t != tend; ++t)
     {
       init_idesc (cpu, & table[t->index], t);
diff --git a/sim/m68hc11/ChangeLog b/sim/m68hc11/ChangeLog
index bc69d846b21c..8947c4b7bc2a 100644
--- a/sim/m68hc11/ChangeLog
+++ b/sim/m68hc11/ChangeLog
@@ -1,3 +1,12 @@
+2017-02-13  Mike Frysinger  <vapier@gentoo.org>
+
+	* gencode.c: Include libiberty.h.
+	(TABLE_SIZE): Delete.
+	(find_opcode_pattern): Change TABLE_SIZE to ARRAY_SIZE.
+	(gen_interpreter): Likewise.
+	* interrupts.c (TableSize): Delete.
+	(interrupts_update_pending): Change TableSize to ARRAY_SIZE.
+
 2016-08-16  Mike Frysinger  <vapier@gentoo.org>
 
 	* sim-main.h (inline): Delete define.
diff --git a/sim/m68hc11/gencode.c b/sim/m68hc11/gencode.c
index e207606cb36a..3e85c9341843 100644
--- a/sim/m68hc11/gencode.c
+++ b/sim/m68hc11/gencode.c
@@ -24,10 +24,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <errno.h>
 
 #include "ansidecl.h"
+#include "libiberty.h"
 #include "opcode/m68hc11.h"
 
-#define TABLE_SIZE(X)	    (sizeof(X) / sizeof(X[0]))
-
 /* Combination of CCR flags.  */
 #define M6811_ZC_BIT	M6811_Z_BIT|M6811_C_BIT
 #define M6811_NZ_BIT	M6811_N_BIT|M6811_Z_BIT
@@ -1812,7 +1811,7 @@ find_opcode_pattern (const struct m6811_opcode_def *opcode)
     {
       pattern = opcode->name;
     }
-  for (i = 0; i < TABLE_SIZE(m6811_opcode_patterns); i++)
+  for (i = 0; i < ARRAY_SIZE (m6811_opcode_patterns); i++)
     {
       if (strcmp (m6811_opcode_patterns[i].name, pattern) == 0)
 	{
@@ -2036,13 +2035,13 @@ gen_interpreter (FILE *fp)
 {
   int col = 0;
 
-  prepare_table (m6811_page1_opcodes, TABLE_SIZE (m6811_page1_opcodes));
-  prepare_table (m6811_page2_opcodes, TABLE_SIZE (m6811_page2_opcodes));
-  prepare_table (m6811_page3_opcodes, TABLE_SIZE (m6811_page3_opcodes));
-  prepare_table (m6811_page4_opcodes, TABLE_SIZE (m6811_page4_opcodes));
+  prepare_table (m6811_page1_opcodes, ARRAY_SIZE (m6811_page1_opcodes));
+  prepare_table (m6811_page2_opcodes, ARRAY_SIZE (m6811_page2_opcodes));
+  prepare_table (m6811_page3_opcodes, ARRAY_SIZE (m6811_page3_opcodes));
+  prepare_table (m6811_page4_opcodes, ARRAY_SIZE (m6811_page4_opcodes));
 
-  prepare_table (m6812_page1_opcodes, TABLE_SIZE (m6812_page1_opcodes));
-  prepare_table (m6812_page2_opcodes, TABLE_SIZE (m6812_page2_opcodes));
+  prepare_table (m6812_page1_opcodes, ARRAY_SIZE (m6812_page1_opcodes));
+  prepare_table (m6812_page2_opcodes, ARRAY_SIZE (m6812_page2_opcodes));
 
   /* Generate header of interpretor.  */
   print (fp, col, "/* File generated automatically by gencode. */\n");
@@ -2051,25 +2050,25 @@ gen_interpreter (FILE *fp)
   if (cpu_type & cpu6811)
     {
       gen_cycle_table (fp, "cycles_page1", m6811_page1_opcodes,
-		       TABLE_SIZE (m6811_page1_opcodes));
+		       ARRAY_SIZE (m6811_page1_opcodes));
       gen_cycle_table (fp, "cycles_page2", m6811_page2_opcodes,
-		       TABLE_SIZE (m6811_page2_opcodes));
+		       ARRAY_SIZE (m6811_page2_opcodes));
       gen_cycle_table (fp, "cycles_page3", m6811_page3_opcodes,
-		       TABLE_SIZE (m6811_page3_opcodes));
+		       ARRAY_SIZE (m6811_page3_opcodes));
       gen_cycle_table (fp, "cycles_page4", m6811_page4_opcodes,
-		       TABLE_SIZE (m6811_page4_opcodes));
+		       ARRAY_SIZE (m6811_page4_opcodes));
 
       gen_function_entry (fp, "static void\ncpu_page3_interp", 0);
       gen_interpreter_for_table (fp, indent_level,
 				 m6811_page3_opcodes,
-				 TABLE_SIZE(m6811_page3_opcodes),
+				 ARRAY_SIZE (m6811_page3_opcodes),
 				 "cycles_page3");
       gen_function_close (fp);
   
       gen_function_entry (fp, "static void\ncpu_page4_interp", 0);
       gen_interpreter_for_table (fp, indent_level,
 				 m6811_page4_opcodes,
-				 TABLE_SIZE(m6811_page4_opcodes),
+				 ARRAY_SIZE (m6811_page4_opcodes),
 				 "cycles_page4");
       gen_function_close (fp);
 
@@ -2078,7 +2077,7 @@ gen_interpreter (FILE *fp)
                           USE_SRC8 | USE_DST8);
       gen_interpreter_for_table (fp, indent_level,
 				 m6811_page2_opcodes,
-				 TABLE_SIZE(m6811_page2_opcodes),
+				 ARRAY_SIZE (m6811_page2_opcodes),
 				 "cycles_page2");
       gen_function_close (fp);
 
@@ -2087,22 +2086,22 @@ gen_interpreter (FILE *fp)
                           USE_SRC8 | USE_DST8);
 
       gen_interpreter_for_table (fp, indent_level, m6811_page1_opcodes,
-				 TABLE_SIZE(m6811_page1_opcodes),
+				 ARRAY_SIZE (m6811_page1_opcodes),
 				 "cycles_page1");
       gen_function_close (fp);
     }
   else
     {
       gen_cycle_table (fp, "cycles_page1", m6812_page1_opcodes,
-		       TABLE_SIZE (m6812_page1_opcodes));
+		       ARRAY_SIZE (m6812_page1_opcodes));
       gen_cycle_table (fp, "cycles_page2", m6812_page2_opcodes,
-		       TABLE_SIZE (m6812_page2_opcodes));
+		       ARRAY_SIZE (m6812_page2_opcodes));
 
       gen_function_entry (fp, "static void\ncpu_page2_interp",
                           USE_SRC8 | USE_DST8);
       gen_interpreter_for_table (fp, indent_level,
 				 m6812_page2_opcodes,
-				 TABLE_SIZE(m6812_page2_opcodes),
+				 ARRAY_SIZE (m6812_page2_opcodes),
 				 "cycles_page2");
       gen_function_close (fp);
 
@@ -2111,7 +2110,7 @@ gen_interpreter (FILE *fp)
                           USE_SRC8 | USE_DST8);
 
       gen_interpreter_for_table (fp, indent_level, m6812_page1_opcodes,
-				 TABLE_SIZE(m6812_page1_opcodes),
+				 ARRAY_SIZE (m6812_page1_opcodes),
 				 "cycles_page1");
       gen_function_close (fp);
     }
diff --git a/sim/m68hc11/interrupts.c b/sim/m68hc11/interrupts.c
index 129f3c022aa0..ed826556ca40 100644
--- a/sim/m68hc11/interrupts.c
+++ b/sim/m68hc11/interrupts.c
@@ -91,7 +91,6 @@ struct interrupt_def idefs[] = {
 #endif
 };
 
-#define TableSize(X) (sizeof X / sizeof(X[0]))
 #define CYCLES_MAX ((((signed64) 1) << 62) - 1)
 
 enum
@@ -290,7 +289,7 @@ interrupts_update_pending (struct interrupts *interrupts)
   set_mask = 0;
   ioregs = &interrupts->cpu->ios[0];
   
-  for (i = 0; i < TableSize(idefs); i++)
+  for (i = 0; i < ARRAY_SIZE (idefs); i++)
     {
       struct interrupt_def *idef = &idefs[i];
       uint8 data;
diff --git a/sim/ppc/ChangeLog b/sim/ppc/ChangeLog
index 7ed024e88b32..c0bb1f5b8b46 100644
--- a/sim/ppc/ChangeLog
+++ b/sim/ppc/ChangeLog
@@ -1,3 +1,15 @@
+2017-02-13  Mike Frysinger  <vapier@gentoo.org>
+
+	* cpu.h: Include libiberty.h.
+	* emul_bugapi.c (emul_bugapi_instruction_name): Use ARRAY_SIZE.
+	* emul_generic.h: Include libiberty.h.
+	* emul_netbsd.c (emul_netbsd_syscalls): Use ARRAY_SIZE.
+	* emul_unix.c (convert_to_solaris_stat): Likewise.
+	(emul_solaris_syscalls): Likewise.
+	(emul_linux_syscalls): Likewise.
+	* options.c (print_options): Likewise.
+	* ppc-instructions: Likewise.
+
 2016-01-10  Mike Frysinger  <vapier@gentoo.org>
 
 	* configure.ac (sim-assert): Call AC_MSG_CHECKING,
diff --git a/sim/ppc/cpu.h b/sim/ppc/cpu.h
index cb141f20657a..bafb5e1791a1 100644
--- a/sim/ppc/cpu.h
+++ b/sim/ppc/cpu.h
@@ -34,6 +34,7 @@
 #include "os_emul.h"
 #include "mon.h"
 #include "model.h"
+#include "libiberty.h"
 
 #ifndef CONST_ATTRIBUTE
 #define CONST_ATTRIBUTE __attribute__((__const__))
diff --git a/sim/ppc/emul_bugapi.c b/sim/ppc/emul_bugapi.c
index e33d0cf2995d..8481b6fb39e6 100644
--- a/sim/ppc/emul_bugapi.c
+++ b/sim/ppc/emul_bugapi.c
@@ -339,7 +339,7 @@ emul_bugapi_instruction_name(int call_id)
   static char buffer[40];
   int i;
 
-  for (i = 0; i < sizeof (bug_mapping) / sizeof (bug_mapping[0]); i++)
+  for (i = 0; i < ARRAY_SIZE (bug_mapping); i++)
     {
       if (bug_mapping[i].value == call_id)
 	return bug_mapping[i].info;
diff --git a/sim/ppc/emul_generic.h b/sim/ppc/emul_generic.h
index e697abddbb1d..9ea23d4cbd55 100644
--- a/sim/ppc/emul_generic.h
+++ b/sim/ppc/emul_generic.h
@@ -28,6 +28,7 @@
 #include "tree.h"
 
 #include "bfd.h"
+#include "libiberty.h"
 
 #ifndef INLINE_EMUL_GENERIC
 #define INLINE_EMUL_GENERIC
diff --git a/sim/ppc/emul_netbsd.c b/sim/ppc/emul_netbsd.c
index 12dfb21b3b06..9b80fc25dc81 100644
--- a/sim/ppc/emul_netbsd.c
+++ b/sim/ppc/emul_netbsd.c
@@ -1413,11 +1413,11 @@ static char *(netbsd_signal_names[]) = {
 
 static emul_syscall emul_netbsd_syscalls = {
   netbsd_descriptors,
-  sizeof(netbsd_descriptors) / sizeof(netbsd_descriptors[0]),
+  ARRAY_SIZE (netbsd_descriptors),
   netbsd_error_names,
-  sizeof(netbsd_error_names) / sizeof(netbsd_error_names[0]),
+  ARRAY_SIZE (netbsd_error_names),
   netbsd_signal_names,
-  sizeof(netbsd_signal_names) / sizeof(netbsd_signal_names[0]),
+  ARRAY_SIZE (netbsd_signal_names),
 };
 
 
diff --git a/sim/ppc/emul_unix.c b/sim/ppc/emul_unix.c
index 1475474727ea..3a1c24586fa2 100644
--- a/sim/ppc/emul_unix.c
+++ b/sim/ppc/emul_unix.c
@@ -1147,15 +1147,15 @@ convert_to_solaris_stat(unsigned_word addr,
   target.st_mtim.tv_sec  = H2T_4(host->st_mtime);
   target.st_mtim.tv_usec = 0;
 
-  for (i = 0; i < sizeof (target.st_pad1) / sizeof (target.st_pad1[0]); i++)
+  for (i = 0; i < ARRAY_SIZE (target.st_pad1); i++)
     target.st_pad1[i] = 0;
 
-  for (i = 0; i < sizeof (target.st_pad2) / sizeof (target.st_pad2[0]); i++)
+  for (i = 0; i < ARRAY_SIZE (target.st_pad2); i++)
     target.st_pad2[i] = 0;
 
   target.st_pad3 = 0;
 
-  for (i = 0; i < sizeof (target.st_pad4) / sizeof (target.st_pad4[0]); i++)
+  for (i = 0; i < ARRAY_SIZE (target.st_pad4); i++)
     target.st_pad4[i] = 0;
 
   /* For now, just punt and always say it is a ufs file */
@@ -1945,11 +1945,11 @@ static char *(solaris_signal_names[]) = {
 
 static emul_syscall emul_solaris_syscalls = {
   solaris_descriptors,
-  sizeof(solaris_descriptors) / sizeof(solaris_descriptors[0]),
+  ARRAY_SIZE (solaris_descriptors),
   solaris_error_names,
-  sizeof(solaris_error_names) / sizeof(solaris_error_names[0]),
+  ARRAY_SIZE (solaris_error_names),
   solaris_signal_names,
-  sizeof(solaris_signal_names) / sizeof(solaris_signal_names[0]),
+  ARRAY_SIZE (solaris_signal_names),
 };
 
 
@@ -2824,11 +2824,11 @@ static char *(linux_signal_names[]) = {
 
 static emul_syscall emul_linux_syscalls = {
   linux_descriptors,
-  sizeof(linux_descriptors) / sizeof(linux_descriptors[0]),
+  ARRAY_SIZE (linux_descriptors),
   linux_error_names,
-  sizeof(linux_error_names) / sizeof(linux_error_names[0]),
+  ARRAY_SIZE (linux_error_names),
   linux_signal_names,
-  sizeof(linux_signal_names) / sizeof(linux_signal_names[0]),
+  ARRAY_SIZE (linux_signal_names),
 };
 
 
diff --git a/sim/ppc/options.c b/sim/ppc/options.c
index 169378ef93dc..ddb492f54fb7 100644
--- a/sim/ppc/options.c
+++ b/sim/ppc/options.c
@@ -216,7 +216,7 @@ print_options (void)
     int max_len = 0;
     int cols;
 
-    for (i = 0; i < sizeof (defines) / sizeof (defines[0]); i++) {
+    for (i = 0; i < ARRAY_SIZE (defines); i++) {
       int len = strlen (defines[i]);
       if (len > max_len)
 	max_len = len;
@@ -227,10 +227,10 @@ print_options (void)
       cols = 1;
 
     printf_filtered ("\n#defines:");
-    for (i = 0; i < sizeof (defines) / sizeof (defines[0]); i++) {
+    for (i = 0; i < ARRAY_SIZE (defines); i++) {
       const char *const prefix = ((i % cols) == 0) ? "\n" : "";
       printf_filtered ("%s  %s%*s", prefix, defines[i],
-		       (((i == (sizeof (defines) / sizeof (defines[0])) - 1)
+		       (((i == ARRAY_SIZE (defines) - 1)
 			 || (((i + 1) % cols) == 0))
 			? 0
 			: max_len + 4 - strlen (defines[i])),
diff --git a/sim/ppc/ppc-instructions b/sim/ppc/ppc-instructions
index 1a2e51afaf2a..5e6d21df561d 100644
--- a/sim/ppc/ppc-instructions
+++ b/sim/ppc/ppc-instructions
@@ -908,7 +908,7 @@ model_print *::model-function::model_mon_info:model_data *model_ptr
 	  tail->suffix_singular = "";
 	}
 
-	for (j = 0; j < (sizeof(ppc_branch_conditional_name) / sizeof(ppc_branch_conditional_name[0])) ; j++) {
+	for (j = 0; j < ARRAY_SIZE (ppc_branch_conditional_name); j++) {
 	  if (model_ptr->nr_branch_conditional[j]) {
 	    tail->next = ZALLOC(model_print);
 	    tail = tail->next;
diff --git a/sim/rx/ChangeLog b/sim/rx/ChangeLog
index 39de491df9f8..d29e429feddf 100644
--- a/sim/rx/ChangeLog
+++ b/sim/rx/ChangeLog
@@ -1,3 +1,8 @@
+2017-02-13  Mike Frysinger  <vapier@gentoo.org>
+
+	* rx.c: Include libiberty.h.
+	(N_RXO, N_RXT): Use ARRAY_SIZE.
+
 2016-07-27  Alan Modra  <amodra@gmail.com>
 
 	* load.c: Don't include libbfd.h.
diff --git a/sim/rx/rx.c b/sim/rx/rx.c
index 82b92b5167d3..28dd2b638d10 100644
--- a/sim/rx/rx.c
+++ b/sim/rx/rx.c
@@ -23,6 +23,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <stdlib.h>
 #include <string.h>
 #include <signal.h>
+#include "libiberty.h"
 
 #include "opcode/rx.h"
 #include "cpu.h"
@@ -151,8 +152,8 @@ static const char * optype_names[] = {
   "RbRi"	/* [Rb + scale * Ri] */
 };
 
-#define N_RXO (sizeof(id_names)/sizeof(id_names[0]))
-#define N_RXT (sizeof(optype_names)/sizeof(optype_names[0]))
+#define N_RXO ARRAY_SIZE (id_names)
+#define N_RXT ARRAY_SIZE (optype_names)
 #define N_MAP 90
 
 static unsigned long long benchmark_start_cycle;
diff --git a/sim/sh/ChangeLog b/sim/sh/ChangeLog
index 9d3cf44132d6..6430e6db2094 100644
--- a/sim/sh/ChangeLog
+++ b/sim/sh/ChangeLog
@@ -1,3 +1,9 @@
+2017-02-13  Mike Frysinger  <vapier@gentoo.org>
+
+	* gencode.c: Include libiberty.h.
+	(conflict_warn): Use ARRAY_SIZE.
+	* interp.c (init_dsp): Likewise.
+
 2016-04-10  Oleg Endo  <olegendo@gcc.gnu.org>
 
 	* interp.c (dmul): Split into dmul_s and dmul_u.  Use explicit integer
diff --git a/sim/sh/gencode.c b/sim/sh/gencode.c
index 2f1a3f5be28d..77a83d637685 100644
--- a/sim/sh/gencode.c
+++ b/sim/sh/gencode.c
@@ -35,6 +35,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include "libiberty.h"
 
 #define MAX_NR_STUFF 42
 
@@ -2595,7 +2596,7 @@ conflict_warn (int val, int i)
   fprintf (stderr, "Warning: opcode table conflict: 0x%04x (idx %d && %d)\n",
 	   val, i, table[val]);
 
-  for (ix = sizeof (tab) / sizeof (tab[0]); ix >= 0; ix--)
+  for (ix = ARRAY_SIZE (tab); ix >= 0; ix--)
     if (tab[ix].index == i || tab[ix].index == j)
       {
 	key = ((tab[ix].code[0] - '0') << 3) + 
@@ -2607,7 +2608,7 @@ conflict_warn (int val, int i)
 	  fprintf (stderr, "  %s -- %s\n", tab[ix].code, tab[ix].name);
       }
 
-  for (ix = sizeof (movsxy_tab) / sizeof (movsxy_tab[0]); ix >= 0; ix--)
+  for (ix = ARRAY_SIZE (movsxy_tab); ix >= 0; ix--)
     if (movsxy_tab[ix].index == i || movsxy_tab[ix].index == j)
       {
 	key = ((movsxy_tab[ix].code[0] - '0') << 3) + 
@@ -2620,7 +2621,7 @@ conflict_warn (int val, int i)
 		   movsxy_tab[ix].code, movsxy_tab[ix].name);
       }
 
-  for (ix = sizeof (ppi_tab) / sizeof (ppi_tab[0]); ix >= 0; ix--)
+  for (ix = ARRAY_SIZE (ppi_tab); ix >= 0; ix--)
     if (ppi_tab[ix].index == i || ppi_tab[ix].index == j)
       {
 	key = ((ppi_tab[ix].code[0] - '0') << 3) + 
diff --git a/sim/sh/interp.c b/sim/sh/interp.c
index 32618ba44902..c77cf3b1d3bf 100644
--- a/sim/sh/interp.c
+++ b/sim/sh/interp.c
@@ -1658,7 +1658,7 @@ init_dsp (struct bfd *abfd)
     {
       int i, tmp;
 
-      for (i = (sizeof sh_dsp_table / sizeof sh_dsp_table[0]) - 1; i >= 0; i--)
+      for (i = ARRAY_SIZE (sh_dsp_table) - 1; i >= 0; i--)
 	{
 	  tmp = sh_jump_table[0xf000 + i];
 	  sh_jump_table[0xf000 + i] = sh_dsp_table[i];
diff --git a/sim/sh64/ChangeLog b/sim/sh64/ChangeLog
index 7627e21caf07..c0d31dd35238 100644
--- a/sim/sh64/ChangeLog
+++ b/sim/sh64/ChangeLog
@@ -1,3 +1,8 @@
+2017-02-13  Mike Frysinger  <vapier@gentoo.org>
+
+	* decode-compact.c (sh64_compact_init_idesc_table): Use ARRAY_SIZE.
+	* decode-media.c (sh64_media_init_idesc_table): Likewise.
+
 2016-01-10  Mike Frysinger  <vapier@gentoo.org>
 
 	* config.in, configure: Regenerate.
diff --git a/sim/sh64/decode-compact.c b/sim/sh64/decode-compact.c
index 3b231666f853..0eeabab75037 100644
--- a/sim/sh64/decode-compact.c
+++ b/sim/sh64/decode-compact.c
@@ -292,7 +292,7 @@ sh64_compact_init_idesc_table (SIM_CPU *cpu)
     init_idesc (cpu, id, t);
 
   /* Now fill in the values for the chosen cpu.  */
-  for (t = sh64_compact_insn_sem, tend = t + sizeof (sh64_compact_insn_sem) / sizeof (*t);
+  for (t = sh64_compact_insn_sem, tend = t + ARRAY_SIZE (sh64_compact_insn_sem);
        t != tend; ++t)
     {
       init_idesc (cpu, & table[t->index], t);
diff --git a/sim/sh64/decode-media.c b/sim/sh64/decode-media.c
index 40aa9836de75..74fb83dbe72d 100644
--- a/sim/sh64/decode-media.c
+++ b/sim/sh64/decode-media.c
@@ -306,7 +306,7 @@ sh64_media_init_idesc_table (SIM_CPU *cpu)
     init_idesc (cpu, id, t);
 
   /* Now fill in the values for the chosen cpu.  */
-  for (t = sh64_media_insn_sem, tend = t + sizeof (sh64_media_insn_sem) / sizeof (*t);
+  for (t = sh64_media_insn_sem, tend = t + ARRAY_SIZE (sh64_media_insn_sem);
        t != tend; ++t)
     {
       init_idesc (cpu, & table[t->index], t);
