Re: [PATCH v2 -next] selftests/bpf: Use ARRAY_SIZE for array length

2024-09-30 Thread Tony Ambardar
On Sun, Sep 29, 2024 at 05:28:11PM +0800, Jiapeng Chong wrote:
> Use of macro ARRAY_SIZE to calculate array size minimizes
> the redundant code and improves code reusability.
> 
> ./tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c:98:34-35: WARNING: 
> Use ARRAY_SIZE.
> ./tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c:93:29-30: WARNING: 
> Use ARRAY_SIZE.
> ./tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c:101:34-35: WARNING: 
> Use ARRAY_SIZE.
> 
> Reported-by: Abaci Robot 
> Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=11167
> Signed-off-by: Jiapeng Chong 
> ---
> Changes in v2:
>   -Modify the header file "kselftest.h" to "linux/kernel.h".
> 
>  tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c | 7 ---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c 
> b/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c
> index a18d3680fb16..7534014279ca 100644
> --- a/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c
> +++ b/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c
> @@ -7,6 +7,7 @@
>  #include 
>  #include 
>  #include 
> +#include 

Hi Jiapeng,

I don't believe adding this header is needed, since ARRAY_SIZE is defined
in bpf_utils.h and already pulled in by test_progs.h below. Maybe try
without "#include  to check?

Take care,
Tony

>  
>  #include "test_progs.h"
>  #include "test_btf.h"
> @@ -90,15 +91,15 @@ static void test_bad_local_id(void)
>   attr.prog_type = BPF_TRACE_RAW_TP;
>   attr.license = (__u64)"GPL";
>   attr.insns = (__u64)&insns;
> - attr.insn_cnt = sizeof(insns) / sizeof(*insns);
> + attr.insn_cnt = ARRAY_SIZE(insns);
>   attr.log_buf = (__u64)log;
>   attr.log_size = sizeof(log);
>   attr.log_level = log_level;
>   attr.func_info = (__u64)funcs;
> - attr.func_info_cnt = sizeof(funcs) / sizeof(*funcs);
> + attr.func_info_cnt = ARRAY_SIZE(funcs);
>   attr.func_info_rec_size = sizeof(*funcs);
>   attr.core_relos = (__u64)relos;
> - attr.core_relo_cnt = sizeof(relos) / sizeof(*relos);
> + attr.core_relo_cnt = ARRAY_SIZE(relos);
>   attr.core_relo_rec_size = sizeof(*relos);
>   prog_fd = sys_bpf_prog_load(&attr, sizeof(attr), 1);
>   saved_errno = errno;
> -- 
> 2.32.0.3.g01195cf9f
> 



Re: [PATCH v3] powerpc: fix EDEADLOCK redefinition error in uapi/asm/errno.h

2021-04-16 Thread Tony Ambardar
On Fri, 16 Apr 2021 at 03:41, Michael Ellerman  wrote:
>
> Tony Ambardar  writes:
> > Hello Michael,
> >
> > The latest version of this patch addressed all feedback I'm aware of
> > when submitted last September, and I've seen no further comments from
> > reviewers since then.
> >
> > Could you please let me know where this stands and if anything further
> > is needed?
>
> Sorry, it's still sitting in my inbox :/
>
> I was going to reply to suggest we split the tools change out. The
> headers under tools are usually updated by another maintainer, I think
> it might even be scripted.
>
> Anyway I've applied your patch and done that (dropped the change to
> tools/.../errno.h), which should also mean the stable backport is more
> likely to work automatically.
>
> It will hit mainline in v5.13-rc1 and then be backported to the stable
> trees.
>
> I don't think you actually need the tools version of the header updated
> to fix your bug? In which case we can probably just wait for it to be
> updated automatically when the tools headers are sync'ed with the kernel
> versions.
>
> cheers

I appreciate the follow up. My original bug was indeed with the tools
header but is being patched locally, so waiting for those headers to
sync with the kernel versions is fine if it simplifies things overall.

Thanks,
Tony


Re: [PATCH v3] powerpc: fix EDEADLOCK redefinition error in uapi/asm/errno.h

2021-04-15 Thread Tony Ambardar
Hello Michael,

The latest version of this patch addressed all feedback I'm aware of
when submitted last September, and I've seen no further comments from
reviewers since then.

Could you please let me know where this stands and if anything further
is needed?

Kind regards,
Tony

On Thu, 17 Sept 2020 at 06:54, Tony Ambardar  wrote:
>
> A few archs like powerpc have different errno.h values for macros
> EDEADLOCK and EDEADLK. In code including both libc and linux versions of
> errno.h, this can result in multiple definitions of EDEADLOCK in the
> include chain. Definitions to the same value (e.g. seen with mips) do
> not raise warnings, but on powerpc there are redefinitions changing the
> value, which raise warnings and errors (if using "-Werror").
>
> Guard against these redefinitions to avoid build errors like the following,
> first seen cross-compiling libbpf v5.8.9 for powerpc using GCC 8.4.0 with
> musl 1.1.24:
>
>   In file included from ../../arch/powerpc/include/uapi/asm/errno.h:5,
>from ../../include/linux/err.h:8,
>from libbpf.c:29:
>   ../../include/uapi/asm-generic/errno.h:40: error: "EDEADLOCK" redefined 
> [-Werror]
>#define EDEADLOCK EDEADLK
>
>   In file included from 
> toolchain-powerpc_8540_gcc-8.4.0_musl/include/errno.h:10,
>from libbpf.c:26:
>   toolchain-powerpc_8540_gcc-8.4.0_musl/include/bits/errno.h:58: note: this 
> is the location of the previous definition
>#define EDEADLOCK   58
>
>   cc1: all warnings being treated as errors
>
> CC: Stable 
> Reported-by: Rosen Penev 
> Signed-off-by: Tony Ambardar 
> ---
> v1 -> v2:
>  * clean up commit description formatting
>
> v2 -> v3: (per Michael Ellerman)
>  * drop indeterminate 'Fixes' tags, request stable backports instead
> ---
>  arch/powerpc/include/uapi/asm/errno.h   | 1 +
>  tools/arch/powerpc/include/uapi/asm/errno.h | 1 +
>  2 files changed, 2 insertions(+)
>
> diff --git a/arch/powerpc/include/uapi/asm/errno.h 
> b/arch/powerpc/include/uapi/asm/errno.h
> index cc79856896a1..4ba87de32be0 100644
> --- a/arch/powerpc/include/uapi/asm/errno.h
> +++ b/arch/powerpc/include/uapi/asm/errno.h
> @@ -2,6 +2,7 @@
>  #ifndef _ASM_POWERPC_ERRNO_H
>  #define _ASM_POWERPC_ERRNO_H
>
> +#undef EDEADLOCK
>  #include 
>
>  #undef EDEADLOCK
> diff --git a/tools/arch/powerpc/include/uapi/asm/errno.h 
> b/tools/arch/powerpc/include/uapi/asm/errno.h
> index cc79856896a1..4ba87de32be0 100644
> --- a/tools/arch/powerpc/include/uapi/asm/errno.h
> +++ b/tools/arch/powerpc/include/uapi/asm/errno.h
> @@ -2,6 +2,7 @@
>  #ifndef _ASM_POWERPC_ERRNO_H
>  #define _ASM_POWERPC_ERRNO_H
>
> +#undef EDEADLOCK
>  #include 
>
>  #undef EDEADLOCK
> --
> 2.25.1
>


Re: [PATCH 5.8 35/99] tools/libbpf: Avoid counting local symbols in ABI check

2020-09-29 Thread Tony Ambardar
[adding Michael Ellerman, linux-ppc maintainer]

Hello Justin,

On Tue, 29 Sep 2020 at 14:54, Justin Forbes  wrote:
>
> On Tue, Sep 29, 2020 at 6:53 AM Greg Kroah-Hartman
>  wrote:
> >
> > From: Tony Ambardar 
> >
> > [ Upstream commit 746f534a4809e07f427f7d13d10f3a6a9641e5c3 ]
> >
> > Encountered the following failure building libbpf from kernel 5.8.5 sources
> > with GCC 8.4.0 and binutils 2.34: (long paths shortened)
> >
> >   Warning: Num of global symbols in sharedobjs/libbpf-in.o (234) does NOT
> >   match with num of versioned symbols in libbpf.so (236). Please make sure
> >   all LIBBPF_API symbols are versioned in libbpf.map.
> > #  --- libbpf_global_syms.tmp2020-09-02 07:30:58.920084380 +
> > #  +++ libbpf_versioned_syms.tmp 2020-09-02 07:30:58.924084388 +
> >   @@ -1,3 +1,5 @@
> >   +_fini
> >   +_init
> >bpf_btf_get_fd_by_id
> >bpf_btf_get_next_id
> >bpf_create_map
> >   make[4]: *** [Makefile:210: check_abi] Error 1
> >
> > Investigation shows _fini and _init are actually local symbols counted
> > amongst global ones:
> >
> >   $ readelf --dyn-syms --wide libbpf.so|head -10
> >
> >   Symbol table '.dynsym' contains 343 entries:
> >  Num:Value  Size TypeBind   Vis  Ndx Name
> >0:  0 NOTYPE  LOCAL  DEFAULT  UND
> >1: 4098 0 SECTION LOCAL  DEFAULT   11
> >2: 4098 8 FUNCLOCAL  DEFAULT   11 _init@@LIBBPF_0.0.1
> >3: 00023040 8 FUNCLOCAL  DEFAULT   14 _fini@@LIBBPF_0.0.1
> >4:  0 OBJECT  GLOBAL DEFAULT  ABS LIBBPF_0.0.4
> >5:  0 OBJECT  GLOBAL DEFAULT  ABS LIBBPF_0.0.1
> >6: ffa4 8 FUNCGLOBAL DEFAULT   12 
> > bpf_object__find_map_by_offset@@LIBBPF_0.0.1
> >
> > A previous commit filtered global symbols in sharedobjs/libbpf-in.o. Do the
> > same with the libbpf.so DSO for consistent comparison.
> >
> > Fixes: 306b267cb3c4 ("libbpf: Verify versioned symbols")
> > Signed-off-by: Tony Ambardar 
> > Signed-off-by: Alexei Starovoitov 
> > Acked-by: Andrii Nakryiko 
> > Link: 
> > https://lore.kernel.org/bpf/20200905214831.1565465-1-tony.ambar...@gmail.com
> > Signed-off-by: Sasha Levin 
>
> This seems to work everywhere else, but breaks PPC64LE.
>

I also ran into a PPC build error while working on some bpf problems,
but it seemed
like a pre-existing PPC issue. I did submit an upstream fix, which is
marked for stable
and being reviewed by Michael. See here for discussion and the patch:
https://lkml.org/lkml/2020/9/17/668.

Is that the same problem you encountered? Does that patch address your issue?

Thanks,
Tony

> Justin
>
> > ---
> >  tools/lib/bpf/Makefile |2 ++
> >  1 file changed, 2 insertions(+)
> >
> > --- a/tools/lib/bpf/Makefile
> > +++ b/tools/lib/bpf/Makefile
> > @@ -152,6 +152,7 @@ GLOBAL_SYM_COUNT = $(shell readelf -s --
> >awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print 
> > $$NF}' | \
> >sort -u | wc -l)
> >  VERSIONED_SYM_COUNT = $(shell readelf --dyn-syms --wide $(OUTPUT)libbpf.so 
> > | \
> > + awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print 
> > $$NF}' | \
> >   grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | sort 
> > -u | wc -l)
> >
> >  CMD_TARGETS = $(LIB_TARGET) $(PC_FILE)
> > @@ -219,6 +220,7 @@ check_abi: $(OUTPUT)libbpf.so
> > awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}'|  \
> > sort -u > $(OUTPUT)libbpf_global_syms.tmp;   \
> > readelf --dyn-syms --wide $(OUTPUT)libbpf.so |   \
> > +   awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}'|  \
> > grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | \
> > sort -u > $(OUTPUT)libbpf_versioned_syms.tmp;\
> > diff -u $(OUTPUT)libbpf_global_syms.tmp  \
> >
> >


Re: [PATCH v2] powerpc: fix EDEADLOCK redefinition error in uapi/asm/errno.h

2020-09-18 Thread Tony Ambardar
On Thu, 17 Sep 2020 at 07:34, Andreas Schwab  wrote:
>
> On Sep 17 2020, Arnd Bergmann wrote:
>
> > The errno man page says they are supposed to be synonyms,
> > and glibc defines it that way, while musl uses the numbers
> > from the kernel.
>
> glibc also uses whatever the kernel defines.
>
That's right, and from my investigation this isn't a libc issue. The
various libc flavours simply try to follow POSIX and the PPC ABI and
aren't doing anything wrong.

See errno.h for example (https://man7.org/linux/man-pages/man3/errno.3.html):
  EDEADLK: Resource deadlock avoided (POSIX.1-2001).
  EDEADLOCK: On most architectures, a synonym for EDEADLK.  On some
architectures (e.g., Linux MIPS, PowerPC, SPARC), it is a separate
error code "File locking deadlock error".

The root cause is unique to the Linux PPC code in
arch/powerpc/include/uapi/asm/errno.h:
  >/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  >#ifndef _ASM_POWERPC_ERRNO_H
  >#define _ASM_POWERPC_ERRNO_H
  >
  >#include 
  >
  >#undef  EDEADLOCK
  >#define EDEADLOCK   58  /* File locking deadlock error */
  >
  >#endif  /* _ASM_POWERPC_ERRNO_H */

It includes "" to pull in various definitions but
has the side-effect of redefining EDEADLOCK to a non-ABI value which
conflicts with the libc errno.h, as I outline in the patch
description. Other arches which also use different EDEADLOCK and
EDEADLK values (mips,sparc) do not do this. They define EDEADLOCK
*once*, with an ABI-consistent value, and don't have the same issue.

The problem goes back a ways (as Arnd points out), affecting current
stable and all LTS branches, so would be nice to get this sorted out.
I'm certainly interested if there's a better way than proposed in this
patch.

> Andreas.
>
> --
> Andreas Schwab, sch...@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."


Re: [PATCH v2] powerpc: fix EDEADLOCK redefinition error in uapi/asm/errno.h

2020-09-17 Thread Tony Ambardar
On Thu, 17 Sep 2020 at 04:55, Michael Ellerman  wrote:
>
> [ Cc += linux-arch & Arnd ]
>
> Hi Tony,
>
> This looks OK to me, but I'm always a bit nervous about changes in uapi.
> I've Cc'ed linux-arch and Arnd who look after the asm-generic headers,
> which this is slightly related to, just in case.
>
I agree with the caution and would welcome any other insights.

> One minor comment below.
>
> Tony Ambardar  writes:
> > A few archs like powerpc have different errno.h values for macros
> > EDEADLOCK and EDEADLK. In code including both libc and linux versions of
> > errno.h, this can result in multiple definitions of EDEADLOCK in the
> > include chain. Definitions to the same value (e.g. seen with mips) do
> > not raise warnings, but on powerpc there are redefinitions changing the
> > value, which raise warnings and errors (if using "-Werror").
> >
> > Guard against these redefinitions to avoid build errors like the following,
> > first seen cross-compiling libbpf v5.8.9 for powerpc using GCC 8.4.0 with
> > musl 1.1.24:
> >
> >   In file included from ../../arch/powerpc/include/uapi/asm/errno.h:5,
> >from ../../include/linux/err.h:8,
> >from libbpf.c:29:
> >   ../../include/uapi/asm-generic/errno.h:40: error: "EDEADLOCK" redefined 
> > [-Werror]
> >#define EDEADLOCK EDEADLK
> >
> >   In file included from 
> > toolchain-powerpc_8540_gcc-8.4.0_musl/include/errno.h:10,
> >from libbpf.c:26:
> >   toolchain-powerpc_8540_gcc-8.4.0_musl/include/bits/errno.h:58: note: this 
> > is the location of the previous definition
> >#define EDEADLOCK   58
> >
> >   cc1: all warnings being treated as errors
> >
> > Fixes: 95f28190aa01 ("tools include arch: Grab a copy of errno.h for arch's 
> > supported by perf")
> > Fixes: c3617f72036c ("UAPI: (Scripted) Disintegrate 
> > arch/powerpc/include/asm")
>
> I suspect that's not the right commit to tag. It just moved errno.h from
> arch/powerpc/include/asm to arch/powerpc/include/uapi/asm. It's content
> was almost identical, and entirely identical as far as EDEADLOCK was
> concerned.
>
> Prior to that the file lived in asm-powerpc/errno.h, eg:
>
> $ git cat-file -p b8b572e1015f^:include/asm-powerpc/errno.h
>
> Before that it was include/asm-ppc64/errno.h, content still the same.
>
> To go back further we'd have to look at the historical git trees, which
> is probably overkill. I'm pretty sure it's always had this problem.
>
> So we should probably drop the Fixes tags and just Cc: stable, that
> means please backport it as far back as possible.
>
Yes, you're right. Those two commits were simply where I stopped tracing back
the long chain. I'll drop them as you suggest and request a backport instead in
the next version of the patch.

Thanks for your feedback!
> cheers
>
>
> > Reported-by: Rosen Penev 
> > Signed-off-by: Tony Ambardar 
> > ---
> > v1 -> v2:
> >  * clean up commit description formatting
> > ---
> >  arch/powerpc/include/uapi/asm/errno.h   | 1 +
> >  tools/arch/powerpc/include/uapi/asm/errno.h | 1 +
> >  2 files changed, 2 insertions(+)
> >
> > diff --git a/arch/powerpc/include/uapi/asm/errno.h 
> > b/arch/powerpc/include/uapi/asm/errno.h
> > index cc79856896a1..4ba87de32be0 100644
> > --- a/arch/powerpc/include/uapi/asm/errno.h
> > +++ b/arch/powerpc/include/uapi/asm/errno.h
> > @@ -2,6 +2,7 @@
> >  #ifndef _ASM_POWERPC_ERRNO_H
> >  #define _ASM_POWERPC_ERRNO_H
> >
> > +#undef   EDEADLOCK
> >  #include 
> >
> >  #undef   EDEADLOCK
> > diff --git a/tools/arch/powerpc/include/uapi/asm/errno.h 
> > b/tools/arch/powerpc/include/uapi/asm/errno.h
> > index cc79856896a1..4ba87de32be0 100644
> > --- a/tools/arch/powerpc/include/uapi/asm/errno.h
> > +++ b/tools/arch/powerpc/include/uapi/asm/errno.h
> > @@ -2,6 +2,7 @@
> >  #ifndef _ASM_POWERPC_ERRNO_H
> >  #define _ASM_POWERPC_ERRNO_H
> >
> > +#undef   EDEADLOCK
> >  #include 
> >
> >  #undef   EDEADLOCK
> > --
> > 2.25.1


[PATCH v3] powerpc: fix EDEADLOCK redefinition error in uapi/asm/errno.h

2020-09-17 Thread Tony Ambardar
A few archs like powerpc have different errno.h values for macros
EDEADLOCK and EDEADLK. In code including both libc and linux versions of
errno.h, this can result in multiple definitions of EDEADLOCK in the
include chain. Definitions to the same value (e.g. seen with mips) do
not raise warnings, but on powerpc there are redefinitions changing the
value, which raise warnings and errors (if using "-Werror").

Guard against these redefinitions to avoid build errors like the following,
first seen cross-compiling libbpf v5.8.9 for powerpc using GCC 8.4.0 with
musl 1.1.24:

  In file included from ../../arch/powerpc/include/uapi/asm/errno.h:5,
   from ../../include/linux/err.h:8,
   from libbpf.c:29:
  ../../include/uapi/asm-generic/errno.h:40: error: "EDEADLOCK" redefined 
[-Werror]
   #define EDEADLOCK EDEADLK

  In file included from 
toolchain-powerpc_8540_gcc-8.4.0_musl/include/errno.h:10,
   from libbpf.c:26:
  toolchain-powerpc_8540_gcc-8.4.0_musl/include/bits/errno.h:58: note: this is 
the location of the previous definition
   #define EDEADLOCK   58

  cc1: all warnings being treated as errors

CC: Stable 
Reported-by: Rosen Penev 
Signed-off-by: Tony Ambardar 
---
v1 -> v2:
 * clean up commit description formatting

v2 -> v3: (per Michael Ellerman)
 * drop indeterminate 'Fixes' tags, request stable backports instead 
---
 arch/powerpc/include/uapi/asm/errno.h   | 1 +
 tools/arch/powerpc/include/uapi/asm/errno.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/arch/powerpc/include/uapi/asm/errno.h 
b/arch/powerpc/include/uapi/asm/errno.h
index cc79856896a1..4ba87de32be0 100644
--- a/arch/powerpc/include/uapi/asm/errno.h
+++ b/arch/powerpc/include/uapi/asm/errno.h
@@ -2,6 +2,7 @@
 #ifndef _ASM_POWERPC_ERRNO_H
 #define _ASM_POWERPC_ERRNO_H
 
+#undef EDEADLOCK
 #include 
 
 #undef EDEADLOCK
diff --git a/tools/arch/powerpc/include/uapi/asm/errno.h 
b/tools/arch/powerpc/include/uapi/asm/errno.h
index cc79856896a1..4ba87de32be0 100644
--- a/tools/arch/powerpc/include/uapi/asm/errno.h
+++ b/tools/arch/powerpc/include/uapi/asm/errno.h
@@ -2,6 +2,7 @@
 #ifndef _ASM_POWERPC_ERRNO_H
 #define _ASM_POWERPC_ERRNO_H
 
+#undef EDEADLOCK
 #include 
 
 #undef EDEADLOCK
-- 
2.25.1



[PATCH v2] powerpc: fix EDEADLOCK redefinition error in uapi/asm/errno.h

2020-09-16 Thread Tony Ambardar
A few archs like powerpc have different errno.h values for macros
EDEADLOCK and EDEADLK. In code including both libc and linux versions of
errno.h, this can result in multiple definitions of EDEADLOCK in the
include chain. Definitions to the same value (e.g. seen with mips) do
not raise warnings, but on powerpc there are redefinitions changing the
value, which raise warnings and errors (if using "-Werror").

Guard against these redefinitions to avoid build errors like the following,
first seen cross-compiling libbpf v5.8.9 for powerpc using GCC 8.4.0 with
musl 1.1.24:

  In file included from ../../arch/powerpc/include/uapi/asm/errno.h:5,
   from ../../include/linux/err.h:8,
   from libbpf.c:29:
  ../../include/uapi/asm-generic/errno.h:40: error: "EDEADLOCK" redefined 
[-Werror]
   #define EDEADLOCK EDEADLK

  In file included from 
toolchain-powerpc_8540_gcc-8.4.0_musl/include/errno.h:10,
   from libbpf.c:26:
  toolchain-powerpc_8540_gcc-8.4.0_musl/include/bits/errno.h:58: note: this is 
the location of the previous definition
   #define EDEADLOCK   58

  cc1: all warnings being treated as errors

Fixes: 95f28190aa01 ("tools include arch: Grab a copy of errno.h for arch's 
supported by perf")
Fixes: c3617f72036c ("UAPI: (Scripted) Disintegrate arch/powerpc/include/asm")
Reported-by: Rosen Penev 
Signed-off-by: Tony Ambardar 
---
v1 -> v2:
 * clean up commit description formatting
---
 arch/powerpc/include/uapi/asm/errno.h   | 1 +
 tools/arch/powerpc/include/uapi/asm/errno.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/arch/powerpc/include/uapi/asm/errno.h 
b/arch/powerpc/include/uapi/asm/errno.h
index cc79856896a1..4ba87de32be0 100644
--- a/arch/powerpc/include/uapi/asm/errno.h
+++ b/arch/powerpc/include/uapi/asm/errno.h
@@ -2,6 +2,7 @@
 #ifndef _ASM_POWERPC_ERRNO_H
 #define _ASM_POWERPC_ERRNO_H
 
+#undef EDEADLOCK
 #include 
 
 #undef EDEADLOCK
diff --git a/tools/arch/powerpc/include/uapi/asm/errno.h 
b/tools/arch/powerpc/include/uapi/asm/errno.h
index cc79856896a1..4ba87de32be0 100644
--- a/tools/arch/powerpc/include/uapi/asm/errno.h
+++ b/tools/arch/powerpc/include/uapi/asm/errno.h
@@ -2,6 +2,7 @@
 #ifndef _ASM_POWERPC_ERRNO_H
 #define _ASM_POWERPC_ERRNO_H
 
+#undef EDEADLOCK
 #include 
 
 #undef EDEADLOCK
-- 
2.25.1



[PATCH v1] powerpc: fix EDEADLOCK redefinition error in uapi/asm/errno.h

2020-09-16 Thread Tony Ambardar
A few archs like powerpc have different errno.h values for macros
EDEADLOCK and EDEADLK. In code including both libc and linux versions of
errno.h, this can result in multiple definitions of EDEADLOCK in the
include chain. Definitions to the same value (e.g. seen with mips) do
not raise warnings, but on powerpc there are redefinitions changing the
value, which raise warnings and errors (if using "-Werror").

Guard against these redefinitions to avoid build errors like the following,
first seen cross-compiling libbpf v5.8.9 for powerpc using GCC 8.4.0 with
musl 1.1.24:

  In file included from ../../arch/powerpc/include/uapi/asm/errno.h:5,
   from ../../include/linux/err.h:8,
   from libbpf.c:29:
  ../../include/uapi/asm-generic/errno.h:40: error: "EDEADLOCK" redefined 
[-Werror]
   #define EDEADLOCK EDEADLK

  In file included from 
toolchain-powerpc_8540_gcc-8.4.0_musl/include/errno.h:10,
   from libbpf.c:26:
  toolchain-powerpc_8540_gcc-8.4.0_musl/include/bits/errno.h:58: note: this is 
the location of the previous definition
   #define EDEADLOCK   58

  cc1: all warnings being treated as errors
  make[5]: *** 
[target-powerpc_8540_musl/bpftools-5.8.9/tools/build/Makefile.build:97: 
/home/kodidev/openwrt-project/build_dir/target-powerpc_8540_musl/bpftools-minimal/bpftools-5.8.9//libbpf/staticobjs/libbpf.o]
 Error 1

Fixes: 95f28190aa01 ("tools include arch: Grab a copy of errno.h for arch's
  supported by perf")
Fixes: c3617f72036c ("UAPI: (Scripted) Disintegrate arch/powerpc/include/asm")

Reported-by: Rosen Penev 
Signed-off-by: Tony Ambardar 
---
 arch/powerpc/include/uapi/asm/errno.h   | 1 +
 tools/arch/powerpc/include/uapi/asm/errno.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/arch/powerpc/include/uapi/asm/errno.h 
b/arch/powerpc/include/uapi/asm/errno.h
index cc79856896a1..4ba87de32be0 100644
--- a/arch/powerpc/include/uapi/asm/errno.h
+++ b/arch/powerpc/include/uapi/asm/errno.h
@@ -2,6 +2,7 @@
 #ifndef _ASM_POWERPC_ERRNO_H
 #define _ASM_POWERPC_ERRNO_H
 
+#undef EDEADLOCK
 #include 
 
 #undef EDEADLOCK
diff --git a/tools/arch/powerpc/include/uapi/asm/errno.h 
b/tools/arch/powerpc/include/uapi/asm/errno.h
index cc79856896a1..4ba87de32be0 100644
--- a/tools/arch/powerpc/include/uapi/asm/errno.h
+++ b/tools/arch/powerpc/include/uapi/asm/errno.h
@@ -2,6 +2,7 @@
 #ifndef _ASM_POWERPC_ERRNO_H
 #define _ASM_POWERPC_ERRNO_H
 
+#undef EDEADLOCK
 #include 
 
 #undef EDEADLOCK
-- 
2.25.1