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; } }