From patchwork Thu Jan 21 11:35:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 12035697 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 573D8C433E0 for ; Thu, 21 Jan 2021 11:37:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 04B79233EF for ; Thu, 21 Jan 2021 11:37:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728976AbhAULgv (ORCPT ); Thu, 21 Jan 2021 06:36:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730358AbhAULgH (ORCPT ); Thu, 21 Jan 2021 06:36:07 -0500 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 118AEC0613D6 for ; Thu, 21 Jan 2021 03:35:27 -0800 (PST) Received: by mail-wr1-x44a.google.com with SMTP id g17so808615wrr.11 for ; Thu, 21 Jan 2021 03:35:26 -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=ufMNqtr2froN5NhNrq+9XfQmylek3tVcYtCEPpmC7MI=; b=g1UWbIeSDKI7xy3Z4cq92acJrZ3dq84cLApjLQgGJsPDSnnqlShsCjUY+Rl+MTNq8s M3SUEZCfhh2uXH7+VLccza+7t5dU1e7aDL0zjP07QXigWxcnJ7tAN4Akqb9COU3R65n5 eaAjf5q57bpvBcICBLlX0iyDgVhxrAqVraR9wV+4Xm7eo8U9mRmFku2QtZjeDZzGqL32 +rImKzUP1v07HTtYxTRWXLSdLf6sWkLTZZ7bG3u1zGrlP8mBDLlJyac0T2kDrObCMfE4 MbFBZnc2upUQbigbPgD7WNEcng0SFJsxhNeCLDyY7OczCGJJTv2lCYn0u6Jny5oweRGl GXlQ== 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=ufMNqtr2froN5NhNrq+9XfQmylek3tVcYtCEPpmC7MI=; b=dgUrhVtCqEC47guJSMC9pS6aZs8XJETTxw0rk13sWNfQZNjZriGUsRsXww+xwZT1pT Bm7tB7P93WO8LYJ/U+jZfAe4kNo+aj6epK+TXY54p7vI0dGMB1noAuLnAxZdlz7IN5di ib+J5R+4gNhrzet1gAgV2HFtAuyn7KyEI2WrRNgiPbww7EIECppmbZo+vpqYlmFJDGBM NOLVHXzAUU8iYnigfG0rQ9AGYfltwlPKYXU2Yl3vZugdsh852qJgDjWC28IvYhFpIqVo TwuyR40XyJYs/zEX6eTvDGhTplF2rxOXtcNA+lSVI8t2RZdDLB8Mzy6vGkrWFn1EmyNJ rNTQ== X-Gm-Message-State: AOAM533URrT1lqV3NWrUkw+N/UhPYYVyjR12Wo1/ZYMjjC4vBN+AZGXp xislj5yXuWQ6/3FsuJXl19wHh4h0yfnwkA== X-Google-Smtp-Source: ABdhPJwpbFDiV630Klw6CHkClUjz++LTTH7yVmGh3ybWxS0IMB2IVq9fm22eoGk2Yjb5ZkKEhrljkMTZ94pMSA== 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:a5d:690d:: with SMTP id t13mr13728061wru.410.1611228925660; Thu, 21 Jan 2021 03:35:25 -0800 (PST) Date: Thu, 21 Jan 2021 11:35:18 +0000 In-Reply-To: <20210121113520.3603097-1-gprocida@google.com> Message-Id: <20210121113520.3603097-2-gprocida@google.com> Mime-Version: 1.0 References: <20210118160139.1971039-1-gprocida@google.com> <20210121113520.3603097-1-gprocida@google.com> X-Mailer: git-send-email 2.30.0.296.g2bfb1c46d8-goog Subject: [PATCH dwarves v2 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 This corrects a typo that resulted in 'restrict' being treated as 'const'. Fixes: 48efa92933e8 ("btf_encoder: Use libbpf APIs to encode BTF type info") Acked-by: Andrii Nakryiko Signed-off-by: Giuliano Procida --- 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 Thu Jan 21 11:35:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 12035695 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 7F99CC433E0 for ; Thu, 21 Jan 2021 11:36:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C10D233EF for ; Thu, 21 Jan 2021 11:36:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729363AbhAULgx (ORCPT ); Thu, 21 Jan 2021 06:36:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730421AbhAULgL (ORCPT ); Thu, 21 Jan 2021 06:36:11 -0500 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89152C061786 for ; Thu, 21 Jan 2021 03:35:28 -0800 (PST) Received: by mail-qt1-x84a.google.com with SMTP id s26so1200420qtq.21 for ; Thu, 21 Jan 2021 03:35:28 -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=7/SN6szQNLLz010hJwo1UBS9+/YFLEy0oZww8gtGTAU=; b=seF3tjBBjQMRwwhd0avsnTQmHfvFUYS4OYKRdUMscToC4Uu8WRTQYW983GuAV9Wcg8 ENe749X+TStHaEzNebOazoh2PuO6m4SVgj5P3qISO08+nD2cKxi22mJsuYMGxqujMZiF H+WuYXaQXSe862t5kLpFcdSyyfGVtsUQSMuaiwxq1ZPMGHKl4L46ujOWZbtMz2y0ZKi+ HYb+Q3wiG0kD0Bv6/g1EpdDkwsZh97CRTSfofMh5GC1eYHrQxU6zMohB71irEWSIT0Pb EzjqqaMMltxoUtJqAcn4PwSPjQlXpEPlYsVclPFkYUuNktJGzow/6twND3fltFQd9Jag My9A== 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=7/SN6szQNLLz010hJwo1UBS9+/YFLEy0oZww8gtGTAU=; b=PFz8oIXuoOUD0hBayllahPx5/c/eNOMdY5/4qR0JqhdJct0FKKjMQUi9zAy8MH5eye zZmauAOuKLV+t2mLDDe1kFCNz8p/bbN/0xBmpqtzRPpwo2863hIGv38CvVVyuYa20wad hDx6Oh1cawHiaH5j3Ahe5wBBmTevynIz9tEnQMlV+RuVN0RuJc/7YxEjBNNdAX9WPNlj /v8jDc9HCG5UzFc7FJvMrDL8ijHOK5u8452/nnHn546IgB3hcOwxZ/LJi502Ln12nXRX UCDwM2UfdGEN7IH+cBrLy62TlPkAbBfNqlU4K4QGeRnhNV1VIHq3phhEYDPIAmY1HL3q EzyA== X-Gm-Message-State: AOAM532aMMPMeT062kYogre8MfleHm/DTFq9TAMTvvhTRX+14uSRoknO R+7cWgqOEjr/VU1xfXMDZEUhQNFzn8KOqA== X-Google-Smtp-Source: ABdhPJzthVyDCUNV6p2fUfYujC2TY5GSWxY3hDjK2c2w7JAUffTUcdFFeJpajHn0lFik4BMRSFbdEDISapsCJA== 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:6214:a03:: with SMTP id dw3mr13807575qvb.24.1611228927732; Thu, 21 Jan 2021 03:35:27 -0800 (PST) Date: Thu, 21 Jan 2021 11:35:19 +0000 In-Reply-To: <20210121113520.3603097-1-gprocida@google.com> Message-Id: <20210121113520.3603097-3-gprocida@google.com> Mime-Version: 1.0 References: <20210118160139.1971039-1-gprocida@google.com> <20210121113520.3603097-1-gprocida@google.com> X-Mailer: git-send-email 2.30.0.296.g2bfb1c46d8-goog Subject: [PATCH dwarves v2 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. Acked-by: Andrii Nakryiko Signed-off-by: Giuliano Procida --- 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 Thu Jan 21 11:35:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 12035693 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 AF75FC433DB for ; Thu, 21 Jan 2021 11:36:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F045233EF for ; Thu, 21 Jan 2021 11:36:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728676AbhAULgr (ORCPT ); Thu, 21 Jan 2021 06:36:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730477AbhAULgN (ORCPT ); Thu, 21 Jan 2021 06:36:13 -0500 Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 664E8C061794 for ; Thu, 21 Jan 2021 03:35:31 -0800 (PST) Received: by mail-wm1-x34a.google.com with SMTP id q24so412523wmc.1 for ; Thu, 21 Jan 2021 03:35:31 -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=tHm4aawgl4upxAANEu6km7IPT8qo7sF57UAGh5jcpEQ=; b=Ds0HNmp+7d57PEygc5eJeuDPMs2K36GpyTgvXuI+sYnvLHDRl4l47t84aX6pqaOUyN M0cqR7DNwQdUFHH+U7RNJYRbRfePFqBPHiKCBVXGiMUt1mPvM3LgLWVDcqqwiTKerhNV yYFLIRDLzcO7VtceJd29Dm1Kyi5aIytZjBpTfHkW+T1wyed2Gvueb08kJqPdQjaDqlHX gwE8jpy9C7X7QxUH2bqooA80qU3E+A3NdGgz15Tf5EKlqB9Hl+JgHnNHnN2XBHvtyaAx g3TiIHdXrlEDWjy8aLL5wdQWKGRWBHYS6XHEZbyrq3JseIowte/ev73FyiyQT1Oh5t0u Vn/w== 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=tHm4aawgl4upxAANEu6km7IPT8qo7sF57UAGh5jcpEQ=; b=rBy7gyQAK+dGt5yddKyg4v3fXUz1zW/o6hwN4m1BqDbDU3RYEvfnSjDO23krXJcVpl CBF9Bpcnh7h868GnM21nDfgFyPjmU1HhamE4t5FuowUe7lTnyt7YzvzBkEnleUgB4/6y JRKLmxoVYyQsmJGsER3qrpkgL+WkzQ3aMy8UYIU6qxdSn2S6qpMyn2nP8OEvbYTTfR0a Qlie6zNuClxpq/D7N6tX/jkI0/V8iyjK5cuRuSu4uBeK6vdaVUT9CeQ3lPRKlUQ0uqn7 VyF2P8ntgZ8MgAsu3DusNjjVLABmO/s/zbJiuWkc0z2lc2nO2ZTBjkCF+lSY9pXXx73t IIXQ== X-Gm-Message-State: AOAM532GbSuhuiqG9bLg6dqkKrpcvUskcFv3e4RX28JSbmi1y1vDClDD aqNbsv0clRU5FcgCkbj/tL1BarZS0stabw== X-Google-Smtp-Source: ABdhPJwkT3VH4D3ylEUPgDZEGZQ7ElFObJ8fc1L0AgD7z8Ml7WHUWCN/ZDwWYaaUpj/nBbu9yEwa89ciGUC+dA== 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:a5d:4806:: with SMTP id l6mr11402294wrq.389.1611228930100; Thu, 21 Jan 2021 03:35:30 -0800 (PST) Date: Thu, 21 Jan 2021 11:35:20 +0000 In-Reply-To: <20210121113520.3603097-1-gprocida@google.com> Message-Id: <20210121113520.3603097-4-gprocida@google.com> Mime-Version: 1.0 References: <20210118160139.1971039-1-gprocida@google.com> <20210121113520.3603097-1-gprocida@google.com> X-Mailer: git-send-email 2.30.0.296.g2bfb1c46d8-goog Subject: [PATCH dwarves v2 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 NOTE: Do not apply. I will try to eliminate the dependency on objcopy instead and achieve what's needed directly using libelf. 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);