All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Shuyi Cheng <chengshuyi@linux.alibaba.com>
Cc: bpf <bpf@vger.kernel.org>, Martin Lau <kafai@fb.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>
Subject: Re: How to avoid compilation errors like "error: no member named xxx in strut xxx"?
Date: Tue, 15 Jun 2021 23:02:30 -0700	[thread overview]
Message-ID: <CAEf4Bza2ytug5PMzTcXZjggZU-Zo63XJZzmw0ZoLHJ3-erJkpg@mail.gmail.com> (raw)
In-Reply-To: <756efe9a-a237-e5d1-17fc-47936e76dacc@linux.alibaba.com>

On Tue, Jun 15, 2021 at 9:06 PM Shuyi Cheng
<chengshuyi@linux.alibaba.com> wrote:
>
> I am trying to write a bpf program that supports multiple linux kernel
> versions. However, there are some differences in the definition of
> struct net in these multiple kernel versions.
>
> Therefore, when we include a certain kernel version of vmlinux.h, the
> compilation error "error: no member named'proc_inum' in strut net" will
> appear.
>
> However, when we include another kernel version of vmlinux.h, the
> compilation will appear "error: no member named'ns.inum' in strut net".
>
> Anakryiko mentioned in the issue of libbpf/libbpf-bootstrap: vmlinux.h
> is just a convenient way to have most of kernel types defined for you,
> so that you don't have to re-define them manually. Link here: https:
> //github.com/libbpf/libbpf-bootstrap/issues/31#issuecomment-861035643
>
> But struct net is a very huge structure, and it may be very difficult to

You don't need to declare the entire struct, it's enough to declare
only fields that you need and use.

If the type has incompatible changes between kernel versions (e.g., if
some field changed it's type), you can use my_type___suffix approach,
see [0] and struct kernfs_iattrs___old example. Let me know if you
need more concrete example (but then also provide more concrete
explanation of what you actually need).

  [0] https://nakryiko.com/posts/bcc-to-libbpf-howto-guide/#dealing-with-compile-time-if-s-in-bcc

> add it manually. So, how can we avoid compilation errors like "error: no
> member named'xxx' in xxx"

  reply	other threads:[~2021-06-16  6:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-16  4:06 How to avoid compilation errors like "error: no member named xxx in strut xxx"? Shuyi Cheng
2021-06-16  6:02 ` Andrii Nakryiko [this message]
2021-06-16  6:57   ` Shuyi Cheng

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=CAEf4Bza2ytug5PMzTcXZjggZU-Zo63XJZzmw0ZoLHJ3-erJkpg@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chengshuyi@linux.alibaba.com \
    --cc=kafai@fb.com \
    --cc=songliubraving@fb.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.