Skip to content

Commit 702eddc

Browse files
jpbruckerAlexei Starovoitov
authored andcommitted
libbpf: Handle GCC built-in types for Arm NEON
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> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Andrii Nakryiko <andriin@fb.com> Link: https://lore.kernel.org/bpf/20200812143909.3293280-1-jean-philippe@linaro.org
1 parent 8faf7fc commit 702eddc

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

tools/lib/bpf/btf_dump.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <errno.h>
1414
#include <linux/err.h>
1515
#include <linux/btf.h>
16+
#include <linux/kernel.h>
1617
#include "btf.h"
1718
#include "hashmap.h"
1819
#include "libbpf.h"
@@ -549,6 +550,9 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr)
549550
}
550551
}
551552

553+
static void btf_dump_emit_missing_aliases(struct btf_dump *d, __u32 id,
554+
const struct btf_type *t);
555+
552556
static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id,
553557
const struct btf_type *t);
554558
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)
671675

672676
switch (kind) {
673677
case BTF_KIND_INT:
678+
/* Emit type alias definitions if necessary */
679+
btf_dump_emit_missing_aliases(d, id, t);
680+
674681
tstate->emit_state = EMITTED;
675682
break;
676683
case BTF_KIND_ENUM:
@@ -870,7 +877,7 @@ static void btf_dump_emit_struct_def(struct btf_dump *d,
870877
btf_dump_printf(d, ": %d", m_sz);
871878
off = m_off + m_sz;
872879
} else {
873-
m_sz = max(0, btf__resolve_size(d->btf, m->type));
880+
m_sz = max(0LL, btf__resolve_size(d->btf, m->type));
874881
off = m_off + m_sz * 8;
875882
}
876883
btf_dump_printf(d, ";");
@@ -890,6 +897,32 @@ static void btf_dump_emit_struct_def(struct btf_dump *d,
890897
btf_dump_printf(d, " __attribute__((packed))");
891898
}
892899

900+
static const char *missing_base_types[][2] = {
901+
/*
902+
* GCC emits typedefs to its internal __PolyX_t types when compiling Arm
903+
* SIMD intrinsics. Alias them to standard base types.
904+
*/
905+
{ "__Poly8_t", "unsigned char" },
906+
{ "__Poly16_t", "unsigned short" },
907+
{ "__Poly64_t", "unsigned long long" },
908+
{ "__Poly128_t", "unsigned __int128" },
909+
};
910+
911+
static void btf_dump_emit_missing_aliases(struct btf_dump *d, __u32 id,
912+
const struct btf_type *t)
913+
{
914+
const char *name = btf_dump_type_name(d, id);
915+
int i;
916+
917+
for (i = 0; i < ARRAY_SIZE(missing_base_types); i++) {
918+
if (strcmp(name, missing_base_types[i][0]) == 0) {
919+
btf_dump_printf(d, "typedef %s %s;\n\n",
920+
missing_base_types[i][1], name);
921+
break;
922+
}
923+
}
924+
}
925+
893926
static void btf_dump_emit_enum_fwd(struct btf_dump *d, __u32 id,
894927
const struct btf_type *t)
895928
{

0 commit comments

Comments
 (0)