[PATCH] tools: mips-relocs: replace format string introducers
Justin Swartz
justin.swartz at risingedge.co.za
Tue Jul 22 15:57:17 CEST 2025
The statement that prints the ELF object type value assumes that "%lx"
(long unsigned int, hexadecimal) is suitable for printing a uint64_t
typed value. While this may seem to work for some machines, ie. amd64,
it isn't ideal on a 32-bit system, such as x86 where uint64_t is likely
to be equivalent to a long long unsigned int, as indicated by:
../tools/mips-relocs.c:275:34:
warning: format '%lx' expects argument of type 'long unsigned int',
but argument 2 has type 'uint64_t'
{aka 'long long unsigned int'} [-Wformat=]
275 | printf("type 0x%lx\n", ehdr_field(e_type));
| ~~^
| |
| long unsigned int
| %llx
As the ehdr_field function-like macro expands to a uint64_t value,
it is better to use the PRIx64 macro in place of "%lx" to ensure that
the correct format string introducer is specified for the actual type
hiding behind uint64_t.
A similar issue is also present in the report of .rel section overflow,
where "%lx" is used to print a few size_t typed values, and would be
better served by "%zx" instead.
Signed-off-by: Justin Swartz <justin.swartz at risingedge.co.za>
Fixes: 963014641117 ("MIPS: make size of relocation table fixed but configurable")
Fixes: 703ec9ddf965 ("MIPS: Stop building position independent code")
Cc: Paul Burton <paulburton at kernel.org>
Cc: Daniel Schwierzeck <daniel.schwierzeck at gmail.com>
Cc: Masahiro Yamada <masahiroy at kernel.org>
---
tools/mips-relocs.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/tools/mips-relocs.c b/tools/mips-relocs.c
index 5db610f5c77..e9234a74f51 100644
--- a/tools/mips-relocs.c
+++ b/tools/mips-relocs.c
@@ -9,6 +9,7 @@
#include <elf.h>
#include <errno.h>
#include <fcntl.h>
+#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
@@ -272,7 +273,7 @@ int main(int argc, char *argv[])
if (ehdr_field(e_type) != ET_EXEC) {
fprintf(stderr, "Input ELF is not an executable\n");
- printf("type 0x%lx\n", ehdr_field(e_type));
+ printf("type 0x%" PRIx64 "\n", ehdr_field(e_type));
err = -EINVAL;
goto out_free_relocs;
}
@@ -394,9 +395,9 @@ int main(int argc, char *argv[])
rel_size = shdr_field(i_rel_shdr, sh_size);
rel_actual_size = buf - buf_start;
if (rel_actual_size > rel_size) {
- fprintf(stderr, "Relocations overflow available space of 0x%lx (required 0x%lx)!\n",
+ fprintf(stderr, "Relocations overflow available space of 0x%zx (required 0x%zx)!\n",
rel_size, rel_actual_size);
- fprintf(stderr, "Please adjust CONFIG_MIPS_RELOCATION_TABLE_SIZE to at least 0x%lx\n",
+ fprintf(stderr, "Please adjust CONFIG_MIPS_RELOCATION_TABLE_SIZE to at least 0x%zx\n",
(rel_actual_size + 0x100) & ~0xFF);
err = -ENOMEM;
goto out_free_relocs;
--
More information about the U-Boot
mailing list