bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Y Song <ys114321@gmail.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
	Alexei Starovoitov <ast@kernel.org>,
	Clark Williams <williams@redhat.com>, bpf <bpf@vger.kernel.org>,
	netdev <netdev@vger.kernel.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Andrii Nakryiko <andriin@fb.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>
Subject: Re: [PATCH 1/2] libbpf: Fix endianness macro usage for some compilers
Date: Fri, 19 Jul 2019 09:25:07 -0700	[thread overview]
Message-ID: <CAH3MdRXDz+Yn104Y3U0u-q_zW0cwSaH0QAPA8aWK9hpBc4hukw@mail.gmail.com> (raw)
In-Reply-To: <20190719143407.20847-2-acme@kernel.org>

On Fri, Jul 19, 2019 at 7:35 AM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> Using endian.h and its endianness macros makes this code build in a
> wider range of compilers, as some don't have those macros
> (__BYTE_ORDER__, __ORDER_LITTLE_ENDIAN__, __ORDER_BIG_ENDIAN__),
> so use instead endian.h's macros (__BYTE_ORDER, __LITTLE_ENDIAN,
> __BIG_ENDIAN) which makes this code even shorter :-)

gcc 4.6.0 starts to support __BYTE_ORDER__, __ORDER_LITTLE_ENDIAN__, etc.
I guess those platforms with failing compilation have gcc < 4.6.0.
Agree that for libbpf, which will be used outside kernel bpf selftest should
try to compile with lower versions of gcc.

>
> Acked-by: Andrii Nakryiko <andriin@fb.com>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Fixes: 12ef5634a855 ("libbpf: simplify endianness check")
> Fixes: e6c64855fd7a ("libbpf: add btf__parse_elf API to load .BTF and .BTF.ext")
> Link: https://lkml.kernel.org/n/tip-eep5n8vgwcdphw3uc058k03u@git.kernel.org
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
>  tools/lib/bpf/btf.c    | 5 +++--
>  tools/lib/bpf/libbpf.c | 5 +++--
>  2 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> index 467224feb43b..d821107f55f9 100644
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -1,6 +1,7 @@
>  // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
>  /* Copyright (c) 2018 Facebook */
>
> +#include <endian.h>
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> @@ -419,9 +420,9 @@ struct btf *btf__new(__u8 *data, __u32 size)
>
>  static bool btf_check_endianness(const GElf_Ehdr *ehdr)
>  {
> -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
>         return ehdr->e_ident[EI_DATA] == ELFDATA2LSB;
> -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
> +#elif __BYTE_ORDER == __BIG_ENDIAN
>         return ehdr->e_ident[EI_DATA] == ELFDATA2MSB;
>  #else
>  # error "Unrecognized __BYTE_ORDER__"
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 794dd5064ae8..b1dec5b1de54 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -20,6 +20,7 @@
>  #include <inttypes.h>
>  #include <string.h>
>  #include <unistd.h>
> +#include <endian.h>
>  #include <fcntl.h>
>  #include <errno.h>
>  #include <asm/unistd.h>
> @@ -612,10 +613,10 @@ static int bpf_object__elf_init(struct bpf_object *obj)
>
>  static int bpf_object__check_endianness(struct bpf_object *obj)
>  {
> -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
> +#if __BYTE_ORDER == __LITTLE_ENDIAN
>         if (obj->efile.ehdr.e_ident[EI_DATA] == ELFDATA2LSB)
>                 return 0;
> -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
> +#elif __BYTE_ORDER == __BIG_ENDIAN
>         if (obj->efile.ehdr.e_ident[EI_DATA] == ELFDATA2MSB)
>                 return 0;
>  #else
> --
> 2.21.0
>

  reply	other threads:[~2019-07-19 16:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-19 14:34 [GIT PULL 0/2] libbpf build fixes Arnaldo Carvalho de Melo
2019-07-19 14:34 ` [PATCH 1/2] libbpf: Fix endianness macro usage for some compilers Arnaldo Carvalho de Melo
2019-07-19 16:25   ` Y Song [this message]
2019-07-19 18:30     ` Arnaldo Carvalho de Melo
2019-07-19 14:34 ` [PATCH 2/2] libbpf: Avoid designated initializers for unnamed union members Arnaldo Carvalho de Melo
2019-07-19 17:28   ` Andrii Nakryiko
2019-07-22 14:23 ` [GIT PULL 0/2] libbpf build fixes Daniel Borkmann

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=CAH3MdRXDz+Yn104Y3U0u-q_zW0cwSaH0QAPA8aWK9hpBc4hukw@mail.gmail.com \
    --to=ys114321@gmail.com \
    --cc=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jolsa@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=williams@redhat.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;
as well as URLs for NNTP newsgroup(s).