From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from 69-171-232-180.mail-mxout.facebook.com (69-171-232-180.mail-mxout.facebook.com [69.171.232.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F33551474D8 for ; Tue, 4 Jun 2024 17:56:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=69.171.232.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717523763; cv=none; b=BJHL3ROROqMhN4oeF6rnONauOKxS8ahE19Ry7KDK9xhHts9EoOumk3C06DRP/X9wiBHQf6EfzQvdM8gOca8xXpG21amOcHvDLapPPIOEuPvSPl35LRUpIykr8qs8AMWWCou94mSTfKMT4jZau+ZF8WRlhJHsXheKdx+pGJ2iPHs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717523763; c=relaxed/simple; bh=fwORXAf0vGkgNor15LiulCZCerTJbuReDRgx6kQMv88=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=q60NQ8GmOMeV7FLWeQoB8GnoC4WFL/7v8ptSZy68eMHLlP1Zu4Xi4ahOo+eikvxylRzTwHYNpPcSMBPeNX+y9SY3hf08Hr9dS0dK8Hacz+2l45lnDKOhlNe9MVwm/aZeSB0KXURTpivBGFa8QPL7vPRKPjUntQMW9WOK+2ebb5c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev; spf=fail smtp.mailfrom=linux.dev; arc=none smtp.client-ip=69.171.232.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=linux.dev Received: by devbig309.ftw3.facebook.com (Postfix, from userid 128203) id EEE275189E8D; Tue, 4 Jun 2024 10:55:46 -0700 (PDT) From: Yonghong Song To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , kernel-team@fb.com, Martin KaFai Lau Subject: [PATCH bpf-next] selftests/bpf: Ignore .llvm. suffix in kallsyms_find() Date: Tue, 4 Jun 2024 10:55:46 -0700 Message-ID: <20240604175546.1339303-1-yonghong.song@linux.dev> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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. in /proc/kallsyms, the kallsyms_find() failed. To fix the issue, in kallsyms_find(), if a symbol has suffix .llvm., that suffix will be ignored for comparison. This fixed the test failure. Signed-off-by: Yonghong Song --- tools/testing/selftests/bpf/trace_helpers.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/= selftests/bpf/trace_helpers.c index 70e29f316fe7..dc871e642ed5 100644 --- a/tools/testing/selftests/bpf/trace_helpers.c +++ b/tools/testing/selftests/bpf/trace_helpers.c @@ -221,6 +221,18 @@ int kallsyms_find(const char *sym, unsigned long lon= g *addr) return -EINVAL; =20 while (fscanf(f, "%llx %c %499s%*[^\n]\n", &value, &type, name) > 0) { + /* If CONFIG_LTO_CLANG_THIN is enabled, static variable/function + * symbols could be promoted to global due to cross-file inlining. + * For such cases, clang compiler will add .llvm. suffix + * to those symbols to avoid potential naming conflict. + * Let us ignore .llvm. suffix during symbol comparison. + */ + if (type =3D=3D 'd') { + char *res =3D strstr(name, ".llvm."); + + if (res) + *res =3D '\0'; + } if (strcmp(name, sym) =3D=3D 0) { *addr =3D value; goto out; --=20 2.43.0