Skip to contentSkip to conversation

btf_encoder: Print the u32 overflow check offset as a u64

PATCH In review Arnaldo Carvalho de Melo 2 participants 2 messages Dec 1 BPF

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btf_encoder: Print the u32 overflow check offset as a u64

From: Arnaldo Carvalho de Melo <[email protected]>

The offset ignored in btf_encoder__encode_cu_variables() is a uint64_t, printed with %zu. That matches on 64-bit, where size_t is also 64-bit, but on 32-bit x86 uint64_t is unsigned long long and gcc rejects it:

btf_encoder.c:2893:88: error: format '%zu' expects argument of type 'size_t', but argument 4 has type 'uint64_t' [-Werror=format=]

which breaks a Debug (-Werror) build on i386 since that check was added. Use PRIu64, inttypes.h is already included.

Fixes 5b5238c0aaff1dfd ("btf_encoder: Explicitly check addr/size for u32 overflow")
Cc Alan Maguire <[email protected]>
Cc Stephen Brennan <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 btf_encoder.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
btf_encoder.c +1 -1
index 85376281da076cb2..ca102eb194b80f8d 100644
@@ -2890,7 +2890,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder)
 		}
 		if (addr > UINT32_MAX) {
 			if (encoder->verbose)
-				fprintf(stderr, "Ignoring variable '%s' - its offset %zu doesn't fit in a u32\n",
+				fprintf(stderr, "Ignoring variable '%s' - its offset %" PRIu64 " doesn't fit in a u32\n",
 					name, addr);
 			continue;
 		}
Signature · 1 line
2.56.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

The offset ignored in btf_encoder__encode_cu_variables() is a uint64_t, printed with %zu. That matches on 64-bit, where size_t is also 64-bit, but on 32-bit x86 uint64_t is unsigned long long and gcc rejects it:

btf_encoder.c:2893:88: error: format '%zu' expects argument of type 'size_t', but argument 4 has type 'uint64_t' [-Werror=format=]

Quoted 8 lines

which breaks a Debug (-Werror) build on i386 since that check was added. Use PRIu64, inttypes.h is already included.

Fixes 5b5238c0aaff1dfd ("btf_encoder: Explicitly check addr/size for u32 overflow")
Cc Alan Maguire <[email protected]>
Cc Stephen Brennan <[email protected]>
Cc Jiri Olsa <[email protected]>

There's some irony that this print happens in the 32-bit overflow case, so I should have thought about what happens when size_t is 32-bit. Thanks for fixing this.

Quoted 17 lines
---
 btf_encoder.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
btf_encoder.c +1 -1
index 85376281da076cb2..ca102eb194b80f8d 100644
@@ -2890,7 +2890,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder)
 		}
 		if (addr > UINT32_MAX) {
 			if (encoder->verbose)
-				fprintf(stderr, "Ignoring variable '%s' - its offset %zu doesn't fit in a u32\n",
+				fprintf(stderr, "Ignoring variable '%s' - its offset %" PRIu64 " doesn't fit in a u32\n",
 					name, addr);
 			continue;
 		}