BPF List
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	kernel-team@fb.com, Martin KaFai Lau <martin.lau@kernel.org>
Subject: Re: [PATCH bpf-next] selftests/bpf: Ignore .llvm.<hash> suffix in kallsyms_find()
Date: Tue, 4 Jun 2024 10:58:52 -0700	[thread overview]
Message-ID: <5cd1549d-1728-4ed4-a35a-3cc80a993c9c@linux.dev> (raw)
In-Reply-To: <20240604175546.1339303-1-yonghong.song@linux.dev>


Sorry, messed up the git submit with two unrelated patches. Please ignore this.
Will submit the correct one soon.

On 6/4/24 10:55 AM, Yonghong Song wrote:
> 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 <yonghong.song@linux.dev>
> ---
>   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 long *addr)
>   		return -EINVAL;
>   
>   	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.<hash> suffix
> +		 * to those symbols to avoid potential naming conflict.
> +		 * Let us ignore .llvm.<hash> suffix during symbol comparison.
> +		 */
> +		if (type == 'd') {
> +			char *res = strstr(name, ".llvm.");
> +
> +			if (res)
> +				*res = '\0';
> +		}
>   		if (strcmp(name, sym) == 0) {
>   			*addr = value;
>   			goto out;

  parent reply	other threads:[~2024-06-04 17:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-04 17:55 [PATCH bpf-next] selftests/bpf: Ignore .llvm.<hash> suffix in kallsyms_find() Yonghong Song
2024-06-04 17:55 ` [PATCH] bpf: Support shadow stack Yonghong Song
2024-06-04 23:41   ` Yonghong Song
2024-06-04 17:55 ` [PATCH] bpf: Support bpf " Yonghong Song
2024-06-04 17:58 ` Yonghong Song [this message]
2024-06-04 20:01 ` [PATCH bpf-next] selftests/bpf: Ignore .llvm.<hash> suffix in kallsyms_find() Andrii Nakryiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5cd1549d-1728-4ed4-a35a-3cc80a993c9c@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox