bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* bpf_core_type_id_kernel with qualifier aborts clang compilation
@ 2021-03-04 11:25 Lorenz Bauer
  2021-03-04 16:41 ` Yonghong Song
  0 siblings, 1 reply; 4+ messages in thread
From: Lorenz Bauer @ 2021-03-04 11:25 UTC (permalink / raw)
  To: Yonghong Song, Andrii Nakryiko; +Cc: bpf

Hi Yonghong, Andrii,

Some more poking at CO-RE. The code below leads to a compiler error:

struct s {
    int _1;
    char _2;
};

__section("socket_filter/type_ids") int type_ids() {
    return bpf_core_type_id_kernel(const struct s);
}

Truncated output:
fatal error: error in backend: Empty type name for BTF_TYPE_ID_REMOTE reloc
PLEASE submit a bug report to https://bugs.llvm.org/ and include the
crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.    Program arguments: clang-12 -target bpf -O2 -g -Wall -Werror
-mlittle-endian -c internal/btf/testdata/relocs.c -o
internal/btf/testdata/relocs-el.elf
1.    <eof> parser at end of file
2.    Per-function optimization
3.    Running pass 'BPF Preserve Debuginfo Type' on function '@type_ids'
...
clang: error: clang frontend command failed with exit code 70 (use -v
to see invocation)
Ubuntu clang version
12.0.0-++20210126113614+510b3d4b3e02-1~exp1~20210126104320.178
Target: bpf

"volatile" has the same problem. Interestingly, the same code works
for bpf_core_type_id_local. Is this expected?

Best
Lorenz

-- 
Lorenz Bauer  |  Systems Engineer
6th Floor, County Hall/The Riverside Building, SE1 7PB, UK

www.cloudflare.com

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

* Re: bpf_core_type_id_kernel with qualifier aborts clang compilation
  2021-03-04 11:25 bpf_core_type_id_kernel with qualifier aborts clang compilation Lorenz Bauer
@ 2021-03-04 16:41 ` Yonghong Song
  2021-03-05 21:36   ` Yonghong Song
  0 siblings, 1 reply; 4+ messages in thread
From: Yonghong Song @ 2021-03-04 16:41 UTC (permalink / raw)
  To: Lorenz Bauer, Andrii Nakryiko; +Cc: bpf



On 3/4/21 3:25 AM, Lorenz Bauer wrote:
> Hi Yonghong, Andrii,
> 
> Some more poking at CO-RE. The code below leads to a compiler error:
> 
> struct s {
>      int _1;
>      char _2;
> };
> 
> __section("socket_filter/type_ids") int type_ids() {
>      return bpf_core_type_id_kernel(const struct s);
> }
> 
> Truncated output:
> fatal error: error in backend: Empty type name for BTF_TYPE_ID_REMOTE reloc
> PLEASE submit a bug report to https://bugs.llvm.org/  and include the
> crash backtrace, preprocessed source, and associated run script.
> Stack dump:
> 0.    Program arguments: clang-12 -target bpf -O2 -g -Wall -Werror
> -mlittle-endian -c internal/btf/testdata/relocs.c -o
> internal/btf/testdata/relocs-el.elf
> 1.    <eof> parser at end of file
> 2.    Per-function optimization
> 3.    Running pass 'BPF Preserve Debuginfo Type' on function '@type_ids'
> ...
> clang: error: clang frontend command failed with exit code 70 (use -v
> to see invocation)
> Ubuntu clang version
> 12.0.0-++20210126113614+510b3d4b3e02-1~exp1~20210126104320.178
> Target: bpf
> 
> "volatile" has the same problem. Interestingly, the same code works
> for bpf_core_type_id_local. Is this expected?

First, bpf_core_type_id_local() works as compiler did not check type 
name. for bpf_core_type_id_local(), there is no relocation, libbpf
may need to adjust type id if it tries to do btf dedup, merging, etc.

Second, the above bpf_core_type_id_kernel() failed due to
"const" (or "volatile") modifier. bpf_core_type_id_kernel()
requires a type name as relocation will be performed.
In the current implementation, the btf type is
    const -> struct s
and there is no name for "const", that is why compiler issues
an explicit fatal error:
     fatal error: error in backend: Empty type name for 
BTF_TYPE_ID_REMOTE reloc

To fix the issue, just do not use any modifier,
   bpf_core_type_id_kernel(struct s)
should work fine.

I think in the case, it would be good if the compiler tries
to peel off modifiers and find the ultimate type name
instead of fatal error. I will put a patch on this.

Thanks for reporting!

> 
> Best
> Lorenz
> 

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

* Re: bpf_core_type_id_kernel with qualifier aborts clang compilation
  2021-03-04 16:41 ` Yonghong Song
@ 2021-03-05 21:36   ` Yonghong Song
  2021-03-08  9:33     ` Lorenz Bauer
  0 siblings, 1 reply; 4+ messages in thread
From: Yonghong Song @ 2021-03-05 21:36 UTC (permalink / raw)
  To: Lorenz Bauer, Andrii Nakryiko; +Cc: bpf



On 3/4/21 8:41 AM, Yonghong Song wrote:
> 
> 
> On 3/4/21 3:25 AM, Lorenz Bauer wrote:
>> Hi Yonghong, Andrii,
>>
>> Some more poking at CO-RE. The code below leads to a compiler error:
>>
>> struct s {
>>      int _1;
>>      char _2;
>> };
>>
>> __section("socket_filter/type_ids") int type_ids() {
>>      return bpf_core_type_id_kernel(const struct s);
>> }
>>
>> Truncated output:
>> fatal error: error in backend: Empty type name for BTF_TYPE_ID_REMOTE 
>> reloc
>> PLEASE submit a bug report to 
>> https://bugs.llvm.org/   
>> and include the
>> crash backtrace, preprocessed source, and associated run script.
>> Stack dump:
>> 0.    Program arguments: clang-12 -target bpf -O2 -g -Wall -Werror
>> -mlittle-endian -c internal/btf/testdata/relocs.c -o
>> internal/btf/testdata/relocs-el.elf
>> 1.    <eof> parser at end of file
>> 2.    Per-function optimization
>> 3.    Running pass 'BPF Preserve Debuginfo Type' on function '@type_ids'
>> ...
>> clang: error: clang frontend command failed with exit code 70 (use -v
>> to see invocation)
>> Ubuntu clang version
>> 12.0.0-++20210126113614+510b3d4b3e02-1~exp1~20210126104320.178
>> Target: bpf
>>
>> "volatile" has the same problem. Interestingly, the same code works
>> for bpf_core_type_id_local. Is this expected?
> 
> First, bpf_core_type_id_local() works as compiler did not check type 
> name. for bpf_core_type_id_local(), there is no relocation, libbpf
> may need to adjust type id if it tries to do btf dedup, merging, etc.
> 
> Second, the above bpf_core_type_id_kernel() failed due to
> "const" (or "volatile") modifier. bpf_core_type_id_kernel()
> requires a type name as relocation will be performed.
> In the current implementation, the btf type is
>     const -> struct s
> and there is no name for "const", that is why compiler issues
> an explicit fatal error:
>      fatal error: error in backend: Empty type name for 
> BTF_TYPE_ID_REMOTE reloc
> 
> To fix the issue, just do not use any modifier,
>    bpf_core_type_id_kernel(struct s)
> should work fine.
> 
> I think in the case, it would be good if the compiler tries
> to peel off modifiers and find the ultimate type name
> instead of fatal error. I will put a patch on this.

Lorenz, the issue has been fixed by llvm patch
https://reviews.llvm.org/D97986. It is in llvm13 trunk now.
I have also requested the fix to backport to 12.0.1 release.
Thanks!

> 
> Thanks for reporting!
> 
>>
>> Best
>> Lorenz
>>

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

* Re: bpf_core_type_id_kernel with qualifier aborts clang compilation
  2021-03-05 21:36   ` Yonghong Song
@ 2021-03-08  9:33     ` Lorenz Bauer
  0 siblings, 0 replies; 4+ messages in thread
From: Lorenz Bauer @ 2021-03-08  9:33 UTC (permalink / raw)
  To: Yonghong Song; +Cc: Andrii Nakryiko, bpf

On Fri, 5 Mar 2021 at 21:36, Yonghong Song <yhs@fb.com> wrote:
>
> Lorenz, the issue has been fixed by llvm patch
> https://reviews.llvm.org/D97986. It is in llvm13 trunk now.
> I have also requested the fix to backport to 12.0.1 release.
> Thanks!
>

Thanks again for the quick fix :)

-- 
Lorenz Bauer  |  Systems Engineer
6th Floor, County Hall/The Riverside Building, SE1 7PB, UK

www.cloudflare.com

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

end of thread, other threads:[~2021-03-08  9:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-04 11:25 bpf_core_type_id_kernel with qualifier aborts clang compilation Lorenz Bauer
2021-03-04 16:41 ` Yonghong Song
2021-03-05 21:36   ` Yonghong Song
2021-03-08  9:33     ` Lorenz Bauer

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).