Skip to contentSkip to conversation

perf: cast some printf() arguments to fix x32 build

PATCH New Vincent Stehlé 1 participant 2 messages Oct 6, 2016 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 perf: cast some printf() arguments to fix x32 build

Fix a few printf() format warnings regarding struct timeval fields on x32 (a.k.a AMD64 ILP32). As those warnings are treated as errors, they break the build.

This fixes this kind of build warning:

bench/sched-pipe.c:160:20: error: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type '__time_t {aka long long int}' [-Werror=format=]

     printf(" %14s: %lu.%03lu [sec]\n\n", "Total time",
                      ^
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Adrian Hunter <[email protected]>
---
 tools/perf/bench/sched-messaging.c | 4 ++--
 tools/perf/bench/sched-pipe.c      | 4 ++--
 tools/perf/builtin-kvm.c           | 2 +-
 tools/perf/builtin-stat.c          | 3 ++-
 4 files changed, 7 insertions(+), 6 deletions(-)
tools/perf/bench/sched-messaging.c +2 -2
index 6a111e77..7ad91c1 100644
@@ -312,11 +312,11 @@ int bench_sched_messaging(int argc, const char **argv,
 		       num_groups, num_groups * 2 * num_fds,
 		       thread_mode ? "threads" : "processes");
 		printf(" %14s: %lu.%03lu [sec]\n", "Total time",
-		       diff.tv_sec,
+		       (unsigned long) diff.tv_sec,
 		       (unsigned long) (diff.tv_usec / USEC_PER_MSEC));
 		break;
 	case BENCH_FORMAT_SIMPLE:
-		printf("%lu.%03lu\n", diff.tv_sec,
+		printf("%lu.%03lu\n", (unsigned long) diff.tv_sec,
 		       (unsigned long) (diff.tv_usec / USEC_PER_MSEC));
 		break;
 	default:
tools/perf/bench/sched-pipe.c +2 -2
index 2243f01..62277fb 100644
@@ -158,7 +158,7 @@ int bench_sched_pipe(int argc, const char **argv, const char *prefix __maybe_unu
 		result_usec += diff.tv_usec;
 
 		printf(" %14s: %lu.%03lu [sec]\n\n", "Total time",
-		       diff.tv_sec,
+		       (unsigned long) diff.tv_sec,
 		       (unsigned long) (diff.tv_usec / USEC_PER_MSEC));
 
 		printf(" %14lf usecs/op\n",
@@ -170,7 +170,7 @@ int bench_sched_pipe(int argc, const char **argv, const char *prefix __maybe_unu
 
 	case BENCH_FORMAT_SIMPLE:
 		printf("%lu.%03lu\n",
-		       diff.tv_sec,
+		       (unsigned long) diff.tv_sec,
 		       (unsigned long) (diff.tv_usec / USEC_PER_MSEC));
 		break;
 
tools/perf/builtin-kvm.c +1 -1
index 08fa88f..9a6489f 100644
@@ -566,7 +566,7 @@ static void show_timeofday(void)
 	gettimeofday(&tv, NULL);
 	if (localtime_r(&tv.tv_sec, &ltime)) {
 		strftime(date, sizeof(date), "%H:%M:%S", &ltime);
-		pr_info("%s.%06ld", date, tv.tv_usec);
+		pr_info("%s.%06ld", date, (long) tv.tv_usec);
 	} else
 		pr_info("00:00:00.000000");
 
tools/perf/builtin-stat.c +2 -1
index 688dea7..ab86bc6 100644
@@ -1393,7 +1393,8 @@ static void print_interval(char *prefix, struct timespec *ts)
 	FILE *output = stat_config.output;
 	static int num_print_interval;
 
-	sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, csv_sep);
+	sprintf(prefix, "%6lu.%09lu%s", (unsigned long) ts->tv_sec,
+		(unsigned long) ts->tv_nsec, csv_sep);
 
 	if (num_print_interval == 0 && !csv_output) {
 		switch (stat_config.aggr_mode) {
Signature · 1 line
2.9.3
#1 lore raw

PATCH 2/2 perf x86: fix compilation of push/pop for x32

The x32 ABI (a.k.a AMD64 ILP32) necessitates to push or pop a 64-bit register even though ILP32 uses 32-bit integers, longs and pointers.

This fixes the following build errors:

arch/x86/tests/regs_load.S:65: Error: operand type mismatch for push' arch/x86/tests/regs_load.S:72: Error: operand type mismatch for pop'

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Adrian Hunter <[email protected]>
---
 tools/perf/arch/x86/tests/regs_load.S | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/perf/arch/x86/tests/regs_load.S +8 -0
index 60875d5..4fa7943 100644
@@ -62,14 +62,22 @@ ENTRY(perf_regs_load)
 ENDPROC(perf_regs_load)
 #else
 ENTRY(perf_regs_load)
+#if defined(__x86_64__) && defined(__ILP32__)
+	pushq %rdi
+#else
 	push %edi
+#endif
 	movl 8(%esp), %edi
 	movl %eax, AX(%edi)
 	movl %ebx, BX(%edi)
 	movl %ecx, CX(%edi)
 	movl %edx, DX(%edi)
 	movl %esi, SI(%edi)
+#if defined(__x86_64__) && defined(__ILP32__)
+	popq %rax
+#else
 	pop %eax
+#endif
 	movl %eax, DI(%edi)
 	movl %ebp, BP(%edi)
 
Signature · 1 line
2.9.3