Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp12050980rwb; Sat, 26 Nov 2022 03:47:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf4/gIK9eJRy0EY2CggzuSNn8fIpLcJ2FmOt13AlB/SeEmZoMLvJiaCJNsf9lVoF5BXvr1J4 X-Received: by 2002:a05:6a00:1d98:b0:56d:4670:6e2a with SMTP id z24-20020a056a001d9800b0056d46706e2amr32417418pfw.77.1669463260777; Sat, 26 Nov 2022 03:47:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669463260; cv=none; d=google.com; s=arc-20160816; b=XW0V2BW+n34/I8p1sZuSMYxrZIBGfcosGMdy/3Jkeji5YLse77UmH2vGHXJfLZhmRb tmn+6oY3i5np8d1nVCdBPryNV1BUUT+mM0VijAlgkS0FmidAgf4nghlPdFbjxyaHbn9V Alnsz0MKuev/ctWHhMmt8gbfvxv7yEVB9SZOwHq1Er7HbX1Lbml8BfpRehR49yuUmLst qroG8n0FcYmO/P1Hsean1GiXDREmZk31WqCSamkZP7A2SHeUSUsLVQHDfikz7x00ftkB 4BZl2hH2223F3xUkWtdBtOWz4krs2R/wijYt++ogfhqL3naEAdVNk2w91L3H3eG/ZOH5 L+UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9w1lPUfY/wiQo03hcSs2vhx8gqp1sMdSqvVAhkIK+mo=; b=Tvwey1QANSN0+dkUCIEZVzoILNhBL2CbcUPwHjlng/TKeXMxT5NzWabJFNzC+DnRoM 2FQlzAvQ8bLXhewgufJjvr9mv+GqJV/Us1CcwFHLnZd0381qtu6LLx22VvV1QFnLDLzk o4tg0yXBZJ4YwQ4HgZwHn7H2IPdLATAZDwVGka/bMX9Cky6PHpi9fEIf59RPTdQRXRAn 1yYgGye71tVWTlcn6HgMst2Q4OGMnfdfGHh34xxjq7pnQ1i/TRQve19KHT1Q98zNCHfd UXpYW0p9zW87lD3nSZWB99ayh+BXsBaU9e2x5thldvP29sjhazdB1n/fkuaosHt3L9NO A8OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="R+/9KRHi"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d9-20020a056a00244900b0056bbdb48fcdsi6818178pfj.118.2022.11.26.03.47.23; Sat, 26 Nov 2022 03:47:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="R+/9KRHi"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229436AbiKZLOK (ORCPT + 84 others); Sat, 26 Nov 2022 06:14:10 -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-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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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; } -- 2.37.2