bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Symbols with double underscore prefix are not emitted to BTF .ksyms DATASEC
@ 2022-10-11  3:18 Kumar Kartikeya Dwivedi
  2022-10-11  6:15 ` Yonghong Song
  0 siblings, 1 reply; 2+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2022-10-11  3:18 UTC (permalink / raw)
  To: bpf; +Cc: yhs, ast, andrii

Hi,

I discovered that for the following program:

 ; cat bpf.c
extern void *__bpf_kptr_new(int, int, void *)
__attribute__((section(".ksyms")));
#define bpf_kptr_new(x) __bpf_kptr_new(x, 0, 0)

struct foo {
        int data;
};

int main(void)
{
        struct foo *f;

        f = bpf_kptr_new(0);
        return f->data;
}
--
Compiling and dumping BTF shows that the __bpf_kptr_new extern is not
added to .ksyms DATASEC.

[1] FUNC_PROTO '(anon)' ret_type_id=2 vlen=0
[2] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
[3] FUNC 'main' type_id=1 linkage=global

However, removing the leading double underscores fixes this:
 ; cat bpf.c
extern void *bpf_kptr_new_(int, int, void *) __attribute__((section(".ksyms")));
#define bpf_kptr_new(x) bpf_kptr_new_(x, 0, 0)

struct foo {
        int data;
};

int main(void)
{
        struct foo *f;

        f = bpf_kptr_new(0);
        return f->data;
}
--

and dumping now shows:

[1] FUNC_PROTO '(anon)' ret_type_id=2 vlen=0
[2] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
[3] FUNC 'main' type_id=1 linkage=global
[4] FUNC_PROTO '(anon)' ret_type_id=5 vlen=3
        '(anon)' type_id=2
        '(anon)' type_id=2
        '(anon)' type_id=5
[5] PTR '(anon)' type_id=0
[6] FUNC 'bpf_kptr_new_' type_id=4 linkage=extern
[7] DATASEC '.ksyms' size=0 vlen=1
        type_id=6 offset=0 size=0 (FUNC 'bpf_kptr_new_')

This is on the latest clang nightly.

Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Symbols with double underscore prefix are not emitted to BTF .ksyms DATASEC
  2022-10-11  3:18 Symbols with double underscore prefix are not emitted to BTF .ksyms DATASEC Kumar Kartikeya Dwivedi
@ 2022-10-11  6:15 ` Yonghong Song
  0 siblings, 0 replies; 2+ messages in thread
From: Yonghong Song @ 2022-10-11  6:15 UTC (permalink / raw)
  To: Kumar Kartikeya Dwivedi, bpf; +Cc: yhs, ast, andrii



On 10/10/22 8:18 PM, Kumar Kartikeya Dwivedi wrote:
> Hi,
> 
> I discovered that for the following program:
> 
>   ; cat bpf.c
> extern void *__bpf_kptr_new(int, int, void *)
> __attribute__((section(".ksyms")));
> #define bpf_kptr_new(x) __bpf_kptr_new(x, 0, 0)
> 
> struct foo {
>          int data;
> };
> 
> int main(void)
> {
>          struct foo *f;
> 
>          f = bpf_kptr_new(0);
>          return f->data;
> }
> --
> Compiling and dumping BTF shows that the __bpf_kptr_new extern is not
> added to .ksyms DATASEC.
> 
> [1] FUNC_PROTO '(anon)' ret_type_id=2 vlen=0
> [2] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
> [3] FUNC 'main' type_id=1 linkage=global
> 
> However, removing the leading double underscores fixes this:
>   ; cat bpf.c
> extern void *bpf_kptr_new_(int, int, void *) __attribute__((section(".ksyms")));
> #define bpf_kptr_new(x) bpf_kptr_new_(x, 0, 0)
> 
> struct foo {
>          int data;
> };
> 
> int main(void)
> {
>          struct foo *f;
> 
>          f = bpf_kptr_new(0);
>          return f->data;
> }
> --
> 
> and dumping now shows:
> 
> [1] FUNC_PROTO '(anon)' ret_type_id=2 vlen=0
> [2] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
> [3] FUNC 'main' type_id=1 linkage=global
> [4] FUNC_PROTO '(anon)' ret_type_id=5 vlen=3
>          '(anon)' type_id=2
>          '(anon)' type_id=2
>          '(anon)' type_id=5
> [5] PTR '(anon)' type_id=0
> [6] FUNC 'bpf_kptr_new_' type_id=4 linkage=extern
> [7] DATASEC '.ksyms' size=0 vlen=1
>          type_id=6 offset=0 size=0 (FUNC 'bpf_kptr_new_')
> 
> This is on the latest clang nightly.

Thanks, Kumar, for reporting. I can reproduce the issue. It is due to
clang frontend. We will take a look and find out a solution
for this.

> 
> Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-11  6:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-11  3:18 Symbols with double underscore prefix are not emitted to BTF .ksyms DATASEC Kumar Kartikeya Dwivedi
2022-10-11  6:15 ` Yonghong Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).