From patchwork Mon Aug 10 12:28:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 11707373 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B5EE8618 for ; Mon, 10 Aug 2020 12:42:36 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8D6CA206C3 for ; Mon, 10 Aug 2020 12:42:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JHE61clz"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="XsYETe4W" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8D6CA206C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=z8PSrZMrLJL1h6Fz9rTeGIIfUjqhcKI6rmyEV1xsTHE=; b=JHE61clzdEFy1xbflD3/syLepV epkuTCp6qiiyoJBNfMdkEkM2zyL5vQeC12UKxRGJzn9N4spJLyOJcBVFDRHpZPiR6pu8nCw1UqxRI C3ZkMSYP0pL2henzTeIOmMbJIsGX5juDOAy4MsEJ3+IDUIjx/HuoUGOFLHGuZETPru68FAKeOtvXn 5u6JLGrMAwr6v+gS1QQM1cIFhm/7wDfXxPXylDV2EDOFGTZUpRkcPFyJDyIg7UOrK00iplqDdwWUv fd5Yh6U+dMRWMu0O1dqlAUmt2oWA0R0lNTfY9eDyku+NXZ3AD4GBCcpHtJF5irWI0a5FdyEZd28vY bQlg+Ktg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k576g-0004N2-2w; Mon, 10 Aug 2020 12:40:50 +0000 Received: from mail-ej1-x642.google.com ([2a00:1450:4864:20::642]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k576c-0004LN-BL for linux-arm-kernel@lists.infradead.org; Mon, 10 Aug 2020 12:40:47 +0000 Received: by mail-ej1-x642.google.com with SMTP id c16so9177354ejx.12 for ; Mon, 10 Aug 2020 05:40:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9jozky3iNUilNi92WXOcNWoi6GSxB0Ejr0u+yMbhGh4=; b=XsYETe4Wj4k8cTZdzC12eoTAI3QhsCa+r1R3+l67mAQGW3RT5kcVwmnegXs5K5EMTp IMpgOB1+IZDhIouVtRKtuvlnh2lD2J/pza+MQTPqiXyC8uPsBnGiWz4DL3PA8dvIkz5c cQAQXhE5qJexHLV/YCPy2wbMhQkDoxfn9VvPzNhhGJ9bTWT4HPU8kMZong+6RfwqOnCR hbEmC7wDohtQLyIrASLbZtyPnDeklcteL6jOq4a8/6BJHNKR2zn2uID2IK2zOvZMIlxC YYCc+L7ybH3i9NzqRLdeok/5C6Rc7tIJOc0pqNn8qCrZCc7gMTacqrMlSPnrYY/293Jz 2Sxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9jozky3iNUilNi92WXOcNWoi6GSxB0Ejr0u+yMbhGh4=; b=bfSF7h+5JPPeX3U3ew+e8rtPiPleA+Ywcp13+CcjL4ioi273G6MHxLDs3nIY0ZuNqO 1B6xUjjXNjYXAF4DRgOl1pYpwOx/DsZsl9tnIJAhXbHx+hrncFyX50bW9QPI7iBGcOpN CcGxx/tlRM2WiTAbFlc81aGc09yX9SmIiX1lc3WXjlkfmYhlUUbp8A+oNI9+b0PP1Rkz a3y0HiUwGFa1UR+wREezTF88nM2fcDvnfy2UUQGx4HATlX7jvmyrytjEKiFrfXGgxkqq DbEySCg+Z67dQb2OgleO+941Tlr4/6pkte203UGR4Ox5Xnu8fWezzV8mo4gVu6gEDqnf bSEw== X-Gm-Message-State: AOAM530DT7d6xyB9ljv1PB9KkO1Uue4V6gt9BaytuNnkIcfqwHloSdg5 BkbGn3LOwyrwL9Odr/hR+Vm24Q== X-Google-Smtp-Source: ABdhPJxz2LAgBDmCKJWiBsGk130LsHhKh7fSGHlvuZTr9dl1h7uD8JkceN96LNyOkKCXbvAGdXFZDA== X-Received: by 2002:a17:906:37c3:: with SMTP id o3mr22588144ejc.54.1597063242060; Mon, 10 Aug 2020 05:40:42 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id b62sm12395285edf.61.2020.08.10.05.40.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2020 05:40:41 -0700 (PDT) From: Jean-Philippe Brucker To: ast@kernel.org, daniel@iogearbox.net Subject: [PATCH bpf] libbpf: Handle GCC built-in types for Arm NEON Date: Mon, 10 Aug 2020 14:28:36 +0200 Message-Id: <20200810122835.2309026-1-jean-philippe@linaro.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200810_084046_735964_8E245BB6 X-CRM114-Status: GOOD ( 19.79 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:642 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jean-Philippe Brucker , songliubraving@fb.com, Jakov Petrina , john.fastabend@gmail.com, kpsingh@chromium.org, yhs@fb.com, bpf@vger.kernel.org, andriin@fb.com, kafai@fb.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org When building Arm NEON (SIMD) code, GCC emits built-in types __PolyXX_t, which are not recognized by Clang. This causes build failures when including vmlinux.h generated from a kernel built with CONFIG_RAID6_PQ=y and CONFIG_KERNEL_MODE_NEON. Emit typedefs for these built-in types, based on the Clang definitions. poly64_t is unsigned long because it's only defined for 64-bit Arm. 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 Signed-off-by: Jean-Philippe Brucker --- 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..3162d7b1880c 100644 --- a/tools/lib/bpf/btf_dump.c +++ b/tools/lib/bpf/btf_dump.c @@ -13,6 +13,7 @@ #include #include #include +#include #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_int_def(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_int_def(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 *builtin_types[][2] = { + /* + * GCC emits typedefs to its internal __PolyXX_t types when compiling + * Arm SIMD intrinsics. Alias them to the same standard types as Clang. + */ + { "__Poly8_t", "unsigned char" }, + { "__Poly16_t", "unsigned short" }, + { "__Poly64_t", "unsigned long" }, + { "__Poly128_t", "unsigned __int128" }, +}; + +static void btf_dump_emit_int_def(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(builtin_types); i++) { + if (strcmp(name, builtin_types[i][0]) == 0) { + btf_dump_printf(d, "typedef %s %s;\n\n", + builtin_types[i][1], name); + break; + } + } +} + static void btf_dump_emit_enum_fwd(struct btf_dump *d, __u32 id, const struct btf_type *t) {