Skip to contentSkip to conversation

perf tools: Fixes for some compile errors.

PATCH Superseded Feng Tang 4 participants 11 messages Aug 27, 2012 – Dec 18, 2012 perf events

lore
Share & tools
lore

Feng Tang

author
#0 lore raw

cover perf tools: Fixes for some compile errors.

Hi Arnaldo and all,

I met 3 compiling problems on my x86_32 machine, and these are the fixes, patch 1/3 only applies for perf/core branch of your git, while patch 2 applies to Linus' tree also. please review.

Thanks,
Feng

---
Feng Tang (3):
perf tools: Fix a compiling error in trace-event-perl.c for 32 bits
machine
Perf tools: Fix a compiling error in util/map.c
perf tools: Fix a misuse of for_each_set_bit() in session.c

 tools/perf/util/map.c                              |    5 ++---
 .../perf/util/scripting-engines/trace-event-perl.c |    2 +-
 tools/perf/util/session.c                          |    9 ++++-----
 3 files changed, 7 insertions(+), 9 deletions(-)
author
#1 lore raw

PATCH 1/3 perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine

On my x86_32 mahcine, there is a compile error:

CC util/scripting-engines/trace-event-perl.o
cc1: warnings being treated as errors
util/scripting-engines/trace-event-perl.c: In function ‘perl_process_tracepoint’:
util/scripting-engines/trace-event-perl.c:285: error: format ‘%d’ expects type ‘int’, but argument 2 has type ‘__u64’
make: *** [util/scripting-engines/trace-event-perl.o] Error 1

Fix it by using the "%lld" for __u64.

---
 .../perf/util/scripting-engines/trace-event-perl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/scripting-engines/trace-event-perl.c +1 -1
index d280010..1cde6aa 100644
@@ -282,7 +282,7 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused,
 
 	event = find_cache_event(evsel);
 	if (!event)
-		die("ug! no event found for type %d", evsel->attr.config);
+		die("ug! no event found for type %lld", evsel->attr.config);
 
 	pid = raw_field_value(event, "common_pid", data);
 
Signature · 1 line
1.7.1
#2 lore raw

Re: [PATCH 1/3] perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine

Em Mon, Aug 27, 2012 at 03:38:25PM +0800, Feng Tang escreveu:

Quoted 20 lines

On my x86_32 mahcine, there is a compile error:

CC util/scripting-engines/trace-event-perl.o
cc1: warnings being treated as errors
util/scripting-engines/trace-event-perl.c: In function ‘perl_process_tracepoint’:
util/scripting-engines/trace-event-perl.c:285: error: format ‘%d’ expects type ‘int’, but argument 2 has type ‘__u64’
make: *** [util/scripting-engines/trace-event-perl.o] Error 1

Fix it by using the "%lld" for __u64.

---
 .../perf/util/scripting-engines/trace-event-perl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/scripting-engines/trace-event-perl.c +0 -0
index d280010..1cde6aa 100644

tools/perf/util/scripting-engines/trace-event-perl.c static void perl_process_tracepoint(union perf_event *perf_event __unused, · line 285

Quoted 5 lines
tools/perf/util/scripting-engines/trace-event-perl.c +1 -1
@@ -282,7 +282,7 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused,
 
 	event = find_cache_event(evsel);
 	if (!event)
-		die("ug! no event found for type %d", evsel->attr.config);
+		die("ug! no event found for type %lld", evsel->attr.config);

Please use PRIu64 instead, like in:

grep PRIu64 tools/perf/*/*.c

Quoted 4 lines
tools/perf/util/scripting-engines/trace-event-perl.c +0 -0
 	pid = raw_field_value(event, "common_pid", data);
 
Signature · 1 line
1.7.1
author
#3 lore raw

PATCH v2 1/3 perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine

Quoted 1 line

From 8e2fe258906fc83869be10a1b4a40ef9acc4a2a6 Mon Sep 17 00:00:00 2001

From: Feng Tang <[email protected]>
Date: Mon, 27 Aug 2012 14:01:33 +0800
Subject: [PATCH 1/3] perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine

On my x86_32 mahcine, there is a compile error:

CC util/scripting-engines/trace-event-perl.o
cc1: warnings being treated as errors
util/scripting-engines/trace-event-perl.c: In function ‘perl_process_tracepoint’:
util/scripting-engines/trace-event-perl.c:285: error: format ‘%d’ expects type ‘int’, but argument 2 has type ‘__u64’
make: *** [util/scripting-engines/trace-event-perl.o] Error 1

Fix it by using the "%PRIu64" for __u64.

v2: use PRIu64 as suggested by Arnaldo.

---
 .../perf/util/scripting-engines/trace-event-perl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/scripting-engines/trace-event-perl.c +1 -1
index d280010..09db03f 100644
@@ -282,7 +282,7 @@ static void perl_process_tracepoint(union perf_event *perf_event __unused,
 
 	event = find_cache_event(evsel);
 	if (!event)
-		die("ug! no event found for type %d", evsel->attr.config);
+		die("ug! no event found for type %" PRIu64, evsel->attr.config);
 
 	pid = raw_field_value(event, "common_pid", data);
 
Signature · 1 line
1.7.1
#4 lore raw

[tip:perf/core] perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine

Commit-ID:  b1ab1bd1921536c2a97adb888effeff4370a3246
Gitweb:     http://git.kernel.org/tip/b1ab1bd1921536c2a97adb888effeff4370a3246
Author:     Feng Tang <[email protected]>
AuthorDate: Thu, 20 Sep 2012 08:30:21 -0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 20 Sep 2012 08:30:21 -0300

perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine

On my x86_32 mahcine, there is a compile error:

CC util/scripting-engines/trace-event-perl.o
cc1: warnings being treated as errors util/scripting-engines/trace-event-perl.c: In function perl_process_tracepoint:
util/scripting-engines/trace-event-perl.c:285: error: format expects type 'int', but argument 2 has type '__u64'
make: *** [util/scripting-engines/trace-event-perl.o] Error 1

Fix it by using the "%PRIu64" for __u64.

v2: use PRIu64 as suggested by Arnaldo.

---
 .../perf/util/scripting-engines/trace-event-perl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/perf/util/scripting-engines/trace-event-perl.c +1 -1
index ffde3e4..f80605e 100644
@@ -282,7 +282,7 @@ static void perl_process_tracepoint(union perf_event *perf_event __maybe_unused,
 
 	event = find_cache_event(evsel);
 	if (!event)
-		die("ug! no event found for type %d", evsel->attr.config);
+		die("ug! no event found for type %" PRIu64, evsel->attr.config);
 
 	pid = raw_field_value(event, "common_pid", data);
 
author
#5 lore raw

PATCH 2/3 Perf tools: Fix a compiling error in util/map.c

In reply to Feng Tang

This patch fix a compile warning taken as error:

CC util/map.o
cc1: warnings being treated as errors
util/map.c: In function ‘map__fprintf_dsoname’:
util/map.c:240: error: ‘dsoname’ may be used uninitialized in this function
make: *** [util/map.o] Error 1

---
 tools/perf/util/map.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
tools/perf/util/map.c +2 -3
index 7d37159..5f90dda 100644
@@ -237,15 +237,14 @@ size_t map__fprintf(struct map *self, FILE *fp)
 
 size_t map__fprintf_dsoname(struct map *map, FILE *fp)
 {
-	const char *dsoname;
+	const char *dsoname = "[unknown]";
 
 	if (map && map->dso && (map->dso->name || map->dso->long_name)) {
 		if (symbol_conf.show_kernel_path && map->dso->long_name)
 			dsoname = map->dso->long_name;
 		else if (map->dso->name)
 			dsoname = map->dso->name;
-	} else
-		dsoname = "[unknown]";
+	}
 
 	return fprintf(fp, "%s", dsoname);
 }
Signature · 1 line
1.7.1
#6 lore raw

[tip:perf/core] perf tools: Fix a compiling error in util/map.c

Commit-ID:  8f28f19a87cb48d13570ba774a3e85776eb36bb4
Gitweb:     http://git.kernel.org/tip/8f28f19a87cb48d13570ba774a3e85776eb36bb4
Author:     Feng Tang <[email protected]>
AuthorDate: Mon, 27 Aug 2012 15:38:26 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 20 Sep 2012 08:36:34 -0300

perf tools: Fix a compiling error in util/map.c

This patch fix a compile warning taken as error:

CC util/map.o
cc1: warnings being treated as errors
util/map.c: In function ‘map__fprintf_dsoname’:
util/map.c:240: error: ‘dsoname’ may be used uninitialized in this function
make: *** [util/map.o] Error 1

---
 tools/perf/util/map.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
tools/perf/util/map.c +2 -3
index b442ee4..ead5316 100644
@@ -243,15 +243,14 @@ size_t map__fprintf(struct map *self, FILE *fp)
 
 size_t map__fprintf_dsoname(struct map *map, FILE *fp)
 {
-	const char *dsoname;
+	const char *dsoname = "[unknown]";
 
 	if (map && map->dso && (map->dso->name || map->dso->long_name)) {
 		if (symbol_conf.show_kernel_path && map->dso->long_name)
 			dsoname = map->dso->long_name;
 		else if (map->dso->name)
 			dsoname = map->dso->name;
-	} else
-		dsoname = "[unknown]";
+	}
 
 	return fprintf(fp, "%s", dsoname);
 }
author
#7 lore raw

PATCH 3/3 perf tools: Fix a misuse of for_each_set_bit() in session.c

In reply to Feng Tang

In regs_dump__printf() it use for_each_set_bit() for bit ops by casting a (u64 *) to a (unsigned long *), this works for 64 bits machine, but will fail on 32 bits ones.

Fix it by using the raw bit comparing method.

---
 tools/perf/util/session.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
tools/perf/util/session.c +4 -5
index f7bb7ae..afcea6c 100644
@@ -904,11 +904,10 @@ static void regs_dump__printf(u64 mask, u64 *regs)
 {
 	unsigned rid, i = 0;
 
-	for_each_set_bit(rid, (unsigned long *) &mask, sizeof(mask) * 8) {
-		u64 val = regs[i++];
-
-		printf(".... %-5s 0x%" PRIx64 "\n",
-		       perf_reg_name(rid), val);
+	for (rid = 0; rid < 64; rid++) {
+		if (mask & (1 << rid))
+			printf(".... %-5s 0x%" PRIx64 "\n",
+				perf_reg_name(rid), regs[i++]);
 	}
 }
 
Signature · 1 line
1.7.1
maintainer
#8 lore raw

Re: [PATCH 3/3] perf tools: Fix a misuse of for_each_set_bit() in session.c

Hi,

Quoted 5 lines · Feng Tang

In regs_dump__printf() it use for_each_set_bit() for bit ops by casting a (u64 *) to a (unsigned long *), this works for 64 bits machine, but will fail on 32 bits ones.

Fix it by using the raw bit comparing method.

Did it really cause a build failure or a program error? If not, it looks better to keep using for_each_set_bit() interface. How about casting the @mask to (void *) ?

Thanks,
Namhyung

Quoted 25 lines
---
 tools/perf/util/session.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
tools/perf/util/session.c +4 -5
index f7bb7ae..afcea6c 100644
@@ -904,11 +904,10 @@ static void regs_dump__printf(u64 mask, u64 *regs)
 {
 	unsigned rid, i = 0;
 
-	for_each_set_bit(rid, (unsigned long *) &mask, sizeof(mask) * 8) {
-		u64 val = regs[i++];
-
-		printf(".... %-5s 0x%" PRIx64 "\n",
-		       perf_reg_name(rid), val);
+	for (rid = 0; rid < 64; rid++) {
+		if (mask & (1 << rid))
+			printf(".... %-5s 0x%" PRIx64 "\n",
+				perf_reg_name(rid), regs[i++]);
 	}
 }
author
#9 lore raw

Re: [PATCH 3/3] perf tools: Fix a misuse of for_each_set_bit() in session.c

Hi,

Quoted 7 lines · On Mon, 27 Aug 2012 16:59:07 +0900 Namhyung Kim <[email protected]> wrote:

Hi,

Quoted 4 lines · Feng Tang

In regs_dump__printf() it use for_each_set_bit() for bit ops by casting a (u64 *) to a (unsigned long *), this works for 64 bits machine, but will fail on 32 bits ones.

Quoted 5 lines
Quoted 1 line

Fix it by using the raw bit comparing method.

Did it really cause a build failure or a program error? If not, it looks better to keep using for_each_set_bit() interface. How about casting the @mask to (void *) ?

It's a compile error:

cc1: warnings being treated as errors
util/session.c: In function ‘perf_session_deliver_event’:
util/include/linux/bitops.h:104: error: dereferencing pointer ‘p’ does break strict-aliasing rules util/include/linux/bitops.h:96: error: dereferencing pointer ‘p’ does break strict-aliasing rules util/session.c:907: note: initialized from here
util/include/linux/bitops.h:96: note: initialized from here
make: *** [util/session.o] Error 1
make: *** Waiting for unfinished jobs....

Casting the @mask to (void *) still sees the same error

Thanks,
Feng

#10 lore raw

Re: [PATCH 3/3] perf tools: Fix a misuse of for_each_set_bit() in session.c

Quoted 11 lines · Feng Tang

It's a compile error:

cc1: warnings being treated as errors util/session.c: In function ‘perf_session_deliver_event’: util/include/linux/bitops.h:104: error:
dereferencing pointer ‘p’ does break strict-aliasing rules util/include/linux/bitops.h:96: error: dereferencing pointer ‘p’ does break strict-aliasing rules util/session.c:907: note: initialized from here util/include/linux/bitops.h:96: note: initialized from here make:
*** [util/session.o] Error 1
make: *** Waiting for unfinished jobs....

Quoted 4 lines

Casting the @mask to (void *) still sees the same error

Thanks,
Feng

We (ELRepo) are seeing the same error while building kernel 3.7 for RHEL 6.3 on a 32-bit system. The perf package would build fine if we run rpmbuild with the 'i686' target specified on a 64-bit system.

http://elrepo.org/bugs/view.php?id=335

Akemi