package/elf2flt: backport upstream patch to remove use of BFD_VMA_FMT

This commit backports upstream commit
a36df7407d
to fix a build issue with binutils 2.40 or later:

elf2flt.c:223:31: error: expected ‘)’ before ‘BFD_VMA_FMT’

We prefer a backport over updating to a newer elf2flt version for now
as there has been multiple other changes in elf2flt, and elf2flt is
very fragile. Therefore for now we prefer to be conservative.

Fixes:

  http://autobuild.buildroot.net/results/938a59b5e52d712786590e80328bb45b1c5fc519/

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Tested-by: Waldemar Brodkorb <wbx@openadk.org>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
Thomas Petazzoni 2023-08-06 12:25:52 +02:00
parent f3b22e3642
commit d79f9c9f41

View File

@ -0,0 +1,169 @@
From 9ec7dd9dead2f3c4c73c3ab2166a1f81bfb41825 Mon Sep 17 00:00:00 2001
From: Greg Ungerer <gerg@kernel.org>
Date: Thu, 13 Apr 2023 22:58:20 +1000
Subject: [PATCH] elf2flt: remove use of BFD_VMA_FMT
In binutils-2.40 the BFD_VMA_FMT definition used for printf style
formatting specifiers has been removed. For reference this was done in
commit b82817674f46 ("Don't use BFD_VMA_FMT in binutils") in the
binutils git development tree.
BFD_VMA_FMT is used in a number of places in the elf2flt code to output
bfd offsets, values and the like. So it is broken when using the bfd
code from binutils-2.40 and newer.
According to the binutils change PRIx64 (and friends) is used to replace
it, with appropriate casts to keep it clean for 32 and 64 bit platforms.
Change the elf2flt.c use of it in the same way to fix.
This does not change the output in any way in normal use. This fix can
be used on all versions of binutils (older and newer), there is no
need to only do this on 2.40 and newer.
Signed-off-by: Greg Ungerer <gerg@kernel.org>
Upstream: https://github.com/uclinux-dev/elf2flt/commit/a36df7407d9e3f93ca6449841ff0821b0d980438
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
elf2flt.c | 58 ++++++++++++++++++++++++++++---------------------------
1 file changed, 30 insertions(+), 28 deletions(-)
diff --git a/elf2flt.c b/elf2flt.c
index 0fcb747..6685bff 100644
--- a/elf2flt.c
+++ b/elf2flt.c
@@ -220,8 +220,8 @@ dump_symbols(asymbol **symbol_table, long number_of_symbols)
long i;
printf("SYMBOL TABLE:\n");
for (i=0; i<number_of_symbols; i++) {
- printf(" NAME=%s VALUE=0x%"BFD_VMA_FMT"x\n",
- symbol_table[i]->name, symbol_table[i]->value);
+ printf(" NAME=%s VALUE=0x%"PRIx64"\n",
+ symbol_table[i]->name, (uint64_t) symbol_table[i]->value);
}
printf("\n");
return(0);
@@ -466,8 +466,8 @@ output_relocs (
if (r == NULL)
continue;
if (verbose)
- printf(" RELOCS: %s [%p]: flags=0x%x vma=0x%"BFD_VMA_FMT"x\n",
- r->name, r, r->flags, elf2flt_bfd_section_vma(r));
+ printf(" RELOCS: %s [%p]: flags=0x%x vma=0x%"PRIx64"\n",
+ r->name, r, r->flags, (uint64_t) elf2flt_bfd_section_vma(r));
if ((r->flags & SEC_RELOC) == 0)
continue;
relsize = bfd_get_reloc_upper_bound(rel_bfd, r);
@@ -952,12 +952,13 @@ output_relocs (
if (verbose)
fprintf(stderr,
"%s vma=0x%x, "
- "value=0x%"BFD_VMA_FMT"x, "
- "address=0x%"BFD_VMA_FMT"x "
+ "value=0x%"PRIx64", "
+ "address=0x%"PRIx64" "
"sym_addr=0x%x rs=0x%x, opcode=0x%x\n",
"ABS32",
- sym_vma, (*(q->sym_ptr_ptr))->value,
- q->address, sym_addr,
+ sym_vma,
+ (uint64_t) (*(q->sym_ptr_ptr))->value,
+ (uint64_t) q->address, sym_addr,
(*p)->howto->rightshift,
*(uint32_t *)r_mem);
sym_vma = elf2flt_bfd_section_vma(sym_section);
@@ -971,12 +972,13 @@ output_relocs (
if (verbose)
fprintf(stderr,
"%s vma=0x%x, "
- "value=0x%"BFD_VMA_FMT"x, "
- "address=0x%"BFD_VMA_FMT"x "
+ "value=0x%"PRIx64", "
+ "address=0x%"PRIx64" "
"sym_addr=0x%x rs=0x%x, opcode=0x%x\n",
"PLT32",
- sym_vma, (*(q->sym_ptr_ptr))->value,
- q->address, sym_addr,
+ sym_vma,
+ (uint64_t) (*(q->sym_ptr_ptr))->value,
+ (uint64_t) q->address, sym_addr,
(*p)->howto->rightshift,
*(uint32_t *)r_mem);
case R_ARM_PC24:
@@ -994,8 +996,8 @@ output_relocs (
case R_V850_ZDA_16_16_OFFSET:
case R_V850_ZDA_16_16_SPLIT_OFFSET:
/* Can't support zero-relocations. */
- printf ("ERROR: %s+0x%"BFD_VMA_FMT"x: zero relocations not supported\n",
- sym_name, q->addend);
+ printf ("ERROR: %s+0x%"PRIx64": zero relocations not supported\n",
+ sym_name, (uint64_t) q->addend);
continue;
#endif /* TARGET_v850 */
@@ -1194,12 +1196,12 @@ output_relocs (
temp |= (exist_val & 0x3f);
*(unsigned long *)r_mem = htoniosl(temp);
if (verbose)
- printf("omit: offset=0x%"BFD_VMA_FMT"x symbol=%s%s "
+ printf("omit: offset=0x%"PRIx64" symbol=%s%s "
"section=%s size=%d "
- "fixup=0x%x (reloc=0x%"BFD_VMA_FMT"x) GPREL\n",
- q->address, sym_name, addstr,
+ "fixup=0x%x (reloc=0x%"PRIx64") GPREL\n",
+ (uint64_t) q->address, sym_name, addstr,
section_name, sym_reloc_size,
- sym_addr, section_vma + q->address);
+ sym_addr, (uint64_t) section_vma + q->address);
continue;
}
case R_NIOS2_PCREL16:
@@ -1214,12 +1216,12 @@ output_relocs (
exist_val |= ((sym_addr & 0xFFFF) << 6);
*(unsigned long *)r_mem = htoniosl(exist_val);
if (verbose)
- printf("omit: offset=0x%"BFD_VMA_FMT"x symbol=%s%s "
+ printf("omit: offset=0x%"PRIx64" symbol=%s%s "
"section=%s size=%d "
- "fixup=0x%x (reloc=0x%"BFD_VMA_FMT"x) PCREL\n",
- q->address, sym_name, addstr,
+ "fixup=0x%x (reloc=0x%"PRIx64") PCREL\n",
+ (uint64_t) q->address, sym_name, addstr,
section_name, sym_reloc_size,
- sym_addr, section_vma + q->address);
+ sym_addr, (uint64_t) section_vma + q->address);
continue;
}
@@ -1231,9 +1233,9 @@ output_relocs (
&& (p[-1]->sym_ptr_ptr == p[0]->sym_ptr_ptr)
&& (p[-1]->addend == p[0]->addend)) {
if (verbose)
- printf("omit: offset=0x%"BFD_VMA_FMT"x symbol=%s%s "
+ printf("omit: offset=0x%"PRIx64" symbol=%s%s "
"section=%s size=%d LO16\n",
- q->address, sym_name, addstr,
+ (uint64_t) q->address, sym_name, addstr,
section_name, sym_reloc_size);
continue;
}
@@ -1646,13 +1648,13 @@ DIS29_RELOCATION:
*/
if (relocation_needed) {
if (verbose)
- printf(" RELOC[%d]: offset=0x%"BFD_VMA_FMT"x symbol=%s%s "
+ printf(" RELOC[%d]: offset=0x%"PRIx64" symbol=%s%s "
"section=%s size=%d "
- "fixup=0x%x (reloc=0x%"BFD_VMA_FMT"x)\n",
+ "fixup=0x%x (reloc=0x%"PRIx64")\n",
flat_reloc_count,
- q->address, sym_name, addstr,
+ (uint64_t) q->address, sym_name, addstr,
section_name, sym_reloc_size,
- sym_addr, section_vma + q->address);
+ sym_addr, (uint64_t) section_vma + q->address);
#ifndef TARGET_bfin
flat_relocs = realloc(flat_relocs,
--
2.41.0