[bfd,opcodes] Remove C99 constructs

Message ID 20210923203934.GA31077@delia
State New
Headers show
Series
  • [bfd,opcodes] Remove C99 constructs
Related show

Commit Message

Alan Modra via Binutils Sept. 23, 2021, 8:39 p.m.
Hi,

When doing a gdb build with --enable-targets=all and gcc-4.8, we run into
build errors.

Two of those are in bfd and opcodes, related to using for loop initial
declarations.  This is a C99 construct which is not availabe by default with
gcc-4.8.

Fix this by rewriting into regular for loops.

Build on x86_64-linux.

OK for trunk?

Thanks,
- Tom

[bfd, opcodes] Remove C99 constructs

---
 bfd/elf32-or1k.c  | 5 +++--
 opcodes/ppc-dis.c | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

Comments

Alan Modra via Binutils Sept. 24, 2021, 1:12 a.m. | #1
On Thu, Sep 23, 2021 at 10:39:35PM +0200, Tom de Vries via Binutils wrote:
> Hi,

> 

> When doing a gdb build with --enable-targets=all and gcc-4.8, we run into

> build errors.

> 

> Two of those are in bfd and opcodes, related to using for loop initial

> declarations.  This is a C99 construct which is not availabe by default with

> gcc-4.8.


So why is AC_PROG_CC_C99 in the top level makefile not effective for
you?  I can successfully build binutils with gcc-4.8.  For me the
build system automatically adds -std=gnu99.

-- 
Alan Modra
Australia Development Lab, IBM
Alan Modra via Binutils Sept. 25, 2021, 8:55 p.m. | #2
On 9/24/21 3:12 AM, Alan Modra wrote:
> On Thu, Sep 23, 2021 at 10:39:35PM +0200, Tom de Vries via Binutils wrote:

>> Hi,

>>

>> When doing a gdb build with --enable-targets=all and gcc-4.8, we run into

>> build errors.

>>

>> Two of those are in bfd and opcodes, related to using for loop initial

>> declarations.  This is a C99 construct which is not availabe by default with

>> gcc-4.8.

> 

> So why is AC_PROG_CC_C99 in the top level makefile not effective for

> you?  I can successfully build binutils with gcc-4.8.  For me the

> build system automatically adds -std=gnu99.

> 


Because I was doing:
...
$ configure CC=gcc-4.8 CXX=g++-4.8
...
followed by:
...
$ make CC=gcc-4.8 CXX=g++-4.8
...
and the latter overrides the -std=c99 addition by configure.

So, my mistake, thanks for pointing this out.  I've updated my build script.

Thanks,
- Tom

Patch

diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c
index 4f9092539f5..c1690d1aaf7 100644
--- a/bfd/elf32-or1k.c
+++ b/bfd/elf32-or1k.c
@@ -2258,7 +2258,8 @@  or1k_write_plt_entry (bfd *output_bfd, bfd_byte *contents, unsigned insnj,
   unsigned output_insns[PLT_MAX_INSN_COUNT];
 
   /* Copy instructions into the output buffer.  */
-  for (size_t i = 0; i < insn_count; i++)
+  size_t i;
+  for (i = 0; i < insn_count; i++)
     output_insns[i] = insns[i];
 
   /* Honor the no-delay-slot setting.  */
@@ -2289,7 +2290,7 @@  or1k_write_plt_entry (bfd *output_bfd, bfd_byte *contents, unsigned insnj,
     }
 
   /* Write out the output buffer.  */
-  for (size_t i = 0; i < (insn_count+1); i++)
+  for (i = 0; i < (insn_count+1); i++)
     bfd_put_32 (output_bfd, output_insns[i], contents + (i*4));
 }
 
diff --git a/opcodes/ppc-dis.c b/opcodes/ppc-dis.c
index f25909d1c01..aa455b407ac 100644
--- a/opcodes/ppc-dis.c
+++ b/opcodes/ppc-dis.c
@@ -1056,7 +1056,8 @@  print_insn_powerpc (bfd_vma memaddr,
 	      && ((insn & ((-1ULL << 50) | (0x3fULL << 26)))
 		  == ((1ULL << 58) | (1ULL << 52) | (57ULL << 26)) /* pld */))
 	    {
-	      for (int i = 0; i < 2; i++)
+	      int i;
+	      for (i = 0; i < 2; i++)
 		if (print_got_plt (private_data (info)->special + i, d34, info))
 		  break;
 	    }