diff mbox series

[bpf-next] bpf, mips: Fix build errors about __NR_bpf undeclared

Message ID 1637744426-22044-1-git-send-email-yangtiezhu@loongson.cn (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] bpf, mips: Fix build errors about __NR_bpf undeclared | expand

Checks

Context Check Description
bpf/vmtest-bpf-next success VM_Test
bpf/vmtest-bpf-next-PR success PR summary
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 5 maintainers not CCed: kafai@fb.com songliubraving@fb.com john.fastabend@gmail.com kpsingh@kernel.org yhs@fb.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 40 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Tiezhu Yang Nov. 24, 2021, 9 a.m. UTC
Add the __NR_bpf definitions to fix the following build errors for mips.

 $ cd tools/bpf/bpftool
 $ make
 [...]
 bpf.c:54:4: error: #error __NR_bpf not defined. libbpf does not support your arch.
  #  error __NR_bpf not defined. libbpf does not support your arch.
     ^~~~~
 bpf.c: In function ‘sys_bpf’:
 bpf.c:66:17: error: ‘__NR_bpf’ undeclared (first use in this function); did you mean ‘__NR_brk’?
   return syscall(__NR_bpf, cmd, attr, size);
                  ^~~~~~~~
                  __NR_brk
 [...]
 In file included from gen_loader.c:15:0:
 skel_internal.h: In function ‘skel_sys_bpf’:
 skel_internal.h:53:17: error: ‘__NR_bpf’ undeclared (first use in this function); did you mean ‘__NR_brk’?
   return syscall(__NR_bpf, cmd, attr, size);
                  ^~~~~~~~
                  __NR_brk

We can see the following generated definitions:

 $ grep -r "#define __NR_bpf" arch/mips
 arch/mips/include/generated/uapi/asm/unistd_o32.h:#define __NR_bpf (__NR_Linux + 355)
 arch/mips/include/generated/uapi/asm/unistd_n64.h:#define __NR_bpf (__NR_Linux + 315)
 arch/mips/include/generated/uapi/asm/unistd_n32.h:#define __NR_bpf (__NR_Linux + 319)

So use the GCC pre-defined macro _ABIO32, _ABIN32 and _ABI64 [1] to define
the corresponding __NR_bpf.

This patch is similar with commit bad1926dd2f6 ("bpf, s390: fix build for
libbpf and selftest suite").

[1] https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/mips/mips.h#l549

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 tools/build/feature/test-bpf.c |  6 ++++++
 tools/lib/bpf/bpf.c            |  6 ++++++
 tools/lib/bpf/skel_internal.h  | 10 ++++++++++
 3 files changed, 22 insertions(+)

Comments

Andrii Nakryiko Nov. 24, 2021, 8:50 p.m. UTC | #1
On Wed, Nov 24, 2021 at 1:00 AM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>
> Add the __NR_bpf definitions to fix the following build errors for mips.
>
>  $ cd tools/bpf/bpftool
>  $ make
>  [...]
>  bpf.c:54:4: error: #error __NR_bpf not defined. libbpf does not support your arch.
>   #  error __NR_bpf not defined. libbpf does not support your arch.
>      ^~~~~
>  bpf.c: In function ‘sys_bpf’:
>  bpf.c:66:17: error: ‘__NR_bpf’ undeclared (first use in this function); did you mean ‘__NR_brk’?
>    return syscall(__NR_bpf, cmd, attr, size);
>                   ^~~~~~~~
>                   __NR_brk
>  [...]
>  In file included from gen_loader.c:15:0:
>  skel_internal.h: In function ‘skel_sys_bpf’:
>  skel_internal.h:53:17: error: ‘__NR_bpf’ undeclared (first use in this function); did you mean ‘__NR_brk’?
>    return syscall(__NR_bpf, cmd, attr, size);
>                   ^~~~~~~~
>                   __NR_brk
>
> We can see the following generated definitions:
>
>  $ grep -r "#define __NR_bpf" arch/mips
>  arch/mips/include/generated/uapi/asm/unistd_o32.h:#define __NR_bpf (__NR_Linux + 355)
>  arch/mips/include/generated/uapi/asm/unistd_n64.h:#define __NR_bpf (__NR_Linux + 315)
>  arch/mips/include/generated/uapi/asm/unistd_n32.h:#define __NR_bpf (__NR_Linux + 319)
>
> So use the GCC pre-defined macro _ABIO32, _ABIN32 and _ABI64 [1] to define
> the corresponding __NR_bpf.
>
> This patch is similar with commit bad1926dd2f6 ("bpf, s390: fix build for
> libbpf and selftest suite").
>
> [1] https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/mips/mips.h#l549
>
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
>  tools/build/feature/test-bpf.c |  6 ++++++
>  tools/lib/bpf/bpf.c            |  6 ++++++
>  tools/lib/bpf/skel_internal.h  | 10 ++++++++++
>  3 files changed, 22 insertions(+)
>
> diff --git a/tools/build/feature/test-bpf.c b/tools/build/feature/test-bpf.c
> index 82070ea..ebc7a2a 100644
> --- a/tools/build/feature/test-bpf.c
> +++ b/tools/build/feature/test-bpf.c
> @@ -14,6 +14,12 @@
>  #  define __NR_bpf 349
>  # elif defined(__s390__)
>  #  define __NR_bpf 351
> +# elif defined(__mips__) && defined(_ABIO32)
> +#  define __NR_bpf (__NR_Linux + 355)
> +# elif defined(__mips__) && defined(_ABIN32)
> +#  define __NR_bpf (__NR_Linux + 319)
> +# elif defined(__mips__) && defined(_ABI64)
> +#  define __NR_bpf (__NR_Linux + 315)

Is it possible to use a final number without __NR_Linux? All the other
cases have final numbers, no relative numbers

>  # else
>  #  error __NR_bpf not defined. libbpf does not support your arch.
>  # endif
> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> index 94560ba..60422404 100644
> --- a/tools/lib/bpf/bpf.c
> +++ b/tools/lib/bpf/bpf.c
> @@ -50,6 +50,12 @@
>  #  define __NR_bpf 351
>  # elif defined(__arc__)
>  #  define __NR_bpf 280
> +# elif defined(__mips__) && defined(_ABIO32)
> +#  define __NR_bpf (__NR_Linux + 355)
> +# elif defined(__mips__) && defined(_ABIN32)
> +#  define __NR_bpf (__NR_Linux + 319)
> +# elif defined(__mips__) && defined(_ABI64)
> +#  define __NR_bpf (__NR_Linux + 315)
>  # else
>  #  error __NR_bpf not defined. libbpf does not support your arch.
>  # endif
> diff --git a/tools/lib/bpf/skel_internal.h b/tools/lib/bpf/skel_internal.h
> index 9cf6670..6ff4939 100644
> --- a/tools/lib/bpf/skel_internal.h
> +++ b/tools/lib/bpf/skel_internal.h
> @@ -7,6 +7,16 @@
>  #include <sys/syscall.h>
>  #include <sys/mman.h>
>
> +#ifndef __NR_bpf
> +# if defined(__mips__) && defined(_ABIO32)
> +#  define __NR_bpf (__NR_Linux + 355)
> +# elif defined(__mips__) && defined(_ABIN32)
> +#  define __NR_bpf (__NR_Linux + 319)
> +# elif defined(__mips__) && defined(_ABI64)
> +#  define __NR_bpf (__NR_Linux + 315)
> +# endif
> +#endif
> +
>  /* This file is a base header for auto-generated *.lskel.h files.
>   * Its contents will change and may become part of auto-generation in the future.
>   *
> --
> 2.1.0
>
diff mbox series

Patch

diff --git a/tools/build/feature/test-bpf.c b/tools/build/feature/test-bpf.c
index 82070ea..ebc7a2a 100644
--- a/tools/build/feature/test-bpf.c
+++ b/tools/build/feature/test-bpf.c
@@ -14,6 +14,12 @@ 
 #  define __NR_bpf 349
 # elif defined(__s390__)
 #  define __NR_bpf 351
+# elif defined(__mips__) && defined(_ABIO32)
+#  define __NR_bpf (__NR_Linux + 355)
+# elif defined(__mips__) && defined(_ABIN32)
+#  define __NR_bpf (__NR_Linux + 319)
+# elif defined(__mips__) && defined(_ABI64)
+#  define __NR_bpf (__NR_Linux + 315)
 # else
 #  error __NR_bpf not defined. libbpf does not support your arch.
 # endif
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 94560ba..60422404 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -50,6 +50,12 @@ 
 #  define __NR_bpf 351
 # elif defined(__arc__)
 #  define __NR_bpf 280
+# elif defined(__mips__) && defined(_ABIO32)
+#  define __NR_bpf (__NR_Linux + 355)
+# elif defined(__mips__) && defined(_ABIN32)
+#  define __NR_bpf (__NR_Linux + 319)
+# elif defined(__mips__) && defined(_ABI64)
+#  define __NR_bpf (__NR_Linux + 315)
 # else
 #  error __NR_bpf not defined. libbpf does not support your arch.
 # endif
diff --git a/tools/lib/bpf/skel_internal.h b/tools/lib/bpf/skel_internal.h
index 9cf6670..6ff4939 100644
--- a/tools/lib/bpf/skel_internal.h
+++ b/tools/lib/bpf/skel_internal.h
@@ -7,6 +7,16 @@ 
 #include <sys/syscall.h>
 #include <sys/mman.h>
 
+#ifndef __NR_bpf
+# if defined(__mips__) && defined(_ABIO32)
+#  define __NR_bpf (__NR_Linux + 355)
+# elif defined(__mips__) && defined(_ABIN32)
+#  define __NR_bpf (__NR_Linux + 319)
+# elif defined(__mips__) && defined(_ABI64)
+#  define __NR_bpf (__NR_Linux + 315)
+# endif
+#endif
+
 /* This file is a base header for auto-generated *.lskel.h files.
  * Its contents will change and may become part of auto-generation in the future.
  *