Skip to contentSkip to conversation

tool/perf: Perf build fails on 5.12.0rc2 on s390

PATCH Applied Thomas Richter 2 participants 2 messages Mar 9, 2021 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tool/perf: Perf build fails on 5.12.0rc2 on s390

perf build fails on 5.12.0rc2 on s390 with this error message:

util/synthetic-events.c: In function
‘__event__synthesize_thread.part.0.isra’:
util/synthetic-events.c:787:19: error: ‘kernel_thread’ may be

    used uninitialized in this function [-Werror=maybe-uninitialized]
    787 |   if (_pid == pid && !kernel_thread) {
        |       ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

The build succeeds using command 'make DEBUG=y'.

The variable kernel_thread is set by this function sequence:

__event__synthesize_thread()
| defines bool kernel_thread; as local variable and calls

+--> perf_event__prepare_comm(..., &kernel_thread)
     +--> perf_event__get_comm_ids(..., bool *kernel);

On return of this function variable kernel is always set to true of false.

To prevent this compile error, assign variable kernel_thread a value when it is defined.

Output after:
[root@m35lp76 perf]# make util/synthetic-events.o
....
CC util/synthetic-events.o
[root@m35lp76 perf]#

---
 tools/perf/util/synthetic-events.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/synthetic-events.c +1 -1
index b698046ec2db..5dd451695f33 100644
@@ -758,7 +758,7 @@ static int __event__synthesize_thread(union perf_event *comm_event,
 	for (i = 0; i < n; i++) {
 		char *end;
 		pid_t _pid;
-		bool kernel_thread;
+		bool kernel_thread = false;
 
 		_pid = strtol(dirent[i]->d_name, &end, 10);
 		if (*end)
Signature · 1 line
2.29.2
maintainer Applied
#1 lore raw

Em Tue, Mar 09, 2021 at 12:04:47PM +0100, Thomas Richter escreveu:

Quoted 11 lines

perf build fails on 5.12.0rc2 on s390 with this error message:

util/synthetic-events.c: In function
‘__event__synthesize_thread.part.0.isra’:
util/synthetic-events.c:787:19: error: ‘kernel_thread’ may be

    used uninitialized in this function [-Werror=maybe-uninitialized]
    787 |   if (_pid == pid && !kernel_thread) {
        |       ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

The build succeeds using command 'make DEBUG=y'.

Quoted 8 lines

The variable kernel_thread is set by this function sequence:

__event__synthesize_thread()
| defines bool kernel_thread; as local variable and calls

+--> perf_event__prepare_comm(..., &kernel_thread)
     +--> perf_event__get_comm_ids(..., bool *kernel);

On return of this function variable kernel is always set to true of false.

    s/of/or/

But it is only called for the host 'struct machine', if that is not the case, then the value of 'kernel_thread' is left undefined/uninitialized, right?

Quoted 3 lines

To prevent this compile error, assign variable kernel_thread a value when it is defined.

Applied, and added:

Fixes c1b907953b2cd9ff ("perf tools: Skip PERF_RECORD_MMAP event synthesis for kernel threads")

Changed the subject to:

perf synthetic-events: Fix uninitialized 'kernel_thread' variable

As this doesn't affect just s/390, it is entirely possible that that variable gets used with an undefined value.

- Arnaldo

Quoted 27 lines

Output after:
[root@m35lp76 perf]# make util/synthetic-events.o
....
CC util/synthetic-events.o
[root@m35lp76 perf]#

---
 tools/perf/util/synthetic-events.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/synthetic-events.c +1 -1
index b698046ec2db..5dd451695f33 100644
@@ -758,7 +758,7 @@ static int __event__synthesize_thread(union perf_event *comm_event,
 	for (i = 0; i < n; i++) {
 		char *end;
 		pid_t _pid;
-		bool kernel_thread;
+		bool kernel_thread = false;
 
 		_pid = strtol(dirent[i]->d_name, &end, 10);
 		if (*end)
Signature · 1 line
2.29.2
Signature · 1 line
- Arnaldo