From patchwork Wed Oct 27 23:08:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonghong Song X-Patchwork-Id: 12588957 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9F89C433FE for ; Wed, 27 Oct 2021 23:08:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B3EE960F56 for ; Wed, 27 Oct 2021 23:08:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230233AbhJ0XLH (ORCPT ); Wed, 27 Oct 2021 19:11:07 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:34158 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230228AbhJ0XLH (ORCPT ); Wed, 27 Oct 2021 19:11:07 -0400 Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19RLfRY2013692 for ; Wed, 27 Oct 2021 16:08:41 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=facebook; bh=yV9eNydbtuV4V15vifsf21aUybt3/ZVpH/BundjH2hk=; b=gKTe8Fw+9mWGiSZM79Xp3ZLhhePSh7FoBHFPxiY7gCvKoujZWLEaFambphed6wedTx7C W5Jcy+6EgkGkqWxTNVvfUQmEehjsV/T3S1pyydxxDFLK2pOz9Te/0mO2LcFviGe+uQRc kEJQrFtHJ/EmJPKRzctk7pM1O57+Iem5MNc= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 3by64s6u4d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 27 Oct 2021 16:08:41 -0700 Received: from intmgw001.05.ash7.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::e) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Wed, 27 Oct 2021 16:08:40 -0700 Received: by devbig309.ftw3.facebook.com (Postfix, from userid 128203) id 7AA3E19948C9; Wed, 27 Oct 2021 16:08:28 -0700 (PDT) From: Yonghong Song To: Arnaldo Carvalho de Melo , CC: Alexei Starovoitov , Andrii Nakryiko , , Daniel Borkmann , Subject: [PATCH dwarves 1/2] dwarf_loader: support typedef DW_TAG_LLVM_annotation Date: Wed, 27 Oct 2021 16:08:28 -0700 Message-ID: <20211027230828.2465451-1-yhs@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211027230822.2465100-1-yhs@fb.com> References: <20211027230822.2465100-1-yhs@fb.com> X-FB-Internal: Safe X-FB-Source: Intern X-Proofpoint-ORIG-GUID: 2VAwgRC7REi7313L0FAbAz2rloG7ejpd X-Proofpoint-GUID: 2VAwgRC7REi7313L0FAbAz2rloG7ejpd X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-10-27_06,2021-10-26_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 impostorscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 malwarescore=0 spamscore=0 suspectscore=0 clxscore=1015 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2110270128 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org llvm commit ([1]) added support for btf_decl_tag attribute with typedef declaration. Eventually, DW_TAG_LLVM_annotation tag may appear inside dwarf typedef declaration tag. kernel support for typedef BTF_KIND_DECL_TAG support is introduced in [2]. There is no additional libbpf change needed as the previous libbpf BTF_KIND_DECL_TAG support is generic enough to cover new typedef use cases. This patch added parsing of DW_TAG_LLVM_annotation for dwarf typedef decl. $ cat t.c $ clang -O2 -g -c t.c $ llvm-dwarfdump --debug-info t.o ...... 0x00000033: DW_TAG_typedef DW_AT_type (0x00000051 "structure ") DW_AT_name ("__t") DW_AT_decl_file ("/home/yhs/t.c") DW_AT_decl_line (3) 0x0000003e: DW_TAG_LLVM_annotation DW_AT_name ("btf_decl_tag") DW_AT_const_value ("tag1") 0x00000047: DW_TAG_LLVM_annotation DW_AT_name ("btf_decl_tag") DW_AT_const_value ("tag2") 0x00000050: NULL Previously, pahole will issue a warning if typedef tag contains any child tag. I removed this warning since it is not true any more. Note that dwarf standard doesn't prevent typedef decl tag from having nested tags. In the future if we need to process any tag inside typedef tag, we can just add code to process it. [1] https://reviews.llvm.org/D110127 [2] https://lore.kernel.org/bpf/20211021195628.4018847-1-yhs@fb.com Signed-off-by: Yonghong Song --- dwarf_loader.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index c5bda81..f748bd7 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -1296,11 +1296,8 @@ static struct tag *die__create_new_typedef(Dwarf_Die *die, struct cu *cu, struct if (tdef == NULL) return NULL; - if (dwarf_haschildren(die)) { - struct dwarf_tag *dtag = tdef->namespace.tag.priv; - fprintf(stderr, "%s: DW_TAG_typedef %llx WITH children!\n", - __func__, (unsigned long long)dtag->id); - } + if (add_child_llvm_annotations(die, -1, conf, &tdef->namespace.annots)) + return NULL; return &tdef->namespace.tag; } From patchwork Wed Oct 27 23:08:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonghong Song X-Patchwork-Id: 12588959 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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28F65C433EF for ; Wed, 27 Oct 2021 23:08:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0854361039 for ; Wed, 27 Oct 2021 23:08:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230228AbhJ0XLI (ORCPT ); Wed, 27 Oct 2021 19:11:08 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:35094 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230230AbhJ0XLH (ORCPT ); Wed, 27 Oct 2021 19:11:07 -0400 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.1.2/8.16.1.2) with SMTP id 19RLfSbD016123 for ; Wed, 27 Oct 2021 16:08:41 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=mRfG9ZTu3I6BiGRcCEkwvNsDMruNfQNKCtrp7lwQXcQ=; b=nkApurSLwZMQrm1B4osTXg+3OkoQTbbGiGZOrrtFsIfIf6oyHJe9YE5AsrglYctRv+ag NJUABLLfoUorAd547yZjFfjfSI/dWD/5C42ij5zpvimtts00Po+yjBEpkQkfelgBKLKy j1i1x8hAsyVSGrQJBCbaOjj6HnIAJUtows0= Received: from mail.thefacebook.com ([163.114.132.120]) by m0089730.ppops.net with ESMTP id 3by64p6na3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 27 Oct 2021 16:08:41 -0700 Received: from intmgw001.06.ash9.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:11d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Wed, 27 Oct 2021 16:08:39 -0700 Received: by devbig309.ftw3.facebook.com (Postfix, from userid 128203) id 3097F19948E7; Wed, 27 Oct 2021 16:08:34 -0700 (PDT) From: Yonghong Song To: Arnaldo Carvalho de Melo , CC: Alexei Starovoitov , Andrii Nakryiko , , Daniel Borkmann , Subject: [PATCH dwarves 2/2] btf_encoder: generate BTF_KIND_DECL_TAGs for typedef btf_decl_tag attributes Date: Wed, 27 Oct 2021 16:08:34 -0700 Message-ID: <20211027230834.2466282-1-yhs@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211027230822.2465100-1-yhs@fb.com> References: <20211027230822.2465100-1-yhs@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-FB-Source: Intern X-Proofpoint-ORIG-GUID: RRjFccpwBp_2IC1CURAm9EHSzsacY-wo X-Proofpoint-GUID: RRjFccpwBp_2IC1CURAm9EHSzsacY-wo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-10-27_06,2021-10-26_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 lowpriorityscore=0 suspectscore=0 phishscore=0 bulkscore=0 clxscore=1015 priorityscore=1501 impostorscore=0 mlxscore=0 mlxlogscore=823 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2110270128 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Emit BTF BTF_KIND_DECL_TAGs for btf_decl_tag attributes attached to typedef declarations. The following is a simple example: $ cat t.c #define __tag1 __attribute__((btf_decl_tag("tag1"))) #define __tag2 __attribute__((btf_decl_tag("tag2"))) typedef struct { int a; int b; } __t __tag1 __tag2; __t g; $ clang -O2 -g -c t.c $ pahole -JV t.o btf_encoder__new: 't.o' doesn't have '.data..percpu' section Found 0 per-CPU variables! File t.o: [1] TYPEDEF __t type_id=2 [2] STRUCT (anon) size=8 a type_id=3 bits_offset=0 b type_id=3 bits_offset=32 [3] INT int size=4 nr_bits=32 encoding=SIGNED [4] DECL_TAG tag1 type_id=1 component_idx=-1 [5] DECL_TAG tag2 type_id=1 component_idx=-1 Signed-off-by: Yonghong Song --- btf_encoder.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 40f6aa3..2f1f4ae 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -1437,19 +1437,25 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu) } cu__for_each_type(cu, core_id, pos) { + const char *tag_name = "typedef"; struct namespace *ns; - if (pos->tag != DW_TAG_structure_type && pos->tag != DW_TAG_union_type) + if (pos->tag != DW_TAG_structure_type && pos->tag != DW_TAG_union_type && + pos->tag != DW_TAG_typedef) continue; + if (pos->tag == DW_TAG_structure_type) + tag_name = "struct"; + else if (pos->tag == DW_TAG_union_type) + tag_name = "union"; + btf_type_id = type_id_off + core_id; ns = tag__namespace(pos); list_for_each_entry(annot, &ns->annots, node) { tag_type_id = btf_encoder__add_decl_tag(encoder, annot->value, btf_type_id, annot->component_idx); if (tag_type_id < 0) { fprintf(stderr, "error: failed to encode tag '%s' to %s '%s' with component_idx %d\n", - annot->value, pos->tag == DW_TAG_structure_type ? "struct" : "union", - namespace__name(ns), annot->component_idx); + annot->value, tag_name, namespace__name(ns), annot->component_idx); goto out; } }