From patchwork Sat Nov 26 11:11:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changbin Du X-Patchwork-Id: 13056467 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78C5BC43217 for ; Sat, 26 Nov 2022 11:14:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229534AbiKZLOH (ORCPT ); Sat, 26 Nov 2022 06:14:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbiKZLNh (ORCPT ); Sat, 26 Nov 2022 06:13:37 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86F281B7A2; Sat, 26 Nov 2022 03:13:35 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id io19so6042804plb.8; Sat, 26 Nov 2022 03:13:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9w1lPUfY/wiQo03hcSs2vhx8gqp1sMdSqvVAhkIK+mo=; b=R+/9KRHijwhpVJ3TK9Mhzp1avdAR4N6nBhWJmUbbdMX8pU9GAZGyZkfOY0xqA2JsSP v1+qtcKBiliuFh7+TX0L9LgUdYAeLw1fBIIrRcyUgfciwXbnPOC8inUIB/bT94s7CRlE XvnGuJd7IQFce9DIvEsC5bWwNE2wxX8f1swU1WxtUJKdAv/qJPlXSRm6Ch3Yew7qqj/d OwYl8CrNB3h0lTBmqGoJDHmkG4jNs9OJ8GXjUBe1wQy8yZkvcf8VFaD8UKMl9ql0P+KG yAwxR4pPhsOHt+rMKjKAMb4QqDhf03/Inmnbry1YihaAB/FFdIdmfcYzIL6hDLrkE8gY fW3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9w1lPUfY/wiQo03hcSs2vhx8gqp1sMdSqvVAhkIK+mo=; b=lwfE/lZFad8eb9LontiOgwjIIfNW4bJKJux0QRcOc7QRVGMVnGVI1z0zTIBKIo6Oeh qEAiEq6yKzeQa3iLY+oB/o/wU83oS8PphKCOgT+30nQZd1m7LVPYNGYW3wfrXF1H4Ibj nbUS7OMM9zgDTTvgVbMkq8eZKWovZOASZ27UiLaVHMvgHvdOGWx/d7mF4D2aCh1hKvoZ 0r5SqhViddmVYWgT230QiWplprwnXiJqS6zehkQYTukEjpuyNF8xbXVxYmWOOChzKWYB E/NWDyUa/Aho2uzDC3JcobZRbXvXopcFCyyt65sHhnahoC1QAgkKFiIkSNScfhmNzQil 2maA== X-Gm-Message-State: ANoB5plFfvIB/5oKvQT1ePmrj4Dj0DdyO032GbQQNmLXf6SLKBle9cOm bXl2SA5OOKiPUDmEoX67zNk= X-Google-Smtp-Source: AA0mqf6jUU7sfY2okUnC7R+t+mkvGRoqfmwxzGo9YTshb9ohc3bSJEU0nantTMsHf/7CVewnAiL6Iw== X-Received: by 2002:a17:90a:8d13:b0:213:c15:6f08 with SMTP id c19-20020a17090a8d1300b002130c156f08mr44241036pjo.134.1669461214986; Sat, 26 Nov 2022 03:13:34 -0800 (PST) Received: from WRT-WX9.. ([103.135.102.183]) by smtp.gmail.com with ESMTPSA id c194-20020a621ccb000000b0056a93838606sm4555639pfc.58.2022.11.26.03.13.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Nov 2022 03:13:34 -0800 (PST) From: Changbin Du To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Quentin Monnet , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Shuah Khan Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Rutland , Alexander Shishkin , Namhyung Kim , Mykola Lysenko , linux-perf-users@vger.kernel.org, linux-kselftest@vger.kernel.org, Changbin Du Subject: [PATCH 1/2] libbpf: show more info about missing ".BTF" section Date: Sat, 26 Nov 2022 19:11:46 +0800 Message-Id: <20221126111147.199366-2-changbin.du@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221126111147.199366-1-changbin.du@gmail.com> References: <20221126111147.199366-1-changbin.du@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Show more information about why failed instead of just saying "No such file or directory". Now will print below info: libbpf: can not find '.BTF' section libbpf: is CONFIG_DEBUG_INFO_BTF enabled for kernel? Error: failed to load BTF from /home/changbin/work/linux/vmlinux: No such file or directory Signed-off-by: Changbin Du --- tools/lib/bpf/btf.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index d88647da2c7f..3f661d991808 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -906,6 +906,15 @@ struct btf *btf__new(const void *data, __u32 size) return libbpf_ptr(btf_new(data, size, NULL)); } +static bool is_vmlinux(const char *path) +{ + size_t path_len = strlen(path); + size_t suffix_len = strlen("vmlinux"); + + return (path_len >= suffix_len) && + (!memcmp(path + path_len - suffix_len, "vmlinux", suffix_len)); +} + static struct btf *btf_parse_elf(const char *path, struct btf *base_btf, struct btf_ext **btf_ext) { @@ -990,6 +999,9 @@ static struct btf *btf_parse_elf(const char *path, struct btf *base_btf, err = 0; if (!btf_data) { + pr_warn("can not find '%s' section\n", BTF_ELF_SEC); + if (is_vmlinux(path)) + pr_warn("is CONFIG_DEBUG_INFO_BTF enabled for kernel?\n"); err = -ENOENT; goto done; } From patchwork Sat Nov 26 11:11:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changbin Du X-Patchwork-Id: 13056468 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A45BAC47088 for ; Sat, 26 Nov 2022 11:14:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229500AbiKZLOG (ORCPT ); Sat, 26 Nov 2022 06:14:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229595AbiKZLNr (ORCPT ); Sat, 26 Nov 2022 06:13:47 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 029291B1DA; Sat, 26 Nov 2022 03:13:46 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id mv18so5591802pjb.0; Sat, 26 Nov 2022 03:13:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7wXxHwlliB9k9y/zRVSVfdaJjEK9h41TVLmU74Ql4mM=; b=Az5eaU6yt/A/9EC16A5mgH5D+UhNxILaYesE0vaILZ41HUY0H0EcrKI190CwWnHlva EXRB9mqds4P/vTNnGQg7YIWQHGxxy4rLja4l7HFjLh+xPTQmDug3UqLnYCBSwRb4OnFR td+HpnkaCwdIwsKLWuIDT/+/983Dja5Dnkjcwn7l69ufK4v3lQ9eRyxXcBvE+vG0o2ZU B7pUk+wC4UHYJrw71hTnsZKRWdr/UfG0sCH8mKtMm9i41WM05y5xUGmMbxlMFniZrXQn 82gU94ss0lWMN2ElU1tahDVhU4fILxrUBPUEiuptI3nsv+xUeD4LabOjkE9mzsmXxY+4 CnLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7wXxHwlliB9k9y/zRVSVfdaJjEK9h41TVLmU74Ql4mM=; b=ETisHak7yZaVwnFqdzUePVIlflzx4x7UMke0HbXSVogI1L2KtdZQT6FHME3FHS4uRo 3TZreymeCJ4zmjd+GOGfCcdFWuGLP600fvY0enFlzmOcB7vJu4KNExUu5rxXzj7E/uWv mXgqQNhp9amsbcMBf0OmqO2p+4Sr49BKZavHiuXFCv99oTOSVFOHDBx5bvqnFj4u3Z58 43rV4l+gCYL9me8LUr+OJrNN1ZJaIsgHqh28LH21AGGs5c8WLuILS1qGHbN5QFFmVv+J rl8PDf1AuNOpADIdpHt2YL01Mn8wTi5seiuNxKMhhx/dN7Of9m3MMwDaziG9FRoyonhl JJUg== X-Gm-Message-State: ANoB5pm2juBX3egqsvGAvH4o1lKdCEXE9vcfCD/vQTirfPEMKs4C6OWa ropDKkJh8Z2x+sUfLGxjDTo= X-Google-Smtp-Source: AA0mqf4bjAQLyAOUkGVkFZ7QeA5U2FbfawVL8N5Pl0UJnzhCMcX/K+w/Q3lJasx/E4aU1n8l6Pjukg== X-Received: by 2002:a17:902:e807:b0:186:fb90:5774 with SMTP id u7-20020a170902e80700b00186fb905774mr23432978plg.137.1669461225418; Sat, 26 Nov 2022 03:13:45 -0800 (PST) Received: from WRT-WX9.. ([103.135.102.183]) by smtp.gmail.com with ESMTPSA id c194-20020a621ccb000000b0056a93838606sm4555639pfc.58.2022.11.26.03.13.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Nov 2022 03:13:44 -0800 (PST) From: Changbin Du To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Quentin Monnet , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Shuah Khan Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Rutland , Alexander Shishkin , Namhyung Kim , Mykola Lysenko , linux-perf-users@vger.kernel.org, linux-kselftest@vger.kernel.org, Changbin Du Subject: [PATCH 2/2] makefiles: do not generate empty vmlinux.h Date: Sat, 26 Nov 2022 19:11:47 +0800 Message-Id: <20221126111147.199366-3-changbin.du@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221126111147.199366-1-changbin.du@gmail.com> References: <20221126111147.199366-1-changbin.du@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Remove the empty vmlinux.h if bpftool failed to dump btf info. The emptry vmlinux.h can hide real error when reading output of make. Signed-off-by: Changbin Du --- samples/bpf/Makefile | 2 +- tools/bpf/bpftool/Makefile | 2 +- tools/bpf/runqslower/Makefile | 2 +- tools/perf/Makefile.perf | 2 +- tools/testing/selftests/bpf/Makefile | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index 727da3c5879b..ab4788b4883e 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile @@ -362,7 +362,7 @@ ifeq ($(VMLINUX_BTF),) $(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)",\ build the kernel or set VMLINUX_BTF or VMLINUX_H variable) endif - $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@ + $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@ || { rm $@; exit 1; } else $(Q)cp "$(VMLINUX_H)" $@ endif diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile index 4a95c017ad4c..d9d6f890884c 100644 --- a/tools/bpf/bpftool/Makefile +++ b/tools/bpf/bpftool/Makefile @@ -177,7 +177,7 @@ BUILD_BPF_SKELS := 1 $(OUTPUT)vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL_BOOTSTRAP) ifeq ($(VMLINUX_H),) - $(QUIET_GEN)$(BPFTOOL_BOOTSTRAP) btf dump file $< format c > $@ + $(QUIET_GEN)$(BPFTOOL_BOOTSTRAP) btf dump file $< format c > $@ || { rm $@; exit 1; } else $(Q)cp "$(VMLINUX_H)" $@ endif diff --git a/tools/bpf/runqslower/Makefile b/tools/bpf/runqslower/Makefile index 8b3d87b82b7a..2d7911f4666b 100644 --- a/tools/bpf/runqslower/Makefile +++ b/tools/bpf/runqslower/Makefile @@ -77,7 +77,7 @@ ifeq ($(VMLINUX_H),) "specify its location." >&2; \ exit 1;\ fi - $(QUIET_GEN)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@ + $(QUIET_GEN)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@ || { rm $@; exit 1; } else $(Q)cp "$(VMLINUX_H)" $@ endif diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index a432e59afc42..0546d408aa4e 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -1064,7 +1064,7 @@ VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS)))) $(SKEL_OUT)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL) ifeq ($(VMLINUX_H),) - $(QUIET_GEN)$(BPFTOOL) btf dump file $< format c > $@ + $(QUIET_GEN)$(BPFTOOL) btf dump file $< format c > $@ || { rm $@; exit 1; } else $(Q)cp "$(VMLINUX_H)" $@ endif diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index e6cf21fad69f..9aa2475b4ac6 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -284,7 +284,7 @@ endif $(INCLUDE_DIR)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL) | $(INCLUDE_DIR) ifeq ($(VMLINUX_H),) $(call msg,GEN,,$@) - $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@ + $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@ || { rm $@; exit 1; } else $(call msg,CP,,$@) $(Q)cp "$(VMLINUX_H)" $@