Skip to content

Commit

Permalink
libbpf-tools: Fix -Wformat errors for 32bit systems
Browse files Browse the repository at this point in the history
When -Wformat is used and we are building for 32bit systems, we
currently hit build failures since on these systems sizeof(long) == 4.

Here we are fixing this by adopting more portable string format
specifiers (through the PRI*64 string literals) and by using %zd for
ssize_t.

Signed-off-by: Jesus Sanchez-Palencia <[email protected]>
  • Loading branch information
jeez authored and yonghong-song committed Oct 25, 2023
1 parent 3162551 commit 425d2b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions libbpf-tools/fsslower.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ static void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
if (e->size == LLONG_MAX)
printf("LL_MAX,");
else
printf("%ld,", e->size);
printf("%zd,", e->size);
printf("%lld,%lld,%s\n", e->offset, e->delta_us, e->file);
return;
}
Expand All @@ -339,7 +339,7 @@ static void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
if (e->size == LLONG_MAX)
printf("%-7s ", "LL_MAX");
else
printf("%-7ld ", e->size);
printf("%-7zd ", e->size);
printf("%-8lld %7.2f %s\n", e->offset / 1024, (double)e->delta_us / 1000, e->file);
}

Expand Down
17 changes: 11 additions & 6 deletions libbpf-tools/trace_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define _GNU_SOURCE
#endif
#include <ctype.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -552,8 +553,9 @@ static int create_tmp_vdso_image(struct dso *dso)
return -1;

while (true) {
ret = fscanf(f, "%lx-%lx %*s %*x %*x:%*x %*u%[^\n]",
&start_addr, &end_addr, buf);
ret = fscanf(f, "%llx-%llx %*s %*x %*x:%*x %*u%[^\n]",
(long long*)&start_addr, (long long*)&end_addr,
buf);
if (ret == EOF && feof(f))
break;
if (ret != 3)
Expand Down Expand Up @@ -669,10 +671,13 @@ struct syms *syms__load_file(const char *fname)
goto err_out;

while (true) {
ret = fscanf(f, "%lx-%lx %4s %lx %lx:%lx %lu%[^\n]",
&map.start_addr, &map.end_addr, perm,
&map.file_off, &map.dev_major,
&map.dev_minor, &map.inode, buf);
ret = fscanf(f, "%llx-%llx %4s %llx %llx:%llx %llu%[^\n]",
(long long*)&map.start_addr,
(long long*)&map.end_addr, perm,
(long long*)&map.file_off,
(long long*)&map.dev_major,
(long long*)&map.dev_minor,
(long long*)&map.inode, buf);
if (ret == EOF && feof(f))
break;
if (ret != 8) /* perf-<PID>.map */
Expand Down

0 comments on commit 425d2b6

Please sign in to comment.