1From ef4ba1da823e8366ea4f126f50885a44ebf4dcf0 Mon Sep 17 00:00:00 2001
2From: Giulio Benetti <giulio.benetti@benettiengineering.com>
3Date: Wed, 9 Jun 2021 17:28:27 +0200
4Subject: [PATCH] bfd/elf32-or1k: fix building with gcc version < 5
5
6Gcc version >= 5 has standard C mode not set to -std=gnu11, so if we use
7an old compiler(i.e. gcc 4.9) build fails on:
8```
9elf32-or1k.c:2251:3: error: 'for' loop initial declarations are only allowed in
10C99 or C11 mode
11    for (size_t i = 0; i < insn_count; i++)
12    ^
13```
14
15So let's declare `size_t i` at the top of the function instead of inside
16for loop.
17
18Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
19---
20 bfd/elf32-or1k.c | 5 +++--
21 1 file changed, 3 insertions(+), 2 deletions(-)
22
23diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c
24index 4ae7f324d33..32063ab0289 100644
25--- a/bfd/elf32-or1k.c
26+++ b/bfd/elf32-or1k.c
27@@ -2244,9 +2244,10 @@ or1k_write_plt_entry (bfd *output_bfd, bfd_byte *contents, unsigned insnj,
28 {
29   unsigned nodelay = elf_elfheader (output_bfd)->e_flags & EF_OR1K_NODELAY;
30   unsigned output_insns[PLT_MAX_INSN_COUNT];
31+  size_t i;
32
33   /* Copy instructions into the output buffer.  */
34-  for (size_t i = 0; i < insn_count; i++)
35+  for (i = 0; i < insn_count; i++)
36     output_insns[i] = insns[i];
37
38   /* Honor the no-delay-slot setting.  */
39@@ -2277,7 +2278,7 @@ or1k_write_plt_entry (bfd *output_bfd, bfd_byte *contents, unsigned insnj,
40     }
41
42   /* Write out the output buffer.  */
43-  for (size_t i = 0; i < (insn_count+1); i++)
44+  for (i = 0; i < (insn_count+1); i++)
45     bfd_put_32 (output_bfd, output_insns[i], contents + (i*4));
46 }
47
48--
492.31.1
50
51