Skip to contentSkip to conversation

Subject: perf jit: Fix incorrect file name in DWARF line table

PATCH Superseded elisabeth 2 participants 3 messages May 31, 2023 – Jun 1, 2023 3 messages not in the archive perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

elisabeth

author
#0 lore raw

PATCH 1/1 Subject: perf jit: Fix incorrect file name in DWARF line table

Fix an issue where an incorrect file name was added in the DWARF line table due to not checking the filename against the repeated name marker (/xff/0). This can be seen with objdump --dwarf=line on the ELF file after perf inject.

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/util/genelf_debug.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/genelf_debug.c +3 -1
index aa5dcc56b2ac..2928b59bb9a5 100644
@@ -349,6 +349,7 @@ static void emit_lineno_info(struct buffer_ext *be,
 	 */
 
 	/* start state of the state machine we take care of */
+	char const repeated_name_marker[] = {'\xff', '\0'};
 	unsigned long last_vma = 0;
 	char const  *cur_filename = NULL;
 	unsigned long cur_file_idx = 0;
@@ -363,7 +364,8 @@ static void emit_lineno_info(struct buffer_ext *be,
 		/*
 		 * check if filename changed, if so add it
 		 */
-		if (!cur_filename || strcmp(cur_filename, ent->name)) {
+		if ((!cur_filename || strcmp(cur_filename, ent->name)) &&
+			memcmp(repeated_name_marker, ent->name, sizeof(repeated_name_marker)) != 0) {
 			emit_lne_define_filename(be, ent->name);
 			cur_filename = ent->name;
 			emit_set_file(be, ++cur_file_idx);
Signature · 1 line
2.34.1

A message that is not in the archive (sent off-list or not yet received): CAM9d7cgsP9cBq_Ui9-53zO0nLzBUK67goO1UcnqZ93Z4E7QcFQ@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CAOh+m7w8uE-2HKi=+gXL6sFbsPRGBfKA4eNT+kJTVhHhJmMSLw@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CAM9d7cho4-JOWTex0GkScQA2kmg3ZU5bqbRbUb_mG3vsoQ9vng@mail.gmail.com

#4 lore raw
Quoted 40 lines · Namhyung Kim

Hello,

Quoted 20 lines · Elisabeth Panholzer

Hello again,

Quoted 5 lines · Namhyung Kim

Hello,

Quoted 1 line · elisabeth
Quoted 10 lines
Quoted 3 lines

Fix an issue where an incorrect file name was added in the DWARF line table due to not checking the filename against the repeated name marker (/xff/0). This can be seen with objdump --dwarf=line on the ELF file after perf inject.

I'm not aware of the marker. Could you please provide a link or something?

Thanks,
Namhyung

Quoted 15 lines

The marker is mentioned in the tools/perf/util/jitdump.h header, this file describes the jitdump binary format. According to a comment in the ‘debug_entry’ struct in the ‘jitdump.h’ file, a filename set to ‘\xff\0’ indicates that the name is the same as the one from the previous entry. When profiling applications in the browser together with v8, I noticed ‘perf inject --jit’ inserts a bogus file name in the DWARF line table. This happens because in the perf source code in the file tools/perf/util/genelf-debug.c, in the function emit_lineno_info(), the debug entry file gets compared to the previous debug entry file. If they are not the same, a new filename is added to the DWARF line table. However, there is no check for ‘\xff\0’, which indicates that it's the same file. As a result, ‘\xff\0’ is inserted as the filename into the DWARF section. This not only makes ‘objdump --dwarf=line’ print bogus as the filename, but it also makes no source code information show up in perf annotate.

Quoted 3 lines

Thanks for your detailed answer. It would be great if you could send it to the mailing list so that others can see it as well.

I added the mailing lists to the cc again.

Quoted 2 lines

So it's from the jitdump format. I thought it was a part of DWARF or some other specification.

It is part of the jitdump format, yes.
The data from the jitdump, generated by for example v8, is just used to generate the ELF images and the DWARF data with 'perf inject --jit'.

Quoted 8 lines
Quoted 4 lines

Hope this makes it more clear,
Elisabeth

Sure, it really helped, thanks.
Namhyung

You're welcome.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 93 lines · Namhyung Kim

Hello,

Quoted 20 lines · Elisabeth Panholzer

Hello again,

Quoted 5 lines · Namhyung Kim

Hello,

Quoted 1 line · elisabeth
Quoted 10 lines
Quoted 3 lines

Fix an issue where an incorrect file name was added in the DWARF line table due to not checking the filename against the repeated name marker (/xff/0). This can be seen with objdump --dwarf=line on the ELF file after perf inject.

I'm not aware of the marker. Could you please provide a link or something?

Thanks,
Namhyung

Quoted 15 lines

The marker is mentioned in the tools/perf/util/jitdump.h header, this file describes the jitdump binary format. According to a comment in the ‘debug_entry’ struct in the ‘jitdump.h’ file, a filename set to ‘\xff\0’ indicates that the name is the same as the one from the previous entry. When profiling applications in the browser together with v8, I noticed ‘perf inject --jit’ inserts a bogus file name in the DWARF line table. This happens because in the perf source code in the file tools/perf/util/genelf-debug.c, in the function emit_lineno_info(), the debug entry file gets compared to the previous debug entry file. If they are not the same, a new filename is added to the DWARF line table. However, there is no check for ‘\xff\0’, which indicates that it's the same file. As a result, ‘\xff\0’ is inserted as the filename into the DWARF section. This not only makes ‘objdump --dwarf=line’ print bogus as the filename, but it also makes no source code information show up in perf annotate.

Thanks for your detailed answer. It would be great if you could send it to the mailing list so that others can see it as well.

So it's from the jitdump format. I thought it was a part of DWARF or some other specification.

Quoted 3 lines

Hope this makes it more clear,
Elisabeth

Sure, it really helped, thanks.
Namhyung

Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/util/genelf_debug.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/genelf_debug.c +3 -2
index aa5dcc56b2ac..2928b59bb9a5 100644
@@ -349,6 +349,7 @@ static void emit_lineno_info(struct buffer_ext *be,
         */
 
        /* start state of the state machine we take care of */
+       char const repeated_name_marker[] = {'\xff', '\0'};
        unsigned long last_vma = 0;
        char const  *cur_filename = NULL;
        unsigned long cur_file_idx = 0;
@@ -363,7 +364,8 @@ static void emit_lineno_info(struct buffer_ext *be,
                /*
                 * check if filename changed, if so add it
                 */
-               if (!cur_filename || strcmp(cur_filename, ent->name)) {
+               if ((!cur_filename || strcmp(cur_filename, ent->name)) &&
+                       memcmp(repeated_name_marker, ent->name, sizeof(repeated_name_marker)) != 0) {
                        emit_lne_define_filename(be, ent->name);
                        cur_filename = ent->name;
                        emit_set_file(be, ++cur_file_idx);
--

2.34.1

maintainer
#5 lore raw
In reply to elisabeth
Quoted 22 lines · elisabeth

Fix an issue where an incorrect file name was added in the DWARF line table due to not checking the filename against the repeated name marker (/xff/0). This can be seen with objdump --dwarf=line on the ELF file after perf inject.

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/util/genelf_debug.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/genelf_debug.c +0 -0
index aa5dcc56b2ac..2928b59bb9a5 100644

tools/perf/util/genelf_debug.c static void emit_lineno_info(struct buffer_ext *be, · line 352

Quoted 4 lines
tools/perf/util/genelf_debug.c +1 -0
@@ -349,6 +349,7 @@ static void emit_lineno_info(struct buffer_ext *be,
         */
 
        /* start state of the state machine we take care of */
+       char const repeated_name_marker[] = {'\xff', '\0'};

Can you please mention that it's from the jitdump format either by renaming or adding a comment?

tools/perf/util/genelf_debug.c static void emit_lineno_info(struct buffer_ext *be, · line 368

Quoted 10 lines
tools/perf/util/genelf_debug.c +2 -1
        unsigned long last_vma = 0;
        char const  *cur_filename = NULL;
        unsigned long cur_file_idx = 0;
@@ -363,7 +364,8 @@ static void emit_lineno_info(struct buffer_ext *be,
                /*
                 * check if filename changed, if so add it
                 */
-               if (!cur_filename || strcmp(cur_filename, ent->name)) {
+               if ((!cur_filename || strcmp(cur_filename, ent->name)) &&
+                       memcmp(repeated_name_marker, ent->name, sizeof(repeated_name_marker)) != 0) {

I think you can just use strcmp().

Thanks,
Namhyung

Quoted 6 lines
tools/perf/util/genelf_debug.c +0 -1
                        emit_lne_define_filename(be, ent->name);
                        cur_filename = ent->name;
                        emit_set_file(be, ++cur_file_idx);
--

2.34.1