[PATCH] microblaze: fix build error on 32-bit hosts

Michael Eager eager@eagercon.com
Sat Oct 7 22:53:32 GMT 2023


On 10/7/23 15:01, Mark Wielaard wrote:
> commit 6bbf24955 opcodes: microblaze: Add new bit-field instructions
> introduced a build error on 32-bit hosts:
> 
> elf32-microblaze.c: In function ‘microblaze_elf_relax_section’:
> elf32-microblaze.c:1989:53: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 5 has type ‘bfd_vma’ {aka ‘unsigned int’} [-Werror=format=]
>   1989 |       fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend);
>        |                                                   ~~^                    ~~~~~~~~~~~~~~
>        |                                                     |                        |
>        |                                                     long unsigned int        bfd_vma {aka unsigned int}
>        |                                                   %x
> elf32-microblaze.c:2074:51: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 5 has type ‘bfd_vma’ {aka ‘unsigned int’} [-Werror=format=]
>   2074 |    fprintf(stderr, "%d: CORRUPT relax reloc! %x %lx\n", __LINE__, val, irelscan->r_addend);
>        |                                                 ~~^                    ~~~~~~~~~~~~~~~~~~
>        |                                                   |                            |
>        |                                                   long unsigned int            bfd_vma {aka unsigned int}
>        |                                                 %x
> 
> Fix by explicitly casting the r_addend to long.
> ---
>   bfd/elf32-microblaze.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
> index a8ced43c08a..2c584f91a4e 100644
> --- a/bfd/elf32-microblaze.c
> +++ b/bfd/elf32-microblaze.c
> @@ -1986,7 +1986,7 @@ microblaze_elf_relax_section (bfd *abfd,
>   		/* Validate the in-band val.  */
>   		val = bfd_get_32 (abfd, contents + irel->r_offset);
>   		if (val != irel->r_addend && ELF32_R_TYPE (irel->r_info) == R_MICROBLAZE_32_NONE) {
> -		    fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend);
> +		    fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, (long) irel->r_addend);
>   		}
>   		irel->r_addend -= (efix - sfix);
>   		/* Should use HOWTO.  */
> @@ -2071,7 +2071,7 @@ microblaze_elf_relax_section (bfd *abfd,
>   
>   		  val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
>   		  if (val != irelscan->r_addend) {
> -			fprintf(stderr, "%d: CORRUPT relax reloc! %x %lx\n", __LINE__, val, irelscan->r_addend);
> +			fprintf(stderr, "%d: CORRUPT relax reloc! %x %lx\n", __LINE__, val, (long) irelscan->r_addend);
>   		  }
>   
>   		  irelscan->r_addend -= calc_fixup (irelscan->r_addend, 0, sec);

I didn't see any build errors, building with GCC-12.3.1.

Which version of GCC are you using?

(Patch was reverted.)

-- 
Michael Eager


More information about the Binutils mailing list