From patchwork Mon Jan 18 16:01:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 12027605 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A225C433DB for ; Mon, 18 Jan 2021 16:12:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 65CE522C9C for ; Mon, 18 Jan 2021 16:12:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406228AbhARQMm (ORCPT ); Mon, 18 Jan 2021 11:12:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406076AbhARQCd (ORCPT ); Mon, 18 Jan 2021 11:02:33 -0500 Received: from mail-ej1-x64a.google.com (mail-ej1-x64a.google.com [IPv6:2a00:1450:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D53B8C0613C1 for ; Mon, 18 Jan 2021 08:01:51 -0800 (PST) Received: by mail-ej1-x64a.google.com with SMTP id h18so1965087ejx.17 for ; Mon, 18 Jan 2021 08:01:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=cw3dvRGpX/nSIs+bFZRctQhooB6vy9IbCBqwEdoTFOc=; b=cFOm+rUnyAKi8JkpTd+HdgTPNG7OBrrUy9ionHXZamrgDP7xbIEWfp9EUbzohDY9y6 8qNpc4Vzo/seVzuMT0dsBell02MySEo1pPEUdKXad3LF9pnA1+DTFHDS9m6D1LssnzpH 4YmHa2u6fG0zS5rfw3rmIXNn/KkQWm5lsvDgm6aduXPuRo9RFfnZJ9TrbeFSVcT0mSkj i4Go/JwqFw6K/rVIAvgBUjnoYt0bcRS1ozHeRtl0rrDWbw21d+HMNHKL8Wbr3qt+PUzY QpGrw2t2FBEQNW/2jz73AjECpQVnOorM+I0m2JONBasQq4zXEaZo5yXqcIqUP09k5QNT U0mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=cw3dvRGpX/nSIs+bFZRctQhooB6vy9IbCBqwEdoTFOc=; b=SPmAM36T7bi8ApsOqsUJxQOxcVfFW93mDVCwoKcerfhBbHtqjIKZ11PBTapbEvrjyu yZYO8KFWQCxR7rorDOaYqu2KuJnklD0932B3Byc+sHbOvBm8AjO8QDWcvSvf568EhkyN 2diazciKjSgkMeadG5qtglQUFIR+5E5xaQqahpMfUpo2SuHrKSkhNkBIDpJVG+YbYdPK rU/eaiD6Y6SmHEyyw6dH+H9GtaPqKw7qh9BeC6EVRrhqQ7Q3fCWlztDx6t4ZJyC3qwqN /kHGb3Qsq4rgIQ5P5P2qXu5RUSFlkjCDDrPszo6MQUFP3mBg8j1+apg0U37Quy3IBs9Q oXSA== X-Gm-Message-State: AOAM5306Rrx/BANHdbnNVF3RkfmS+s0kiVCP5ZOw9BbNU5xNL7PLHNtW 7DECJiAnMq2xq8VxfUemvJhkZp2Gn4k5Zw== X-Google-Smtp-Source: ABdhPJw+SvlnDKL5tE8q7bmDcvaaf08OQSqdIUpo3tCtpAC6m5QMFbp1u2chxyy6bFqmUFfKLlt+Tpu886Tm3Q== Sender: "gprocida via sendgmr" X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:110:a6ae:11ff:fe11:4f04]) (user=gprocida job=sendgmr) by 2002:a17:906:15ca:: with SMTP id l10mr242893ejd.402.1610985710175; Mon, 18 Jan 2021 08:01:50 -0800 (PST) Date: Mon, 18 Jan 2021 16:01:37 +0000 In-Reply-To: <20210118160139.1971039-1-gprocida@google.com> Message-Id: <20210118160139.1971039-2-gprocida@google.com> Mime-Version: 1.0 References: <20210118160139.1971039-1-gprocida@google.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH 1/3] btf_encoder: Fix handling of restrict qualifier From: Giuliano Procida To: dwarves@vger.kernel.org Cc: kernel-team@android.com, maennich@google.com, ast@kernel.org, andrii@kernel.org, bpf@vger.kernel.org, kernel-team@fb.com, Giuliano Procida Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Fixes: 48efa92933e8 ("btf_encoder: Use libbpf APIs to encode BTF type info") Signed-off-by: Giuliano Procida Acked-by: Andrii Nakryiko --- libbtf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libbtf.c b/libbtf.c index 16e1d45..3709087 100644 --- a/libbtf.c +++ b/libbtf.c @@ -417,7 +417,7 @@ int32_t btf_elf__add_ref_type(struct btf_elf *btfe, uint16_t kind, uint32_t type id = btf__add_const(btf, type); break; case BTF_KIND_RESTRICT: - id = btf__add_const(btf, type); + id = btf__add_restrict(btf, type); break; case BTF_KIND_TYPEDEF: id = btf__add_typedef(btf, name, type); From patchwork Mon Jan 18 16:01:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 12027603 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 795EFC433E0 for ; Mon, 18 Jan 2021 16:12:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E5CE22B49 for ; Mon, 18 Jan 2021 16:12:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406039AbhARQMl (ORCPT ); Mon, 18 Jan 2021 11:12:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406294AbhARQCe (ORCPT ); Mon, 18 Jan 2021 11:02:34 -0500 Received: from mail-ej1-x649.google.com (mail-ej1-x649.google.com [IPv6:2a00:1450:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F17EC0613D3 for ; Mon, 18 Jan 2021 08:01:54 -0800 (PST) Received: by mail-ej1-x649.google.com with SMTP id z2so955251ejf.3 for ; Mon, 18 Jan 2021 08:01:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=xJW+vh6Tz+lnlfSKKXUu0ilT0sLF89GsDOa6tzMi6P4=; b=gVBZjpbzK0sWaNwLagBuUZIVK8bqxNZCJW58/1vgP9IMkMHe3BUPab5fJ0MdwLUmyn vh5blPry0CpazDHEEnYECMJwNX8YLQ9kT72rwNrepGvnoAGg2zWsZOQA0j0nFCjEXYKy tnc7cYnnpWfZqkEWPxWlGJFk3KnfZ7t201rwEvgAAENjCx2XJjdUGXf3xn257+oCSjJD +5C2TVz98B4JgLkQcI6ROFYMOKf3CaQyC9GJd/dbZNfvVPoM63FFbNk4cSTlSQk+BeVn DFV+Xo8hkqyZfWDdtxcOSOnkl6oG+uG/WwtzdQXsSzOhCIuBof13np5Hl0TgHiBgyN5I T4YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=xJW+vh6Tz+lnlfSKKXUu0ilT0sLF89GsDOa6tzMi6P4=; b=VTiCa1qJz2ZL0P1/v2P+Y4eAxSZ0r3dQm22M5JiZmXGEpvtXS4zOYf6NWq7IjRoRZB 0lKI846mWeGZfw6lR7RGVzBZk2DNyK2Xtq799nbPudndWfMxYMUTLtTbuuFr9Nxr/4o6 Gk6ZRS394pq+JbR7LJWHNhl8jnY6nKDc0wUinlzK+LvzH5D0hnhrLOr2JkqGaIRmqW/1 RYGZFxoimtfoxTmWOjCJ0BOpH2j/6311FiMT1xX7rEyB0PgcPSO/CUhkdrngqAstq/lE SGAOp/m+QqmnVpDFunehcfvwJgTf/BOxAdoG43VlLxPZXyt9q198stsEzl/UDZqPT0e5 xw6A== X-Gm-Message-State: AOAM531H76MlxD2HHCtImZqLfWq+Uv+zSAUrQ/03FOPVHomxgmBUhJ2l fN2gj9nVcZBThCXmAt1Ns7SOQ24OYBAQZQ== X-Google-Smtp-Source: ABdhPJxc3+gFztCUk7U2uUODW9KMDIMQSy6Ib3bLKyNwRGMHjRvtOxuVyAhvYo90mYp002CeLpMKwA365lO0rQ== Sender: "gprocida via sendgmr" X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:110:a6ae:11ff:fe11:4f04]) (user=gprocida job=sendgmr) by 2002:a17:906:e093:: with SMTP id gh19mr253006ejb.510.1610985712776; Mon, 18 Jan 2021 08:01:52 -0800 (PST) Date: Mon, 18 Jan 2021 16:01:38 +0000 In-Reply-To: <20210118160139.1971039-1-gprocida@google.com> Message-Id: <20210118160139.1971039-3-gprocida@google.com> Mime-Version: 1.0 References: <20210118160139.1971039-1-gprocida@google.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH 2/3] btf_encoder: Improve error-handling around objcopy From: Giuliano Procida To: dwarves@vger.kernel.org Cc: kernel-team@android.com, maennich@google.com, ast@kernel.org, andrii@kernel.org, bpf@vger.kernel.org, kernel-team@fb.com, Giuliano Procida Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org * Report the correct filename when objcopy fails. * Unlink the temporary file on error. Signed-off-by: Giuliano Procida Acked-by: Andrii Nakryiko --- libbtf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libbtf.c b/libbtf.c index 3709087..7552d8e 100644 --- a/libbtf.c +++ b/libbtf.c @@ -786,18 +786,19 @@ static int btf_elf__write(const char *filename, struct btf *btf) if (write(fd, raw_btf_data, raw_btf_size) != raw_btf_size) { fprintf(stderr, "%s: write of %d bytes to '%s' failed: %d!\n", __func__, raw_btf_size, tmp_fn, errno); - goto out; + goto unlink; } snprintf(cmd, sizeof(cmd), "%s --add-section .BTF=%s %s", llvm_objcopy, tmp_fn, filename); if (system(cmd)) { fprintf(stderr, "%s: failed to add .BTF section to '%s': %d!\n", - __func__, tmp_fn, errno); - goto out; + __func__, filename, errno); + goto unlink; } err = 0; + unlink: unlink(tmp_fn); } From patchwork Mon Jan 18 16:01:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 12027595 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72319C433E0 for ; Mon, 18 Jan 2021 16:03:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 404F722B4E for ; Mon, 18 Jan 2021 16:03:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405918AbhARQCl (ORCPT ); Mon, 18 Jan 2021 11:02:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406298AbhARQCg (ORCPT ); Mon, 18 Jan 2021 11:02:36 -0500 Received: from mail-ed1-x54a.google.com (mail-ed1-x54a.google.com [IPv6:2a00:1450:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5071BC0613ED for ; Mon, 18 Jan 2021 08:01:56 -0800 (PST) Received: by mail-ed1-x54a.google.com with SMTP id a9so8085976edy.8 for ; Mon, 18 Jan 2021 08:01:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=TqkGDF1ta5PCdnxEEvsF8Ma1Lt/vVVNhRWpTG6LTrD8=; b=skeG0dILnijwcANaFRzfFG8rns/gfweOPnEBdnioVj37CH0jabLoyCs8pkSk9UokwC Cq+ktrPAYJ9ABubh9LzgMr/5AZdBTGTaR1Ph8E6xbry2rqtZdl0jYnCPoEBEI6jwtW77 DqNVltbUjUHsljLeFb1o7erBKBnYqAARQfPyQK2cXwmmJEg0W23x9HfmxDYW/QJnDuX6 fX3FpqMOKfNLQnV9RcX9JqGCfVayXjjyawj6DAn4Sfn/E9DB7/ZFpfcVATHAncOxE8C2 gjWmeOyp1sSGA41DwWg4HU10TqQinbYXP5hCupAr6THMXjp7knQlllZVpz7rGh2/6x1H rIhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=TqkGDF1ta5PCdnxEEvsF8Ma1Lt/vVVNhRWpTG6LTrD8=; b=RMidPznPuu2TWsKqVVocxUQuZ5jj49T3rI/LcYTGcJYg+CS2ond834dtBRl0x4ff38 lgQZgQFTiRJ2bAdZzlMJDY6iJDfTVUlsSaNtUVV/CQzrRlgzmvWWvBXZV7TvxaQgtsUg vUYsvSDGhiZTlohDfqXuKZcXyqrs2RGwIZH4+T8jyLf38AFQY4RyAHfO00MCeuMmJLNf exUVGjIMa3WZfMV5qtij/XtfbMvkG/f6ua3k4swGE2RQBE9blt/tH2uO/jM8sBrGtjur f2/TNdmVlha5HD5Y3FLxwc4JOUoKjTszAxi09BHu/r40R32u/HQXLN711/VF71YYriBh P41w== X-Gm-Message-State: AOAM531rqCXatVMedubhnX8K1pUEYI9eP2VUTDrEzjP7Qt1MyTuWylt9 W8tatLYVnVs8Ve4xyFD40/tXJ4RqgiQJHQ== X-Google-Smtp-Source: ABdhPJyUWrBT4UlLd93wmvwwr+Ba6wo0Z3mXx1DRRmGWRLYjv9cnrAdfGCj0xvRwKN6BhYXAA17iu5VlIxUdWA== Sender: "gprocida via sendgmr" X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:110:a6ae:11ff:fe11:4f04]) (user=gprocida job=sendgmr) by 2002:a05:6402:158:: with SMTP id s24mr119650edu.19.1610985714831; Mon, 18 Jan 2021 08:01:54 -0800 (PST) Date: Mon, 18 Jan 2021 16:01:39 +0000 In-Reply-To: <20210118160139.1971039-1-gprocida@google.com> Message-Id: <20210118160139.1971039-4-gprocida@google.com> Mime-Version: 1.0 References: <20210118160139.1971039-1-gprocida@google.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH 3/3] btf_encoder: Set .BTF section alignment to 16 From: Giuliano Procida To: dwarves@vger.kernel.org Cc: kernel-team@android.com, maennich@google.com, ast@kernel.org, andrii@kernel.org, bpf@vger.kernel.org, kernel-team@fb.com, Giuliano Procida Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org This is to avoid misaligned access when memory-mapping ELF sections. Signed-off-by: Giuliano Procida --- libbtf.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libbtf.c b/libbtf.c index 7552d8e..2f12d53 100644 --- a/libbtf.c +++ b/libbtf.c @@ -797,6 +797,14 @@ static int btf_elf__write(const char *filename, struct btf *btf) goto unlink; } + snprintf(cmd, sizeof(cmd), "%s --set-section-alignment .BTF=16 %s", + llvm_objcopy, filename); + if (system(cmd)) { + /* non-fatal, this is a nice-to-have and it's only supported from LLVM 10 */ + fprintf(stderr, "%s: warning: failed to align .BTF section in '%s': %d!\n", + __func__, filename, errno); + } + err = 0; unlink: unlink(tmp_fn);