RISC-V/BFD: Correct a missing initializer error with pre-4.7 GCC

Message ID alpine.DEB.2.00.1802030210580.3553@tp.orcam.me.uk
State New
Headers show
Series
  • RISC-V/BFD: Correct a missing initializer error with pre-4.7 GCC
Related show

Commit Message

Maciej W. Rozycki Feb. 3, 2018, 3:14 p.m.
Correct a commit 9d06997adb88 ("RISC-V: Relax RISCV_PCREL_* to 
RISCV_GPREL_*") regression and remove a `-Wmissing-field-initializers' 
compilation error:

cc1: warnings being treated as errors
.../bfd/elfnn-riscv.c: In function '_bfd_riscv_relax_pc':
.../bfd/elfnn-riscv.c:3117: error: missing initializer
.../bfd/elfnn-riscv.c:3117: error: (near initialization for 'hi_reloc.hi_addend')
make[4]: *** [elf64-riscv.lo] Error 1

which for versions of GCC before 4.7 prevents support for RISC-V targets 
from being built.  See also GCC PR c/36750.

	bfd/
	* elfnn-riscv.c (_bfd_riscv_relax_pc): Use `memset' to 
	initialize `hi_reloc'.
---
Hi,

 This has popped up as a regression in routine cross-target testing for an 
unrelated change and should be obvious.  OK to apply?

  Maciej
---
 bfd/elfnn-riscv.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

binutils-riscv-bfd-relax-pc-hi-reloc-init.diff

Comments

Jim Wilson Feb. 3, 2018, 7:33 p.m. | #1
On Sat, Feb 3, 2018 at 7:14 AM, Maciej W. Rozycki <macro@mips.com> wrote:
>         bfd/

>         * elfnn-riscv.c (_bfd_riscv_relax_pc): Use `memset' to

>         initialize `hi_reloc'.


OK.

Jim
Maciej W. Rozycki Feb. 5, 2018, 2:09 p.m. | #2
On Sat, 3 Feb 2018, Jim Wilson wrote:

> >         bfd/

> >         * elfnn-riscv.c (_bfd_riscv_relax_pc): Use `memset' to

> >         initialize `hi_reloc'.

> 

> OK.


 Applied, thanks for your review.

  Maciej

Patch

Index: binutils/bfd/elfnn-riscv.c
===================================================================
--- binutils.orig/bfd/elfnn-riscv.c	2018-01-10 20:12:45.000000000 +0000
+++ binutils/bfd/elfnn-riscv.c	2018-01-18 08:00:40.342123901 +0000
@@ -3114,7 +3114,8 @@  _bfd_riscv_relax_pc  (bfd *abfd,
 
   /* Chain the _LO relocs to their cooresponding _HI reloc to compute the
    * actual target address.  */
-  riscv_pcgp_hi_reloc hi_reloc = {0};
+  riscv_pcgp_hi_reloc hi_reloc;
+  memset (&hi_reloc, 0, sizeof (hi_reloc));
   switch (ELFNN_R_TYPE (rel->r_info))
     {
     case R_RISCV_PCREL_LO12_I: