BPF List
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Lorenz Bauer <lmb@cloudflare.com>, bpf <bpf@vger.kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>
Subject: Re: Enum relocations against zero values
Date: Fri, 26 Feb 2021 10:08:23 -0800	[thread overview]
Message-ID: <05c0e4ff-3d93-00c8-b81b-9758c90deca8@fb.com> (raw)
In-Reply-To: <CACAyw9-XZ4XqNP1MZxC1i7+zntVAivopkgRgc4yXaNtD8QcADw@mail.gmail.com>



On 2/26/21 9:47 AM, Lorenz Bauer wrote:
> Hi Andrii and Yonghong,
> 
> I'm playing around with enum CO-RE relocations, and hit the following snag:
> 
>      enum e { TWO };
>      bpf_core_enum_value_exists(enum e, TWO);
> 
> Compiling this with clang-12
> (12.0.0-++20210225092616+e0e6b1e39e7e-1~exp1~20210225083321.50) gives
> me the following:
> 
> internal/btf/testdata/relocs.c:66:2: error:
> __builtin_preserve_enum_value argument 1 invalid
>          enum_value_exists(enum e, TWO);
>          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> internal/btf/testdata/relocs.c:53:8: note: expanded from macro
> 'enum_value_exists'
>                  if (!bpf_core_enum_value_exists(t, v)) { \
>                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> internal/btf/testdata/bpf_core_read.h:168:32: note: expanded from
> macro 'bpf_core_enum_value_exists'
>          __builtin_preserve_enum_value(*(typeof(enum_type)
> *)enum_value, BPF_ENUMVAL_EXISTS)
>                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Andrii can comment on MACRO failures.

> 
> Changing the definition of the enum to
> 
>      enum e { TWO = 1 }
> 
> compiles successfully. I get the same result for any enum value that
> is zero. Is this expected?

IIRC, libbpf will try to do relocation against vmlinux BTF.
So here, "enum e" probably does not exist in vmlinux BTF, so
the builtin will return 0. You can try some enum type
existing in vmlinux BTF to see what happens.

> 
> Best
> Lorenz
> 

  reply	other threads:[~2021-02-26 18:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-26 17:47 Enum relocations against zero values Lorenz Bauer
2021-02-26 18:08 ` Yonghong Song [this message]
2021-02-26 20:43   ` Andrii Nakryiko
2021-02-27  3:31     ` Yonghong Song
2021-03-02  4:19       ` Yonghong Song
2021-03-02  5:08         ` Andrii Nakryiko
2021-03-02  9:51         ` Lorenz Bauer

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=05c0e4ff-3d93-00c8-b81b-9758c90deca8@fb.com \
    --to=yhs@fb.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=lmb@cloudflare.com \
    /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