bfd/elf32-or1k: fix building with gcc version < 5
PATCH 1/1 bfd/elf32-or1k: fix building with gcc version < 5
Gcc version >= 5 has standard C mode not set to -std=gnu11, so if we use an old compiler(i.e. gcc 4.9) build fails on:
```
elf32-or1k.c:2251:3: error: 'for' loop initial declarations are only allowed in
C99 or C11 mode
for (size_t i = 0; i < insn_count; i++)
^
```So let's declare size_t i at the top of the function instead of inside for loop.
--- bfd/elf32-or1k.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
bfd/elf32-or1k.c +3 -2
@@ -2244,9 +2244,10 @@ or1k_write_plt_entry (bfd *output_bfd, bfd_byte *contents, unsigned insnj, {unsigned nodelay =elf_elfheader (output_bfd)->e_flags &EF_OR1K_NODELAY ;unsigned output_insns[PLT_MAX_INSN_COUNT ]; +size_t i;/* Copy instructions into the output buffer. */ -for (size_t i =0 ; i < insn_count; i++) +for (i =0 ; i < insn_count; i++) output_insns[i] = insns[i];/* Honor the no-delay-slot setting. */
@@ -2277,7 +2278,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 )); }
Signature · 1 line
2.25.1
PATCH 1/1 bfd/elf32-or1k: fix building with gcc version < 5
Quoted 11 lines · Giulio Benetti
Gcc version >= 5 has standard C mode not set to -std=gnu11, so if we use an old compiler(i.e. gcc 4.9) build fails on:
``` elf32-or1k.c:2251:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode for (size_t i = 0; i < insn_count; i++) ^ ```So let's declare
size_t iat the top of the function instead of inside for loop.
This looks ok to me. Can you also include the changelog entry needed for binutils patches?
Something like:
bfd/ChangeLog:
* elf32-or1k.c (or1k_write_plt_entry): Move i declaration to top of function.
Quoted 33 lines
Signed-off-by Giulio Benetti <[email protected]>--- bfd/elf32-or1k.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)bfd/elf32-or1k.c +3
-2@@ -2244,9 +2244,10 @@ or1k_write_plt_entry (bfd *output_bfd, bfd_byte *contents, unsigned insnj, {unsigned nodelay =elf_elfheader (output_bfd)->e_flags &EF_OR1K_NODELAY ;unsigned output_insns[PLT_MAX_INSN_COUNT ]; +size_t i;/* Copy instructions into the output buffer. */ -for (size_t i =0 ; i < insn_count; i++) +for (i =0 ; i < insn_count; i++) output_insns[i] = insns[i];/* Honor the no-delay-slot setting. */ @@ -2277,7 +2278,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 )); }Signature · 1 line
2.25.1
PATCH v2 1/1 bfd/elf32-or1k: fix building with gcc version < 5
Gcc version >= 5 has standard C mode not set to -std=gnu11, so if we use an old compiler(i.e. gcc 4.9) build fails on:
```
elf32-or1k.c:2251:3: error: 'for' loop initial declarations are only allowed in
C99 or C11 mode
for (size_t i = 0; i < insn_count; i++)
^
```So let's declare size_t i at the top of the function instead of inside for loop.
bfd/ChangeLog:
* elf32-or1k.c (or1k_write_plt_entry): Move i declaration to top of function.
--- bfd/elf32-or1k.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
bfd/elf32-or1k.c +3 -2
@@ -2244,9 +2244,10 @@ or1k_write_plt_entry (bfd *output_bfd, bfd_byte *contents, unsigned insnj, {unsigned nodelay =elf_elfheader (output_bfd)->e_flags &EF_OR1K_NODELAY ;unsigned output_insns[PLT_MAX_INSN_COUNT ]; +size_t i;/* Copy instructions into the output buffer. */ -for (size_t i =0 ; i < insn_count; i++) +for (i =0 ; i < insn_count; i++) output_insns[i] = insns[i];/* Honor the no-delay-slot setting. */
@@ -2277,7 +2278,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 )); }
Signature · 1 line
2.25.1
PATCH v2 1/1 bfd/elf32-or1k: fix building with gcc version < 5
Quoted 8 lines · Giulio Benetti
Gcc version >= 5 has standard C mode not set to -std=gnu11, so if we use an old compiler(i.e. gcc 4.9) build fails on:
``` elf32-or1k.c:2251:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode for (size_t i = 0; i < insn_count; i++) ^ ```
Did you find this problem on current mainline binutils? The configure machinery is supposed to supply the appropriate -std=c99 or -std=gnu99 when using older compilers. That happens for me when I build with gcc-4.9. I don't think any patch is needed for mainline.
Signature · 2 lines
Alan Modra Australia Development Lab, IBM
PATCH v2 1/1 bfd/elf32-or1k: fix building with gcc version < 5
Hello Alan, All,
Quoted 10 lines · Alan Modra
Quoted 8 lines · Giulio Benetti
Gcc version >= 5 has standard C mode not set to -std=gnu11, so if we use an old compiler(i.e. gcc 4.9) build fails on:
``` elf32-or1k.c:2251:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode for (size_t i = 0; i < insn_count; i++) ^ ```
Quoted 5 lines
Did you find this problem on current mainline binutils? The configure machinery is supposed to supply the appropriate -std=c99 or -std=gnu99 when using older compilers. That happens for me when I build with gcc-4.9. I don't think any patch is needed for mainline.
On Buildroot they don't pass -std=c99/g99 and this is the result:
https://gitlab.com/bootlin/toolchains-builder/-/jobs/1325646298
This patch seems to follow all the rest code style of binutils since no other part of it fails and this happens only after patch [1] has been upstreamed.
Here [2] you can see all the other toolchains built succesfully and only Openrisc fails after the patch provided by Stafford([1]).
[1]: http://patches-tcwg.linaro.org/patch/53151/
[2]: https://gitlab.com/bootlin/toolchains-builder/-/jobs
Best regards
Signature · 2 lines
Giulio Benetti Benetti Engineering sas
PATCH v2 1/1 bfd/elf32-or1k: fix building with gcc version < 5
Quoted 13 lines · Giulio Benetti
Hello Alan, All,
Quoted 10 lines · Alan Modra
Quoted 8 lines · Giulio Benetti
Gcc version >= 5 has standard C mode not set to -std=gnu11, so if we use an old compiler(i.e. gcc 4.9) build fails on:
``` elf32-or1k.c:2251:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode for (size_t i = 0; i < insn_count; i++) ^ ```
Quoted 8 lines
Quoted 5 lines
Did you find this problem on current mainline binutils? The configure machinery is supposed to supply the appropriate -std=c99 or -std=gnu99 when using older compilers. That happens for me when I build with gcc-4.9. I don't think any patch is needed for mainline.
On Buildroot they don't pass -std=c99/g99 and this is the result:
https://gitlab.com/bootlin/toolchains-builder/-/jobs/1325646298
That appears to be building binutils 2.35.2
Quoted 1 line
This patch seems to follow all the rest code style of binutils
True, we've only just switched over to requiring C99.
Quoted 9 lines
since no
other part of it fails and this happens only after patch [1] has been upstreamed.Here [2] you can see all the other toolchains built succesfully and only Openrisc fails after the patch provided by
Stafford([1]).[1]: http://patches-tcwg.linaro.org/patch/53151/
[2]: https://gitlab.com/bootlin/toolchains-builder/-/jobs
OK, so the real problem is in a backport. It isn't current mainline binutils configure, which is what I was worried about.
BTW, thank you for posting a fix here, even if it isn't strictly necessary for mainline. Please note that I'm not advocating against your patch. If target maintainers want to keep their code compatible with C89 that's fine by me.
Signature · 2 lines
Alan Modra Australia Development Lab, IBM
PATCH v2 1/1 bfd/elf32-or1k: fix building with gcc version < 5
Hello Alan, All,
Quoted 20 lines · Alan Modra
Quoted 19 lines · Giulio Benetti
Hello Alan, All,
Quoted 15 lines · Alan Modra
Quoted 8 lines · Giulio Benetti
Gcc version >= 5 has standard C mode not set to -std=gnu11, so if we use an old compiler(i.e. gcc 4.9) build fails on:
``` elf32-or1k.c:2251:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode for (size_t i = 0; i < insn_count; i++) ^ ```Did you find this problem on current mainline binutils? The configure machinery is supposed to supply the appropriate -std=c99 or -std=gnu99 when using older compilers. That happens for me when I build with gcc-4.9. I don't think any patch is needed for mainline.
Quoted 8 lines
Quoted 2 lines
On Buildroot they don't pass -std=c99/g99 and this is the result:
https://gitlab.com/bootlin/toolchains-builder/-/jobs/1325646298That appears to be building binutils 2.35.2
Quoted 1 line
This patch seems to follow all the rest code style of binutils
True, we've only just switched over to requiring C99.
Ok so...
Quoted 4 lines
Quoted 4 lines
since no
other part of it fails and this happens only after patch [1] has been upstreamed.
Quoted 8 lines
Quoted 5 lines
Here [2] you can see all the other toolchains built succesfully and only Openrisc fails after the patch provided by
Stafford([1]).[1]: http://patches-tcwg.linaro.org/patch/53151/
[2]: https://gitlab.com/bootlin/toolchains-builder/-/jobsOK, so the real problem is in a backport. It isn't current mainline binutils configure, which is what I was worried about.
...it happens on mainline too but it can be solved by adding -std=c99 to CFLAGS.
Quoted 5 lines
BTW, thank you for posting a fix here, even if it isn't strictly necessary for mainline. Please note that I'm not advocating against your patch. If target maintainers want to keep their code compatible with C89 that's fine by me.
I didn't know about this since no other file failed building on C99. What it seems strange to me is that on buildroot binutils seem to be built without -std=c99
Best regards
Signature · 2 lines
Giulio Benetti Benetti Engineering sas
PATCH v2 1/1 bfd/elf32-or1k: fix building with gcc version < 5
Quoted 41 lines · Giulio Benetti
Hello Alan, All,
Quoted 20 lines · Alan Modra
Quoted 19 lines · Giulio Benetti
Hello Alan, All,
Quoted 15 lines · Alan Modra
Quoted 8 lines · Giulio Benetti
Gcc version >= 5 has standard C mode not set to -std=gnu11, so if we use an old compiler(i.e. gcc 4.9) build fails on:
``` elf32-or1k.c:2251:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode for (size_t i = 0; i < insn_count; i++) ^ ```Did you find this problem on current mainline binutils? The configure machinery is supposed to supply the appropriate -std=c99 or -std=gnu99 when using older compilers. That happens for me when I build with gcc-4.9. I don't think any patch is needed for mainline.
Quoted 8 lines
Quoted 2 lines
On Buildroot they don't pass -std=c99/g99 and this is the result:
https://gitlab.com/bootlin/toolchains-builder/-/jobs/1325646298That appears to be building binutils 2.35.2
Quoted 1 line
This patch seems to follow all the rest code style of binutils
True, we've only just switched over to requiring C99.
Ok so...
Quoted 7 lines
Quoted 7 lines
since no
other part of it fails and this happens only after patch [1] has been upstreamed.Here [2] you can see all the other toolchains built succesfully and only Openrisc fails after the patch provided by
Stafford([1]).
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
[1]: http://patches-tcwg.linaro.org/patch/53151/
[2]: https://gitlab.com/bootlin/toolchains-builder/-/jobsOK, so the real problem is in a backport. It isn't current mainline binutils configure, which is what I was worried about.
...it happens on mainline too but it can be solved by adding -std=c99 to CFLAGS.
Do you have an example of it happening on mainline? According to Alan, mainline should not happen as we should be applying -std=c99 automatically. If not we can fix that.
Quoted 8 lines
Quoted 5 lines
BTW, thank you for posting a fix here, even if it isn't strictly necessary for mainline. Please note that I'm not advocating against your patch. If target maintainers want to keep their code compatible with C89 that's fine by me.
I didn't know about this since no other file failed building on C99. What it seems strange to me is that on buildroot binutils seem to be built without -std=c99
As mainline binutils is supposed to require c99 now. I rather not change the code but fix any issues with configure not setting flags.
I looked at ./configure.ac and I confirm that we have setup c99 flags. But I also notice in bfd/configure.ac that we define it again without c99, but that should not matter as CC should already be defined. Either way does the below patch help?
bfd/configure.ac +0 -0
@@ -34,7 +34,7 @@ dnl Default to a non shared library. This may be overridden
by the
dnl configure option --enable-shared.
AC_DISABLE_SHARED
-AC_PROG_CC
+AC_PROG_CC_C99
AC_GNU_SOURCE
AC_USE_SYSTEM_EXTENSIONS
--
-Stafford
PATCH v2 1/1 bfd/elf32-or1k: fix building with gcc version < 5
Hi Staffor, Alan, All,
Quoted 48 lines · Stafford Horne
Quoted 47 lines · Giulio Benetti
Hello Alan, All,
Quoted 20 lines · Alan Modra
Quoted 19 lines · Giulio Benetti
Hello Alan, All,
Quoted 15 lines · Alan Modra
Quoted 8 lines · Giulio Benetti
Gcc version >= 5 has standard C mode not set to -std=gnu11, so if we use an old compiler(i.e. gcc 4.9) build fails on:
``` elf32-or1k.c:2251:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode for (size_t i = 0; i < insn_count; i++) ^ ```Did you find this problem on current mainline binutils? The configure machinery is supposed to supply the appropriate -std=c99 or -std=gnu99 when using older compilers. That happens for me when I build with gcc-4.9. I don't think any patch is needed for mainline.
Quoted 8 lines
Quoted 2 lines
On Buildroot they don't pass -std=c99/g99 and this is the result:
https://gitlab.com/bootlin/toolchains-builder/-/jobs/1325646298That appears to be building binutils 2.35.2
Quoted 1 line
This patch seems to follow all the rest code style of binutils
True, we've only just switched over to requiring C99.
Ok so...
Quoted 12 lines
Quoted 9 lines
since no
other part of it fails and this happens only after patch [1] has been upstreamed.Here [2] you can see all the other toolchains built succesfully and only Openrisc fails after the patch provided by
Stafford([1]).[1]: http://patches-tcwg.linaro.org/patch/53151/
[2]: https://gitlab.com/bootlin/toolchains-builder/-/jobsOK, so the real problem is in a backport. It isn't current mainline binutils configure, which is what I was worried about.
Quoted 6 lines
Quoted 2 lines
...it happens on mainline too but it can be solved by adding -std=c99 to CFLAGS.
Do you have an example of it happening on mainline? According to Alan, mainline should not happen as we should be applying -std=c99 automatically. If not we can fix that.
I was wrong, it's not on mainline, it's on 2.35.2.
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
BTW, thank you for posting a fix here, even if it isn't strictly necessary for mainline. Please note that I'm not advocating against your patch. If target maintainers want to keep their code compatible with C89 that's fine by me.
I didn't know about this since no other file failed building on C99. What it seems strange to me is that on buildroot binutils seem to be built without -std=c99
Quoted 6 lines
As mainline binutils is supposed to require c99 now. I rather not change the code but fix any issues with configure not setting flags.
I looked at ./configure.ac and I confirm that we have setup c99 flags. But I also notice in bfd/configure.ac that we define it again without c99, but that should not matter as CC should already be defined.
I've verified that it inherits -std=c99 from upper configure.ac, so no need for it. Then please ignore this patch and we will use it backported on binutils:
2.32
2.34
2.35.2
2.36.1
in Buildroot. Sorry for the noise :-)
and Best regards
Signature · 2 lines
Giulio Benetti Benetti Engineering sas
Quoted 20 lines
Either way does the below patch help?
bfd/configure.ac +0
-0@@ -34,7 +34,7 @@ dnl Default to a non shared library. This may be overriddenby the
dnl configure option --enable-shared.
AC_DISABLE_SHAREDbfd/configure.ac +1
-3-AC_PROG_CC +AC_PROG_CC_C99 AC_GNU_SOURCE AC_USE_SYSTEM_EXTENSIONS -- -Stafford
PATCH 1/1 bfd/elf32-or1k: fix building with gcc version < 5
In reply to Stafford HorneHi Stafford,
Quoted 16 lines · Stafford Horne
Quoted 11 lines · Giulio Benetti
Gcc version >= 5 has standard C mode not set to -std=gnu11, so if we use an old compiler(i.e. gcc 4.9) build fails on:
``` elf32-or1k.c:2251:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode for (size_t i = 0; i < insn_count; i++) ^ ```So let's declare
size_t iat the top of the function instead of inside for loop.This looks ok to me. Can you also include the changelog entry needed for binutils patches?
Quoted 6 lines
Something like:
bfd/ChangeLog:
*
elf32-or1k.c(or1k_write_plt_entry): Move i declaration to top of function.
Sure, this it the first time I send a patch for binutils. I've just sent the v2.
Best regards
Signature · 2 lines
Giulio Benetti Benetti Engineering sas
Quoted 33 lines
Quoted 33 lines
Signed-off-by Giulio Benetti <[email protected]>--- bfd/elf32-or1k.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)bfd/elf32-or1k.c +3
-2@@ -2244,9 +2244,10 @@ or1k_write_plt_entry (bfd *output_bfd, bfd_byte *contents, unsigned insnj, {unsigned nodelay =elf_elfheader (output_bfd)->e_flags &EF_OR1K_NODELAY ;unsigned output_insns[PLT_MAX_INSN_COUNT ]; +size_t i;/* Copy instructions into the output buffer. */ -for (size_t i =0 ; i < insn_count; i++) +for (i =0 ; i < insn_count; i++) output_insns[i] = insns[i];/* Honor the no-delay-slot setting. */ @@ -2277,7 +2278,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 )); }Signature · 1 line
2.25.1