Skip to contentSkip to conversation

perf tests vmlinux-kallsyms: ignore hidden symbols

PATCH In review Michael Petlan 2 participants 4 messages Jul 8, 2021 – Jul 23, 2021 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf tests vmlinux-kallsyms: ignore hidden symbols

Symbols containing particular prefixes are purposely hidden from kallsyms. The prefixes are listed in scripts/kallsyms.c, using ignored_prefixes[] string array. The perf test "vmlinux symtab matches kallsyms" fails in case perf finds some of the hidden symbols in its machine image and can't match them to kallsyms.

Let's add a filter to check if a symbol not found isn't one of these before failing the test.

The ignored_prefixes[] array has been copied from scripts/kallsyms.c and needs to be updated along with the original.

---
 tools/perf/tests/vmlinux-kallsyms.c | 41 +++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
tools/perf/tests/vmlinux-kallsyms.c +41 -0
index 193b7c91b4e2..11cd276ec8fd 100644
@@ -14,6 +14,41 @@
 
 #define UM(x) kallsyms_map->unmap_ip(kallsyms_map, (x))
 
+/* Symbol names that begin with the following are ignored. (a copy from scripts/kallsyms.c) */
+static const char * const ignored_prefixes[] = {
+	"$",			/* local symbols for ARM, MIPS, etc. */
+	".LASANPC",		/* s390 kasan local symbols */
+	"__crc_",		/* modversions */
+	"__efistub_",		/* arm64 EFI stub namespace */
+	"__kvm_nvhe_",		/* arm64 non-VHE KVM namespace */
+	"__AArch64ADRPThunk_",	/* arm64 lld */
+	"__ARMV5PILongThunk_",	/* arm lld */
+	"__ARMV7PILongThunk_",
+	"__ThumbV7PILongThunk_",
+	"__LA25Thunk_",		/* mips lld */
+	"__microLA25Thunk_",
+	NULL
+};
+
+static int has_prefix(const char *prefix, const char *string)
+{
+	while(*prefix)
+        if(*prefix++ != *string++)
+            return 0;
+
+	return 1;
+}
+
+static int should_be_hidden(const char *sym_name)
+{
+	int i;
+	for(i = 0; ignored_prefixes[i] != NULL; i++)
+		if(has_prefix(ignored_prefixes[i], sym_name))
+			return 1;
+
+	return 0;
+}
+
 int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest __maybe_unused)
 {
 	int err = -1;
@@ -169,6 +204,12 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
 			 * such as __indirect_thunk_end.
 			 */
 			continue;
+		} else if (should_be_hidden(sym->name)) {
+			/*
+			 * Ignore hidden symbols, see scripts/kallsyms.c for the ignored_prefixes[]
+			 * array
+			 */
+			continue;
 		} else {
 			pr_debug("ERR : %#" PRIx64 ": %s not on kallsyms\n",
 				 mem_start, sym->name);
Signature · 1 line
2.18.4
#1 lore raw
Quoted 5 lines · Michael Petlan

Symbols containing particular prefixes are purposely hidden from kallsyms. The prefixes are listed in scripts/kallsyms.c, using ignored_prefixes[] string array. The perf test "vmlinux symtab matches kallsyms" fails in case perf finds some of the hidden symbols in its machine image and can't match them to kallsyms.

there's also other arrays like ignored_suffixes, ignored_matches ... should we have them as well? should we take the whole is_ignored_symbol function?

Quoted 43 lines

Let's add a filter to check if a symbol not found isn't one of these before failing the test.

The ignored_prefixes[] array has been copied from scripts/kallsyms.c and needs to be updated along with the original.

---
 tools/perf/tests/vmlinux-kallsyms.c | 41 +++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
tools/perf/tests/vmlinux-kallsyms.c +23 -0
index 193b7c91b4e2..11cd276ec8fd 100644
@@ -14,6 +14,41 @@
 
 #define UM(x) kallsyms_map->unmap_ip(kallsyms_map, (x))
 
+/* Symbol names that begin with the following are ignored. (a copy from scripts/kallsyms.c) */
+static const char * const ignored_prefixes[] = {
+	"$",			/* local symbols for ARM, MIPS, etc. */
+	".LASANPC",		/* s390 kasan local symbols */
+	"__crc_",		/* modversions */
+	"__efistub_",		/* arm64 EFI stub namespace */
+	"__kvm_nvhe_",		/* arm64 non-VHE KVM namespace */
+	"__AArch64ADRPThunk_",	/* arm64 lld */
+	"__ARMV5PILongThunk_",	/* arm lld */
+	"__ARMV7PILongThunk_",
+	"__ThumbV7PILongThunk_",
+	"__LA25Thunk_",		/* mips lld */
+	"__microLA25Thunk_",
+	NULL
+};
+
+static int has_prefix(const char *prefix, const char *string)
+{
+	while(*prefix)
+        if(*prefix++ != *string++)
+            return 0;
+
+	return 1;

tools/perf/tests/vmlinux-kallsyms.c line 49

Quoted 10 lines
tools/perf/tests/vmlinux-kallsyms.c +10 -0
+}
+
+static int should_be_hidden(const char *sym_name)
+{
+	int i;
+	for(i = 0; ignored_prefixes[i] != NULL; i++)
+		if(has_prefix(ignored_prefixes[i], sym_name))
+			return 1;
+
+	return 0;

please check your patch with scripts/checkpatch.pl before posting

thanks,
jirka

#2 lore raw
Quoted 10 lines · Jiri Olsa
Quoted 5 lines · Michael Petlan

Symbols containing particular prefixes are purposely hidden from kallsyms. The prefixes are listed in scripts/kallsyms.c, using ignored_prefixes[] string array. The perf test "vmlinux symtab matches kallsyms" fails in case perf finds some of the hidden symbols in its machine image and can't match them to kallsyms.

there's also other arrays like ignored_suffixes, ignored_matches ... should we have them as well? should we take the whole is_ignored_symbol function?

Well, maybe? There hasn't been a problem with the others yet... :-)

Arnaldo, should I do a v2 with the above?

Quoted 61 lines
Quoted 44 lines

Let's add a filter to check if a symbol not found isn't one of these before failing the test.

The ignored_prefixes[] array has been copied from scripts/kallsyms.c and needs to be updated along with the original.

---
 tools/perf/tests/vmlinux-kallsyms.c | 41 +++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
tools/perf/tests/vmlinux-kallsyms.c +23 -0
index 193b7c91b4e2..11cd276ec8fd 100644
@@ -14,6 +14,41 @@
 
 #define UM(x) kallsyms_map->unmap_ip(kallsyms_map, (x))
 
+/* Symbol names that begin with the following are ignored. (a copy from scripts/kallsyms.c) */
+static const char * const ignored_prefixes[] = {
+	"$",			/* local symbols for ARM, MIPS, etc. */
+	".LASANPC",		/* s390 kasan local symbols */
+	"__crc_",		/* modversions */
+	"__efistub_",		/* arm64 EFI stub namespace */
+	"__kvm_nvhe_",		/* arm64 non-VHE KVM namespace */
+	"__AArch64ADRPThunk_",	/* arm64 lld */
+	"__ARMV5PILongThunk_",	/* arm lld */
+	"__ARMV7PILongThunk_",
+	"__ThumbV7PILongThunk_",
+	"__LA25Thunk_",		/* mips lld */
+	"__microLA25Thunk_",
+	NULL
+};
+
+static int has_prefix(const char *prefix, const char *string)
+{
+	while(*prefix)
+        if(*prefix++ != *string++)
+            return 0;
+
+	return 1;

tools/perf/tests/vmlinux-kallsyms.c line 49

Quoted 10 lines
tools/perf/tests/vmlinux-kallsyms.c +10 -0
+}
+
+static int should_be_hidden(const char *sym_name)
+{
+	int i;
+	for(i = 0; ignored_prefixes[i] != NULL; i++)
+		if(has_prefix(ignored_prefixes[i], sym_name))
+			return 1;
+
+	return 0;

please check your patch with scripts/checkpatch.pl before posting

thanks,
jirka

#3 lore raw

PATCH 1/1 perf tests vmlinux-kallsyms: ignore hidden symbols

In reply to Michael Petlan

Symbols containing particular prefixes are purposely hidden from kallsyms. The prefixes are listed in scripts/kallsyms.c, using ignored_prefixes[] string array. The perf test "vmlinux symtab matches kallsyms" fails in case perf finds some of the hidden symbols in its machine image and can't match them to kallsyms.

Let's add a filter to check if a symbol not found isn't one of these before failing the test.

The ignored_prefixes[] array has been copied from scripts/kallsyms.c and needs to be updated along with the original.

v2: Fixed formatting issues.

---
 tools/perf/tests/vmlinux-kallsyms.c | 42 +++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
tools/perf/tests/vmlinux-kallsyms.c +42 -0
index 193b7c91b4e2..fb9696bbf6f3 100644
@@ -14,6 +14,42 @@
 
 #define UM(x) kallsyms_map->unmap_ip(kallsyms_map, (x))
 
+/* Symbol names that begin with the following are ignored. (a copy from scripts/kallsyms.c) */
+static const char * const ignored_prefixes[] = {
+	"$",			/* local symbols for ARM, MIPS, etc. */
+	".LASANPC",		/* s390 kasan local symbols */
+	"__crc_",		/* modversions */
+	"__efistub_",		/* arm64 EFI stub namespace */
+	"__kvm_nvhe_",		/* arm64 non-VHE KVM namespace */
+	"__AArch64ADRPThunk_",	/* arm64 lld */
+	"__ARMV5PILongThunk_",	/* arm lld */
+	"__ARMV7PILongThunk_",
+	"__ThumbV7PILongThunk_",
+	"__LA25Thunk_",		/* mips lld */
+	"__microLA25Thunk_",
+	NULL
+};
+
+static int has_prefix(const char *prefix, const char *string)
+{
+	while (*prefix)
+		if (*prefix++ != *string++)
+			return 0;
+
+	return 1;
+}
+
+static int should_be_hidden(const char *sym_name)
+{
+	int i;
+
+	for (i = 0; ignored_prefixes[i] != NULL; i++)
+		if (has_prefix(ignored_prefixes[i], sym_name))
+			return 1;
+
+	return 0;
+}
+
 int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest __maybe_unused)
 {
 	int err = -1;
@@ -169,6 +205,12 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
 			 * such as __indirect_thunk_end.
 			 */
 			continue;
+		} else if (should_be_hidden(sym->name)) {
+			/*
+			 * Ignore hidden symbols, see scripts/kallsyms.c for the ignored_prefixes[]
+			 * array
+			 */
+			continue;
 		} else {
 			pr_debug("ERR : %#" PRIx64 ": %s not on kallsyms\n",
 				 mem_start, sym->name);
Signature · 1 line
2.18.4