Skip to content

Commit 5d59c8e

Browse files
Yonghong SongKernel Patches Daemon
Yonghong Song
authored and
Kernel Patches Daemon
committed
selftests/bpf: Ignore .llvm.<hash> suffix in kallsyms_find()
I hit the following failure when running selftests with internal backported upstream kernel: test_ksyms:PASS:kallsyms_fopen 0 nsec test_ksyms:FAIL:ksym_find symbol 'bpf_link_fops' not found #123 ksyms:FAIL In /proc/kallsyms, we have $ cat /proc/kallsyms | grep bpf_link_fops ffffffff829f0cb0 d bpf_link_fops.llvm.12608678492448798416 The CONFIG_LTO_CLANG_THIN is enabled in the kernel which is responsible for bpf_link_fops.llvm.12608678492448798416 symbol name. In prog_tests/ksyms.c we have kallsyms_find("bpf_link_fops", &link_fops_addr) and kallsyms_find() compares "bpf_link_fops" with symbols in /proc/kallsyms in order to find the entry. With bpf_link_fops.llvm.<hash> in /proc/kallsyms, the kallsyms_find() failed. To fix the issue, in kallsyms_find(), if a symbol has suffix .llvm.<hash>, that suffix will be ignored for comparison. This fixed the test failure. Signed-off-by: Yonghong Song <[email protected]>
1 parent 1eed4b7 commit 5d59c8e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tools/testing/selftests/bpf/trace_helpers.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,18 @@ int kallsyms_find(const char *sym, unsigned long long *addr)
221221
return -EINVAL;
222222

223223
while (fscanf(f, "%llx %c %499s%*[^\n]\n", &value, &type, name) > 0) {
224+
/* If CONFIG_LTO_CLANG_THIN is enabled, static variable/function
225+
* symbols could be promoted to global due to cross-file inlining.
226+
* For such cases, clang compiler will add .llvm.<hash> suffix
227+
* to those symbols to avoid potential naming conflict.
228+
* Let us ignore .llvm.<hash> suffix during symbol comparison.
229+
*/
230+
if (type == 'd') {
231+
char *res = strstr(name, ".llvm.");
232+
233+
if (res)
234+
*res = '\0';
235+
}
224236
if (strcmp(name, sym) == 0) {
225237
*addr = value;
226238
goto out;

0 commit comments

Comments
 (0)