Skip to contentSkip to conversation

perf symbol: Fix symbol loading from libbfd

PATCH Superseded Namhyung Kim 1 participant 2 messages Oct 10 perf events

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/2 perf symbol: Fix symbol loading from libbfd

The dso__load() should return a positive number (number of symbols loaded) when it succeded to load symbols. But dso__load_bfd_symbols() only returns 0 and it's hard to check if it actually loaded symbols or not. Let's return the value of dso__has_symbol() and check it in dso__load() so that it can return 1 for success.

Fixes eac9a4342e5447cad ("perf symbols: Try reading the symbol table with libbfd")
---
 tools/perf/util/libbfd.c | 2 +-
 tools/perf/util/symbol.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/libbfd.c +1 -1
index a907d7c1ac948808..a4dcb406c79e9cee 100644
@@ -463,7 +463,7 @@ int dso__load_bfd_symbols(struct dso *dso, const char *debugfile)
 	symbols__fixup_duplicate(dso__symbols(dso));
 	dso__set_adjust_symbols(dso, true);
 
-	err = 0;
+	err = dso__has_symbols(dso);
 out_free:
 	free(symbols);
 out_close:
tools/perf/util/symbol.c +2 -2
index 1175cb60f8206757..4d6c5d60cbaa693f 100644
@@ -1933,9 +1933,9 @@ int dso__load(struct dso *dso, struct map *map)
 		if (nsexit)
 			nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
 
-		if (bfdrc == 0) {
+		if (bfdrc > 0) {
 			dso__set_symtab_type(dso, symtab_type);
-			ret = 0;
+			ret = 1;
 			break;
 		}
 
Signature · 1 line
2.55.0
author maintainer
#1 lore raw

PATCH 2/2 perf symbol: Add missing symsrc__destroy() for libbfd

When libbfd loaded symbols and there's a pending syms_ss, it'd be lost or overwrite existing symbols. Let's destroy it before breaking the loop so that it can safely return from the function.

Fixes eac9a4342e5447cad ("perf symbols: Try reading the symbol table with libbfd")
---
 tools/perf/util/symbol.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/perf/util/symbol.c +4 -0
index 4d6c5d60cbaa693f..4335e6549d0aecf0 100644
@@ -1935,6 +1935,10 @@ int dso__load(struct dso *dso, struct map *map)
 
 		if (bfdrc > 0) {
 			dso__set_symtab_type(dso, symtab_type);
+			if (syms_ss) {
+				symsrc__destroy(syms_ss);
+				syms_ss = NULL;
+			}
 			ret = 1;
 			break;
 		}
Signature · 1 line
2.55.0