All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf v2] libbpf: Handle GCC built-in types for Arm NEON
@ 2020-08-12 14:39 ` Jean-Philippe Brucker
  0 siblings, 0 replies; 6+ messages in thread
From: Jean-Philippe Brucker @ 2020-08-12 14:39 UTC (permalink / raw)
  To: ast, daniel
  Cc: kafai, songliubraving, yhs, andriin, john.fastabend, kpsingh,
	bpf, linux-arm-kernel, Jean-Philippe Brucker, Jakov Petrina

When building Arm NEON (SIMD) code from lib/raid6/neon.uc, GCC emits
DWARF information using a base type "__Poly8_t", which is internal to
GCC and not recognized by Clang. This causes build failures when
building with Clang a vmlinux.h generated from an arm64 kernel that was
built with GCC.

	vmlinux.h:47284:9: error: unknown type name '__Poly8_t'
	typedef __Poly8_t poly8x16_t[16];
	        ^~~~~~~~~

The polyX_t types are defined as unsigned integers in the "Arm C
Language Extension" document (101028_Q220_00_en). Emit typedefs based on
standard integer types for the GCC internal types, similar to those
emitted by Clang.

Including linux/kernel.h to use ARRAY_SIZE() incidentally redefined
max(), causing a build bug due to different types, hence the seemingly
unrelated change.

Reported-by: Jakov Petrina <jakov.petrina@sartura.hr>
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
v2:
* Tried to clarify the commit message a bit.
* Made __Poly64_t an unsigned long long, for portability.
* Improve names.
---
 tools/lib/bpf/btf_dump.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index cf711168d34a..ac81f3f8957a 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -13,6 +13,7 @@
 #include <errno.h>
 #include <linux/err.h>
 #include <linux/btf.h>
+#include <linux/kernel.h>
 #include "btf.h"
 #include "hashmap.h"
 #include "libbpf.h"
@@ -549,6 +550,9 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr)
 	}
 }
 
+static void btf_dump_emit_missing_aliases(struct btf_dump *d, __u32 id,
+					  const struct btf_type *t);
+
 static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id,
 				     const struct btf_type *t);
 static void btf_dump_emit_struct_def(struct btf_dump *d, __u32 id,
@@ -671,6 +675,9 @@ static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id)
 
 	switch (kind) {
 	case BTF_KIND_INT:
+		/* Emit type alias definitions if necessary */
+		btf_dump_emit_missing_aliases(d, id, t);
+
 		tstate->emit_state = EMITTED;
 		break;
 	case BTF_KIND_ENUM:
@@ -870,7 +877,7 @@ static void btf_dump_emit_struct_def(struct btf_dump *d,
 			btf_dump_printf(d, ": %d", m_sz);
 			off = m_off + m_sz;
 		} else {
-			m_sz = max(0, btf__resolve_size(d->btf, m->type));
+			m_sz = max(0LL, btf__resolve_size(d->btf, m->type));
 			off = m_off + m_sz * 8;
 		}
 		btf_dump_printf(d, ";");
@@ -890,6 +897,32 @@ static void btf_dump_emit_struct_def(struct btf_dump *d,
 		btf_dump_printf(d, " __attribute__((packed))");
 }
 
+static const char *missing_base_types[][2] = {
+	/*
+	 * GCC emits typedefs to its internal __PolyX_t types when compiling Arm
+	 * SIMD intrinsics. Alias them to standard base types.
+	 */
+	{ "__Poly8_t",		"unsigned char" },
+	{ "__Poly16_t",		"unsigned short" },
+	{ "__Poly64_t",		"unsigned long long" },
+	{ "__Poly128_t",	"unsigned __int128" },
+};
+
+static void btf_dump_emit_missing_aliases(struct btf_dump *d, __u32 id,
+					  const struct btf_type *t)
+{
+	const char *name = btf_dump_type_name(d, id);
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(missing_base_types); i++) {
+		if (strcmp(name, missing_base_types[i][0]) == 0) {
+			btf_dump_printf(d, "typedef %s %s;\n\n",
+					missing_base_types[i][1], name);
+			break;
+		}
+	}
+}
+
 static void btf_dump_emit_enum_fwd(struct btf_dump *d, __u32 id,
 				   const struct btf_type *t)
 {
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH bpf v2] libbpf: Handle GCC built-in types for Arm NEON
@ 2020-08-12 14:39 ` Jean-Philippe Brucker
  0 siblings, 0 replies; 6+ messages in thread
From: Jean-Philippe Brucker @ 2020-08-12 14:39 UTC (permalink / raw)
  To: ast, daniel
  Cc: Jean-Philippe Brucker, songliubraving, Jakov Petrina,
	john.fastabend, kpsingh, yhs, bpf, andriin, kafai,
	linux-arm-kernel

When building Arm NEON (SIMD) code from lib/raid6/neon.uc, GCC emits
DWARF information using a base type "__Poly8_t", which is internal to
GCC and not recognized by Clang. This causes build failures when
building with Clang a vmlinux.h generated from an arm64 kernel that was
built with GCC.

	vmlinux.h:47284:9: error: unknown type name '__Poly8_t'
	typedef __Poly8_t poly8x16_t[16];
	        ^~~~~~~~~

The polyX_t types are defined as unsigned integers in the "Arm C
Language Extension" document (101028_Q220_00_en). Emit typedefs based on
standard integer types for the GCC internal types, similar to those
emitted by Clang.

Including linux/kernel.h to use ARRAY_SIZE() incidentally redefined
max(), causing a build bug due to different types, hence the seemingly
unrelated change.

Reported-by: Jakov Petrina <jakov.petrina@sartura.hr>
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
v2:
* Tried to clarify the commit message a bit.
* Made __Poly64_t an unsigned long long, for portability.
* Improve names.
---
 tools/lib/bpf/btf_dump.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index cf711168d34a..ac81f3f8957a 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -13,6 +13,7 @@
 #include <errno.h>
 #include <linux/err.h>
 #include <linux/btf.h>
+#include <linux/kernel.h>
 #include "btf.h"
 #include "hashmap.h"
 #include "libbpf.h"
@@ -549,6 +550,9 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr)
 	}
 }
 
+static void btf_dump_emit_missing_aliases(struct btf_dump *d, __u32 id,
+					  const struct btf_type *t);
+
 static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id,
 				     const struct btf_type *t);
 static void btf_dump_emit_struct_def(struct btf_dump *d, __u32 id,
@@ -671,6 +675,9 @@ static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id)
 
 	switch (kind) {
 	case BTF_KIND_INT:
+		/* Emit type alias definitions if necessary */
+		btf_dump_emit_missing_aliases(d, id, t);
+
 		tstate->emit_state = EMITTED;
 		break;
 	case BTF_KIND_ENUM:
@@ -870,7 +877,7 @@ static void btf_dump_emit_struct_def(struct btf_dump *d,
 			btf_dump_printf(d, ": %d", m_sz);
 			off = m_off + m_sz;
 		} else {
-			m_sz = max(0, btf__resolve_size(d->btf, m->type));
+			m_sz = max(0LL, btf__resolve_size(d->btf, m->type));
 			off = m_off + m_sz * 8;
 		}
 		btf_dump_printf(d, ";");
@@ -890,6 +897,32 @@ static void btf_dump_emit_struct_def(struct btf_dump *d,
 		btf_dump_printf(d, " __attribute__((packed))");
 }
 
+static const char *missing_base_types[][2] = {
+	/*
+	 * GCC emits typedefs to its internal __PolyX_t types when compiling Arm
+	 * SIMD intrinsics. Alias them to standard base types.
+	 */
+	{ "__Poly8_t",		"unsigned char" },
+	{ "__Poly16_t",		"unsigned short" },
+	{ "__Poly64_t",		"unsigned long long" },
+	{ "__Poly128_t",	"unsigned __int128" },
+};
+
+static void btf_dump_emit_missing_aliases(struct btf_dump *d, __u32 id,
+					  const struct btf_type *t)
+{
+	const char *name = btf_dump_type_name(d, id);
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(missing_base_types); i++) {
+		if (strcmp(name, missing_base_types[i][0]) == 0) {
+			btf_dump_printf(d, "typedef %s %s;\n\n",
+					missing_base_types[i][1], name);
+			break;
+		}
+	}
+}
+
 static void btf_dump_emit_enum_fwd(struct btf_dump *d, __u32 id,
 				   const struct btf_type *t)
 {
-- 
2.27.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf v2] libbpf: Handle GCC built-in types for Arm NEON
  2020-08-12 14:39 ` Jean-Philippe Brucker
@ 2020-08-12 17:35   ` Andrii Nakryiko
  -1 siblings, 0 replies; 6+ messages in thread
From: Andrii Nakryiko @ 2020-08-12 17:35 UTC (permalink / raw)
  To: Jean-Philippe Brucker
  Cc: Alexei Starovoitov, Daniel Borkmann, Martin Lau, Song Liu,
	Yonghong Song, Andrii Nakryiko, john fastabend, KP Singh, bpf,
	linux-arm-kernel, Jakov Petrina

On Wed, Aug 12, 2020 at 7:42 AM Jean-Philippe Brucker
<jean-philippe@linaro.org> wrote:
>
> When building Arm NEON (SIMD) code from lib/raid6/neon.uc, GCC emits
> DWARF information using a base type "__Poly8_t", which is internal to
> GCC and not recognized by Clang. This causes build failures when
> building with Clang a vmlinux.h generated from an arm64 kernel that was
> built with GCC.
>
>         vmlinux.h:47284:9: error: unknown type name '__Poly8_t'
>         typedef __Poly8_t poly8x16_t[16];
>                 ^~~~~~~~~
>
> The polyX_t types are defined as unsigned integers in the "Arm C
> Language Extension" document (101028_Q220_00_en). Emit typedefs based on
> standard integer types for the GCC internal types, similar to those
> emitted by Clang.
>
> Including linux/kernel.h to use ARRAY_SIZE() incidentally redefined
> max(), causing a build bug due to different types, hence the seemingly
> unrelated change.
>
> Reported-by: Jakov Petrina <jakov.petrina@sartura.hr>
> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> ---

LGTM.

Acked-by: Andrii Nakryiko <andriin@fb.com>

[...]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf v2] libbpf: Handle GCC built-in types for Arm NEON
@ 2020-08-12 17:35   ` Andrii Nakryiko
  0 siblings, 0 replies; 6+ messages in thread
From: Andrii Nakryiko @ 2020-08-12 17:35 UTC (permalink / raw)
  To: Jean-Philippe Brucker
  Cc: Song Liu, Daniel Borkmann, Jakov Petrina, john fastabend,
	Alexei Starovoitov, KP Singh, Yonghong Song, bpf,
	Andrii Nakryiko, Martin Lau, linux-arm-kernel

On Wed, Aug 12, 2020 at 7:42 AM Jean-Philippe Brucker
<jean-philippe@linaro.org> wrote:
>
> When building Arm NEON (SIMD) code from lib/raid6/neon.uc, GCC emits
> DWARF information using a base type "__Poly8_t", which is internal to
> GCC and not recognized by Clang. This causes build failures when
> building with Clang a vmlinux.h generated from an arm64 kernel that was
> built with GCC.
>
>         vmlinux.h:47284:9: error: unknown type name '__Poly8_t'
>         typedef __Poly8_t poly8x16_t[16];
>                 ^~~~~~~~~
>
> The polyX_t types are defined as unsigned integers in the "Arm C
> Language Extension" document (101028_Q220_00_en). Emit typedefs based on
> standard integer types for the GCC internal types, similar to those
> emitted by Clang.
>
> Including linux/kernel.h to use ARRAY_SIZE() incidentally redefined
> max(), causing a build bug due to different types, hence the seemingly
> unrelated change.
>
> Reported-by: Jakov Petrina <jakov.petrina@sartura.hr>
> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> ---

LGTM.

Acked-by: Andrii Nakryiko <andriin@fb.com>

[...]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf v2] libbpf: Handle GCC built-in types for Arm NEON
  2020-08-12 17:35   ` Andrii Nakryiko
@ 2020-08-13  1:12     ` Alexei Starovoitov
  -1 siblings, 0 replies; 6+ messages in thread
From: Alexei Starovoitov @ 2020-08-13  1:12 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Jean-Philippe Brucker, Alexei Starovoitov, Daniel Borkmann,
	Martin Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	john fastabend, KP Singh, bpf, linux-arm-kernel, Jakov Petrina

On Wed, Aug 12, 2020 at 10:35 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Wed, Aug 12, 2020 at 7:42 AM Jean-Philippe Brucker
> <jean-philippe@linaro.org> wrote:
> >
> > When building Arm NEON (SIMD) code from lib/raid6/neon.uc, GCC emits
> > DWARF information using a base type "__Poly8_t", which is internal to
> > GCC and not recognized by Clang. This causes build failures when
> > building with Clang a vmlinux.h generated from an arm64 kernel that was
> > built with GCC.
> >
> >         vmlinux.h:47284:9: error: unknown type name '__Poly8_t'
> >         typedef __Poly8_t poly8x16_t[16];
> >                 ^~~~~~~~~
> >
> > The polyX_t types are defined as unsigned integers in the "Arm C
> > Language Extension" document (101028_Q220_00_en). Emit typedefs based on
> > standard integer types for the GCC internal types, similar to those
> > emitted by Clang.
> >
> > Including linux/kernel.h to use ARRAY_SIZE() incidentally redefined
> > max(), causing a build bug due to different types, hence the seemingly
> > unrelated change.
> >
> > Reported-by: Jakov Petrina <jakov.petrina@sartura.hr>
> > Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> > ---
>
> LGTM.
>
> Acked-by: Andrii Nakryiko <andriin@fb.com>

Applied. Thanks

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH bpf v2] libbpf: Handle GCC built-in types for Arm NEON
@ 2020-08-13  1:12     ` Alexei Starovoitov
  0 siblings, 0 replies; 6+ messages in thread
From: Alexei Starovoitov @ 2020-08-13  1:12 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: Jean-Philippe Brucker, Song Liu, Daniel Borkmann, Jakov Petrina,
	john fastabend, Alexei Starovoitov, KP Singh, Yonghong Song, bpf,
	Andrii Nakryiko, Martin Lau, linux-arm-kernel

On Wed, Aug 12, 2020 at 10:35 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Wed, Aug 12, 2020 at 7:42 AM Jean-Philippe Brucker
> <jean-philippe@linaro.org> wrote:
> >
> > When building Arm NEON (SIMD) code from lib/raid6/neon.uc, GCC emits
> > DWARF information using a base type "__Poly8_t", which is internal to
> > GCC and not recognized by Clang. This causes build failures when
> > building with Clang a vmlinux.h generated from an arm64 kernel that was
> > built with GCC.
> >
> >         vmlinux.h:47284:9: error: unknown type name '__Poly8_t'
> >         typedef __Poly8_t poly8x16_t[16];
> >                 ^~~~~~~~~
> >
> > The polyX_t types are defined as unsigned integers in the "Arm C
> > Language Extension" document (101028_Q220_00_en). Emit typedefs based on
> > standard integer types for the GCC internal types, similar to those
> > emitted by Clang.
> >
> > Including linux/kernel.h to use ARRAY_SIZE() incidentally redefined
> > max(), causing a build bug due to different types, hence the seemingly
> > unrelated change.
> >
> > Reported-by: Jakov Petrina <jakov.petrina@sartura.hr>
> > Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> > ---
>
> LGTM.
>
> Acked-by: Andrii Nakryiko <andriin@fb.com>

Applied. Thanks

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-08-13  1:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-12 14:39 [PATCH bpf v2] libbpf: Handle GCC built-in types for Arm NEON Jean-Philippe Brucker
2020-08-12 14:39 ` Jean-Philippe Brucker
2020-08-12 17:35 ` Andrii Nakryiko
2020-08-12 17:35   ` Andrii Nakryiko
2020-08-13  1:12   ` Alexei Starovoitov
2020-08-13  1:12     ` Alexei Starovoitov

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.