public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: Alan Maguire <alan.maguire@oracle.com>,
	yhs@fb.com, ast@kernel.org, andrii@kernel.org
Cc: martin.lau@linux.dev, song@kernel.org, john.fastabend@gmail.com,
	kpsingh@kernel.org, sdf@google.com, haoluo@google.com,
	jolsa@kernel.org, mykolal@fb.com, bpf@vger.kernel.org,
	Colm Harrington <colm.harrington@oracle.com>
Subject: Re: [PATCH v2 bpf] selftests/bpf: fix static assert compilation issue for test_cls_*.c
Date: Wed, 2 Aug 2023 07:07:50 -0700	[thread overview]
Message-ID: <ae5ef31e-5ab2-4f92-a0a6-6ca0628f2556@linux.dev> (raw)
In-Reply-To: <20230802073906.3197480-1-alan.maguire@oracle.com>



On 8/2/23 12:39 AM, Alan Maguire wrote:
> commit bdeeed3498c7 ("libbpf: fix offsetof() and container_of() to work with CO-RE")
> 
> ...was backported to stable trees such as 5.15. The problem is that with older
> LLVM/clang (14/15) - which is often used for older kernels - we see compilation
> failures in BPF selftests now:
> 
> In file included from progs/test_cls_redirect_subprogs.c:2:
> progs/test_cls_redirect.c:90:2: error: static assertion expression is not an integral constant expression
>          sizeof(flow_ports_t) !=
>          ^~~~~~~~~~~~~~~~~~~~~~~
> progs/test_cls_redirect.c:91:3: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
>                  offsetofend(struct bpf_sock_tuple, ipv4.dport) -
>                  ^
> progs/test_cls_redirect.c:32:3: note: expanded from macro 'offsetofend'
>          (offsetof(TYPE, MEMBER) + sizeof((((TYPE *)0)->MEMBER)))
>           ^
> tools/testing/selftests/bpf/tools/include/bpf/bpf_helpers.h:86:33: note: expanded from macro 'offsetof'
>                                   ^
> In file included from progs/test_cls_redirect_subprogs.c:2:
> progs/test_cls_redirect.c:95:2: error: static assertion expression is not an integral constant expression
>          sizeof(flow_ports_t) !=
>          ^~~~~~~~~~~~~~~~~~~~~~~
> progs/test_cls_redirect.c:96:3: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
>                  offsetofend(struct bpf_sock_tuple, ipv6.dport) -
>                  ^
> progs/test_cls_redirect.c:32:3: note: expanded from macro 'offsetofend'
>          (offsetof(TYPE, MEMBER) + sizeof((((TYPE *)0)->MEMBER)))
>           ^
> tools/testing/selftests/bpf/tools/include/bpf/bpf_helpers.h:86:33: note: expanded from macro 'offsetof'
>                                   ^
> 2 errors generated.
> make: *** [Makefile:594: tools/testing/selftests/bpf/test_cls_redirect_subprogs.bpf.o] Error 1
> 
> The problem is the new offsetof() does not play nice with static asserts.
> Given that the context is a static assert (and CO-RE relocation is not
> needed at compile time), offsetof() usage can be replaced by restoring
> the original offsetof() definition as __builtin_offsetof().
> 
> Fixes: bdeeed3498c7 ("libbpf: fix offsetof() and container_of() to work with CO-RE")
> Reported-by: Colm Harrington <colm.harrington@oracle.com>
> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>

Acked-by: Yonghong Song <yonghong.song@linux.dev>

  parent reply	other threads:[~2023-08-02 14:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-02  7:39 [PATCH v2 bpf] selftests/bpf: fix static assert compilation issue for test_cls_*.c Alan Maguire
2023-08-02 12:15 ` Yipeng Zou
2023-08-02 14:07 ` Yonghong Song [this message]
2023-08-02 21:20 ` patchwork-bot+netdevbpf

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=ae5ef31e-5ab2-4f92-a0a6-6ca0628f2556@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=colm.harrington@oracle.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=yhs@fb.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