From patchwork Fri Nov 6 05:25:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 11886029 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=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 EC680C5517A for ; Fri, 6 Nov 2020 05:25:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9A3D1208C3 for ; Fri, 6 Nov 2020 05:25:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604640357; bh=CqqPzpnhZeyR2BNfHH58yLlMvQ1f/qTLxVEIxAQ9jWg=; h=From:To:CC:Subject:Date:In-Reply-To:References:List-ID:From; b=qKcvULXIyVyLbxa5ExXlmxA125CNKjNMoyqrot3bfd7x07Rl6N94gDGhcwGjAfCWR JFHHqZfr/XBLxwQ09pemyhRI4jWD+lsVesNGolvGCz3lRMptpmnxd3c2YpVCp9c82G qLSJjQIfjifzhN5gPRzehxve01A8g08ooOoeSa0A= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725925AbgKFFZ5 convert rfc822-to-8bit (ORCPT ); Fri, 6 Nov 2020 00:25:57 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:45190 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725835AbgKFFZ4 (ORCPT ); Fri, 6 Nov 2020 00:25:56 -0500 Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0A65FAQO018023 for ; Thu, 5 Nov 2020 21:25:56 -0800 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 34m5rr7rb8-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 05 Nov 2020 21:25:56 -0800 Received: from intmgw002.03.ash8.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 5 Nov 2020 21:25:54 -0800 Received: by devbig012.ftw2.facebook.com (Postfix, from userid 137359) id 7D1582EC8EF6; Thu, 5 Nov 2020 21:25:53 -0800 (PST) From: Andrii Nakryiko To: , , CC: , Subject: [PATCH dwarves 1/4] btf_encoder: fix array index type numbering Date: Thu, 5 Nov 2020 21:25:46 -0800 Message-ID: <20201106052549.3782099-2-andrii@kernel.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201106052549.3782099-1-andrii@kernel.org> References: <20201106052549.3782099-1-andrii@kernel.org> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-06_01:2020-11-05,2020-11-06 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 adultscore=0 clxscore=1034 lowpriorityscore=0 bulkscore=0 suspectscore=8 priorityscore=1501 mlxscore=0 phishscore=0 malwarescore=0 impostorscore=0 spamscore=0 mlxlogscore=948 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011060036 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Take into account type ID offset, accumulated from previous CUs, when calculating a new type ID for the generated array index type. Signed-off-by: Andrii Nakryiko --- btf_encoder.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 4c92908beab2..b3e47f172bb3 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -358,22 +358,22 @@ int cu__encode_btf(struct cu *cu, int verbose, bool force, printf("File %s:\n", btfe->filename); } + btf_elf__verbose = verbose; + btf_elf__force = force; + type_id_off = btf__get_nr_types(btfe->btf); + if (!has_index_type) { /* cu__find_base_type_by_name() takes "type_id_t *id" */ type_id_t id; if (cu__find_base_type_by_name(cu, "int", &id)) { has_index_type = true; - array_index_id = id; + array_index_id = type_id_off + id; } else { has_index_type = false; - array_index_id = cu->types_table.nr_entries; + array_index_id = type_id_off + cu->types_table.nr_entries; } } - btf_elf__verbose = verbose; - btf_elf__force = force; - type_id_off = btf__get_nr_types(btfe->btf); - cu__for_each_type(cu, core_id, pos) { int32_t btf_type_id = tag__encode_btf(cu, pos, core_id, btfe, array_index_id, type_id_off); From patchwork Fri Nov 6 05:25:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 11886027 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=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 7AE58C4741F for ; Fri, 6 Nov 2020 05:26:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 25F55208C3 for ; Fri, 6 Nov 2020 05:26:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604640364; bh=OUwJtNMRWNgO+HYJ9tnNCUlKi3s38M9MIqZoTVM+4TI=; h=From:To:CC:Subject:Date:In-Reply-To:References:List-ID:From; b=J8kk5d7FCEXco90k3+6JusAlyJQJPV4rIehtBpupBAO38/y3d2DmGo/HDuB7PnfTe 78+vZkby/dVYbjLsNJ1y5dU7pfUs3039wRZRQAd9eJ1TqWy5XFiUO8lOTNO45Fj/nW CYhKlOEPzOyuczqCzv94JEvSaRNm1H7UDqeMikws= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726105AbgKFF0C convert rfc822-to-8bit (ORCPT ); Fri, 6 Nov 2020 00:26:02 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:27648 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725979AbgKFF0B (ORCPT ); Fri, 6 Nov 2020 00:26:01 -0500 Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0A65OfiW016481 for ; Thu, 5 Nov 2020 21:26:01 -0800 Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 34mr9ba68n-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 05 Nov 2020 21:26:01 -0800 Received: from intmgw002.03.ash8.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::c) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 5 Nov 2020 21:25:59 -0800 Received: by devbig012.ftw2.facebook.com (Postfix, from userid 137359) id A7E322EC8EF6; Thu, 5 Nov 2020 21:25:55 -0800 (PST) From: Andrii Nakryiko To: , , CC: , Subject: [PATCH dwarves 2/4] libbtf: improve variable naming and error reporting when writing out BTF Date: Thu, 5 Nov 2020 21:25:47 -0800 Message-ID: <20201106052549.3782099-3-andrii@kernel.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201106052549.3782099-1-andrii@kernel.org> References: <20201106052549.3782099-1-andrii@kernel.org> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-06_01:2020-11-05,2020-11-06 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 malwarescore=0 phishscore=0 clxscore=1034 lowpriorityscore=0 mlxlogscore=802 suspectscore=8 mlxscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011060037 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Rename few local variables to reflects the purpose a bit better. Also separate writing out BTF raw data and objcopy invocation into two separate steps and improve error reporting for each. Signed-off-by: Andrii Nakryiko --- libbtf.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/libbtf.c b/libbtf.c index babf4fe8cd9e..b6ddd7599395 100644 --- a/libbtf.c +++ b/libbtf.c @@ -679,11 +679,11 @@ static int btf_elf__write(const char *filename, struct btf *btf) { GElf_Shdr shdr_mem, *shdr; GElf_Ehdr ehdr_mem, *ehdr; - Elf_Data *btf_elf = NULL; + Elf_Data *btf_data = NULL; Elf_Scn *scn = NULL; Elf *elf = NULL; - const void *btf_data; - uint32_t btf_size; + const void *raw_btf_data; + uint32_t raw_btf_size; int fd, err = -1; size_t strndx; @@ -735,18 +735,18 @@ static int btf_elf__write(const char *filename, struct btf *btf) continue; char *secname = elf_strptr(elf, strndx, shdr->sh_name); if (strcmp(secname, ".BTF") == 0) { - btf_elf = elf_getdata(scn, btf_elf); + btf_data = elf_getdata(scn, btf_data); break; } } - btf_data = btf__get_raw_data(btf, &btf_size); + raw_btf_data = btf__get_raw_data(btf, &raw_btf_size); - if (btf_elf) { + if (btf_data) { /* Exisiting .BTF section found */ - btf_elf->d_buf = (void *)btf_data; - btf_elf->d_size = btf_size; - elf_flagdata(btf_elf, ELF_C_SET, ELF_F_DIRTY); + btf_data->d_buf = (void *)raw_btf_data; + btf_data->d_size = raw_btf_size; + elf_flagdata(btf_data, ELF_C_SET, ELF_F_DIRTY); if (elf_update(elf, ELF_C_NULL) >= 0 && elf_update(elf, ELF_C_WRITE) >= 0) @@ -770,12 +770,21 @@ static int btf_elf__write(const char *filename, struct btf *btf) goto out; } + 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; + } + 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; + } - if (write(fd, btf_data, btf_size) == btf_size && !system(cmd)) - err = 0; - + err = 0; unlink(tmp_fn); } From patchwork Fri Nov 6 05:25:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 11886031 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=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 6D471C4741F for ; Fri, 6 Nov 2020 05:26:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 153F2208C3 for ; Fri, 6 Nov 2020 05:26:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604640369; bh=YuNxCAhU5igq8xtKY8dIWLWTO3xu3TgDcdvZWSExVVs=; h=From:To:CC:Subject:Date:In-Reply-To:References:List-ID:From; b=Tq3uDjBaVYmazhGLjavQHDjHSt31uN73TOoJ6efpbLe6ZWjPlkSzXKz6ooVbZea2u +PJ6klyb+kN97lIlQYbihIDAZwCS9BJGDAEoZRTStisVqT+LUWnmBo7j629KJzTJbP vh9nRu9i03kHbs0l88S4UYn/7wgBSnKS9+u423uo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726140AbgKFF0I convert rfc822-to-8bit (ORCPT ); Fri, 6 Nov 2020 00:26:08 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:58640 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726125AbgKFF0I (ORCPT ); Fri, 6 Nov 2020 00:26:08 -0500 Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0A65Q6LW008311 for ; Thu, 5 Nov 2020 21:26:07 -0800 Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 34m81m75au-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 05 Nov 2020 21:26:07 -0800 Received: from intmgw001.03.ash8.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c085:21d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 5 Nov 2020 21:26:05 -0800 Received: by devbig012.ftw2.facebook.com (Postfix, from userid 137359) id D3EEE2EC8EF6; Thu, 5 Nov 2020 21:25:57 -0800 (PST) From: Andrii Nakryiko To: , , CC: , Subject: [PATCH dwarves 3/4] libbpf: update libbpf submodlue reference to latest master Date: Thu, 5 Nov 2020 21:25:48 -0800 Message-ID: <20201106052549.3782099-4-andrii@kernel.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201106052549.3782099-1-andrii@kernel.org> References: <20201106052549.3782099-1-andrii@kernel.org> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-06_01:2020-11-05,2020-11-06 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 malwarescore=0 adultscore=0 mlxlogscore=778 lowpriorityscore=0 clxscore=1034 mlxscore=0 bulkscore=0 impostorscore=0 phishscore=0 spamscore=0 suspectscore=8 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011060037 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Pull in latest libbpf changes, containing split BTF APIs. Signed-off-by: Andrii Nakryiko --- lib/bpf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bpf b/lib/bpf index ff797cc905d9..5af3d86b5a2c 160000 --- a/lib/bpf +++ b/lib/bpf @@ -1 +1 @@ -Subproject commit ff797cc905d9c5fe9acab92d2da127342b20f80f +Subproject commit 5af3d86b5a2c5fecdc3ab83822d083edd32b4396 From patchwork Fri Nov 6 05:25:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 11886033 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=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 3F38CC56202 for ; Fri, 6 Nov 2020 05:26:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA64620A8B for ; Fri, 6 Nov 2020 05:26:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604640364; bh=RoBu1C2wy7B/488G60eL67YD+ZfuQIi8nQdrCsZRhqM=; h=From:To:CC:Subject:Date:In-Reply-To:References:List-ID:From; b=sqwX7fLT1uRRYSYVcebG9IC35Awj4HNLkoTn/QTrwzcGbnJGQDn7xLkNigLj0Ecq9 I+ZDGKrd3h0sSCpCPkVaUOSMD+D/u27axtdsZk63IeBo4ZSXmb76Q6lFfJAxZde4yo 4dn/L41UE9V9Hm6Zuytqy1AkjkTER1R8S+hxy4k8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726127AbgKFF0E convert rfc822-to-8bit (ORCPT ); Fri, 6 Nov 2020 00:26:04 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:61774 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725979AbgKFF0E (ORCPT ); Fri, 6 Nov 2020 00:26:04 -0500 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.42/8.16.0.42) with SMTP id 0A65Q23F002641 for ; Thu, 5 Nov 2020 21:26:02 -0800 Received: from maileast.thefacebook.com ([163.114.130.16]) by m0089730.ppops.net with ESMTP id 34m5r17tek-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 05 Nov 2020 21:26:02 -0800 Received: from intmgw001.08.frc2.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 5 Nov 2020 21:26:02 -0800 Received: by devbig012.ftw2.facebook.com (Postfix, from userid 137359) id 094DB2EC8EF6; Thu, 5 Nov 2020 21:26:00 -0800 (PST) From: Andrii Nakryiko To: , , CC: , Subject: [PATCH dwarves 4/4] btf: add support for split BTF loading and encoding Date: Thu, 5 Nov 2020 21:25:49 -0800 Message-ID: <20201106052549.3782099-5-andrii@kernel.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201106052549.3782099-1-andrii@kernel.org> References: <20201106052549.3782099-1-andrii@kernel.org> X-FB-Internal: Safe X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-06_01:2020-11-05,2020-11-06 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 spamscore=0 adultscore=0 priorityscore=1501 lowpriorityscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 phishscore=0 mlxscore=0 clxscore=1015 impostorscore=0 suspectscore=2 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011060037 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Add support for generating split BTF, in which there is a designated base BTF, containing a base set of types, and a split BTF, which extends main BTF with extra types, that can reference types and strings from the main BTF. This is going to be used to generate compact BTFs for kernel modules, with vmlinux BTF being a main BTF, which all kernel modules are based off of. These changes rely on patch set [0] to be present in libbpf submodule. [0] https://patchwork.kernel.org/project/netdevbpf/list/?series=377859&state=* Signed-off-by: Andrii Nakryiko --- btf_encoder.c | 3 ++- btf_loader.c | 2 +- libbtf.c | 10 ++++++---- libbtf.h | 4 +++- pahole.c | 23 +++++++++++++++++++++++ 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index b3e47f172bb3..d67e29b9cbee 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -12,6 +12,7 @@ #include "dwarves.h" #include "libbtf.h" #include "lib/bpf/include/uapi/linux/btf.h" +#include "lib/bpf/src/libbpf.h" #include "hash.h" #include "elf_symtab.h" #include "btf_encoder.h" @@ -343,7 +344,7 @@ int cu__encode_btf(struct cu *cu, int verbose, bool force, } if (!btfe) { - btfe = btf_elf__new(cu->filename, cu->elf); + btfe = btf_elf__new(cu->filename, cu->elf, base_btf); if (!btfe) return -1; diff --git a/btf_loader.c b/btf_loader.c index 6ea207ea65b4..ec286f413f36 100644 --- a/btf_loader.c +++ b/btf_loader.c @@ -534,7 +534,7 @@ struct debug_fmt_ops btf_elf__ops; int btf_elf__load_file(struct cus *cus, struct conf_load *conf, const char *filename) { int err; - struct btf_elf *btfe = btf_elf__new(filename, NULL); + struct btf_elf *btfe = btf_elf__new(filename, NULL, base_btf); if (btfe == NULL) return -1; diff --git a/libbtf.c b/libbtf.c index b6ddd7599395..3c52aa0d482b 100644 --- a/libbtf.c +++ b/libbtf.c @@ -27,6 +27,7 @@ #include "dwarves.h" #include "elf_symtab.h" +struct btf *base_btf; uint8_t btf_elf__verbose; uint8_t btf_elf__force; @@ -52,9 +53,9 @@ int btf_elf__load(struct btf_elf *btfe) /* free initial empty BTF */ btf__free(btfe->btf); if (btfe->raw_btf) - btfe->btf = btf__parse_raw(btfe->filename); + btfe->btf = btf__parse_raw_split(btfe->filename, btfe->base_btf); else - btfe->btf = btf__parse_elf(btfe->filename, NULL); + btfe->btf = btf__parse_elf_split(btfe->filename, btfe->base_btf); err = libbpf_get_error(btfe->btf); if (err) @@ -63,7 +64,7 @@ int btf_elf__load(struct btf_elf *btfe) return 0; } -struct btf_elf *btf_elf__new(const char *filename, Elf *elf) +struct btf_elf *btf_elf__new(const char *filename, Elf *elf, struct btf *base_btf) { struct btf_elf *btfe = zalloc(sizeof(*btfe)); GElf_Shdr shdr; @@ -77,7 +78,8 @@ struct btf_elf *btf_elf__new(const char *filename, Elf *elf) if (btfe->filename == NULL) goto errout; - btfe->btf = btf__new_empty(); + btfe->base_btf = base_btf; + btfe->btf = btf__new_empty_split(base_btf); if (libbpf_get_error(btfe->btf)) { fprintf(stderr, "%s: failed to create empty BTF.\n", __func__); goto errout; diff --git a/libbtf.h b/libbtf.h index 887b5bc55c8e..71f6cecbea93 100644 --- a/libbtf.h +++ b/libbtf.h @@ -27,8 +27,10 @@ struct btf_elf { uint32_t percpu_shndx; uint64_t percpu_base_addr; struct btf *btf; + struct btf *base_btf; }; +extern struct btf *base_btf; extern uint8_t btf_elf__verbose; extern uint8_t btf_elf__force; #define btf_elf__verbose_log(fmt, ...) { if (btf_elf__verbose) printf(fmt, __VA_ARGS__); } @@ -39,7 +41,7 @@ struct cu; struct base_type; struct ftype; -struct btf_elf *btf_elf__new(const char *filename, Elf *elf); +struct btf_elf *btf_elf__new(const char *filename, Elf *elf, struct btf *base_btf); void btf_elf__delete(struct btf_elf *btf); int32_t btf_elf__add_base_type(struct btf_elf *btf, const struct base_type *bt, diff --git a/pahole.c b/pahole.c index bd9b993777ee..d18092c1212c 100644 --- a/pahole.c +++ b/pahole.c @@ -22,12 +22,15 @@ #include "dutil.h" #include "ctf_encoder.h" #include "btf_encoder.h" +#include "libbtf.h" +#include "lib/bpf/src/libbpf.h" static bool btf_encode; static bool ctf_encode; static bool first_obj_only; static bool skip_encoding_btf_vars; static bool btf_encode_force; +static const char *base_btf_file; static uint8_t class__include_anonymous; static uint8_t class__include_nested_anonymous; @@ -820,6 +823,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version; #define ARGP_skip_encoding_btf_vars 317 #define ARGP_btf_encode_force 318 #define ARGP_just_packed_structs 319 +#define ARGP_btf_base 320 static const struct argp_option pahole__options[] = { { @@ -1093,6 +1097,12 @@ static const struct argp_option pahole__options[] = { .key = ARGP_hex_fmt, .doc = "Print offsets and sizes in hexadecimal", }, + { + .name = "btf_base", + .key = ARGP_btf_base, + .arg = "SIZE", + .doc = "Path to the base BTF file", + }, { .name = "btf_encode", .key = 'J', @@ -1234,6 +1244,9 @@ static error_t pahole__options_parser(int key, char *arg, skip_encoding_btf_vars = true; break; case ARGP_btf_encode_force: btf_encode_force = true; break; + case ARGP_btf_base: + base_btf_file = arg; + break; default: return ARGP_ERR_UNKNOWN; } @@ -2682,6 +2695,15 @@ int main(int argc, char *argv[]) goto out; } + if (base_btf_file) { + base_btf = btf__parse(base_btf_file, NULL); + if (libbpf_get_error(base_btf)) { + fprintf(stderr, "Failed to parse base BTF '%s': %ld\n", + base_btf_file, libbpf_get_error(base_btf)); + goto out; + } + } + struct cus *cus = cus__new(); if (cus == NULL) { fputs("pahole: insufficient memory\n", stderr); @@ -2766,6 +2788,7 @@ out_cus_delete: #ifdef DEBUG_CHECK_LEAKS cus__delete(cus); structures__delete(); + btf__free(base_btf); #endif out_dwarves_exit: #ifdef DEBUG_CHECK_LEAKS