Skip to contentSkip to conversation

perf llvm: Clean up after a failed disassembly

PATCH Applied Peter Collingbourne 3 participants 4 messages Mar 3 – Mar 4 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf llvm: Clean up after a failed disassembly

An error returned from a failed backend will cause perf to call the next backend. If the error happens mid-function, e.g. due to an unrecognized instruction, we will end up with duplicated instructions in the output unless the backend that failed deletes any instructions that it created before failing. The capstone backend was already doing this but the LLVM backend was not; fix it.

---
 tools/perf/util/llvm.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/perf/util/llvm.c +9 -0
index 0d126d233c019..87fceae8488a7 100644
@@ -261,6 +261,15 @@ int symbol__disassemble_llvm(const char *filename, struct symbol *sym,
 	ret = 0;
 
 err:
+	if (ret != 0) {
+		struct disasm_line *tmp;
+
+		list_for_each_entry_safe(dl, tmp, &notes->src->source,
+					 al.node) {
+			list_del(&dl->al.node);
+			disasm_line__free(dl);
+		}
+	}
 	LLVMDisasmDispose(disasm);
 	free(code_buf);
 	free(line_storage);
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Peter Collingbourne

An error returned from a failed backend will cause perf to call the next backend. If the error happens mid-function, e.g. due to an unrecognized instruction, we will end up with duplicated instructions in the output unless the backend that failed deletes any instructions that it created before failing. The capstone backend was already doing this but the LLVM backend was not; fix it.

Thanks,
Ian

Quoted 27 lines
---
 tools/perf/util/llvm.c | 9 +++++++++
 1 file changed, 9 insertions(+)
tools/perf/util/llvm.c +9 -1
index 0d126d233c019..87fceae8488a7 100644
@@ -261,6 +261,15 @@ int symbol__disassemble_llvm(const char *filename, struct symbol *sym,
        ret = 0;
 
 err:
+       if (ret != 0) {
+               struct disasm_line *tmp;
+
+               list_for_each_entry_safe(dl, tmp, &notes->src->source,
+                                        al.node) {
+                       list_del(&dl->al.node);
+                       disasm_line__free(dl);
+               }
+       }
        LLVMDisasmDispose(disasm);
        free(code_buf);
        free(line_storage);
--

2.53.0.473.g4a7958ca14-goog

#2 lore raw
Quoted 10 lines · Ian Rogers
Quoted 8 lines · Peter Collingbourne

An error returned from a failed backend will cause perf to call the next backend. If the error happens mid-function, e.g. due to an unrecognized instruction, we will end up with duplicated instructions in the output unless the backend that failed deletes any instructions that it created before failing. The capstone backend was already doing this but the LLVM backend was not; fix it.

Quoted 4 lines
Quoted 2 lines

Thanks for the review. I guess this one should have also had

Fixes 048856817888 ("perf annotate: LLVM-based disassembler")

Peter

maintainer Applied
#3 lore raw
Quoted 11 lines · Peter Collingbourne
Quoted 10 lines · Ian Rogers
Quoted 8 lines · Peter Collingbourne

An error returned from a failed backend will cause perf to call the next backend. If the error happens mid-function, e.g. due to an unrecognized instruction, we will end up with duplicated instructions in the output unless the backend that failed deletes any instructions that it created before failing. The capstone backend was already doing this but the LLVM backend was not; fix it.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Thanks for the review. I guess this one should have also had

Fixes 048856817888 ("perf annotate: LLVM-based disassembler")

Thanks, applied to perf-tools, for v7.0.

- Arnaldo