From patchwork Fri Oct 9 19:26:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 11827141 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 EE0AAC433E7 for ; Fri, 9 Oct 2020 19:26:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9BAAC22282 for ; Fri, 9 Oct 2020 19:26:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602271583; bh=yS6RKBxqsgnq6nsKoMaegkXKZ1OsoCl7jwv+FXdtnsI=; h=From:To:CC:Subject:Date:List-ID:From; b=gsAh9LAk+09Zw8qXGZnb7hDXEPndfdP15pKZC59aZzwWYs3tXmtQ3k4my+h8CgF1U iIofYrgT0G91McBeQ2wFRgTGjaVzDPUao/uVy0BHwG/X3Moc3KKQS+U77Olm8JZuTt p7QTRgxMQ9/LH6skVrFrPGRQOAalYMHJyXazUu/A= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388640AbgJIT0X convert rfc822-to-8bit (ORCPT ); Fri, 9 Oct 2020 15:26:23 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:58402 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731624AbgJIT0W (ORCPT ); Fri, 9 Oct 2020 15:26:22 -0400 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 099JPRO8024216 for ; Fri, 9 Oct 2020 12:26:20 -0700 Received: from mail.thefacebook.com ([163.114.132.120]) by m0089730.ppops.net with ESMTP id 3429gwdf0e-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 09 Oct 2020 12:26:20 -0700 Received: from intmgw003.03.ash8.facebook.com (2620:10d:c085:208::f) 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; Fri, 9 Oct 2020 12:26:19 -0700 Received: by devbig012.ftw2.facebook.com (Postfix, from userid 137359) id 0783F2EC7D45; Fri, 9 Oct 2020 12:26:18 -0700 (PDT) From: Andrii Nakryiko To: , CC: , , , Andrii Nakryiko Subject: [PATCH dwarves] btf_loader: handle union forward declaration properly Date: Fri, 9 Oct 2020 12:26:07 -0700 Message-ID: <20201009192607.699835-1-andrii@kernel.org> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-10-09_12:2020-10-09,2020-10-09 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 clxscore=1015 malwarescore=0 impostorscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2010090140 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Differentiate between struct and union forwards. For BTF_KIND_FWD this is determined by kflag. So teach btf_loader to use that bit to decide whether forward is for union or struct. Signed-off-by: Andrii Nakryiko --- N.B. This patch is based on top of tmp.libbtf_encoder branch. Also seems like non-forward declared union has a slightly different representation from struct (class). Not sure why it is so, but this change doesn't seem to break anything. --- btf_loader.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/btf_loader.c b/btf_loader.c index 9b5da3a4997a..0cb23967fec3 100644 --- a/btf_loader.c +++ b/btf_loader.c @@ -134,12 +134,13 @@ static struct type *type__new(uint16_t tag, strings_t name, size_t size) return type; } -static struct class *class__new(strings_t name, size_t size) +static struct class *class__new(strings_t name, size_t size, bool is_union) { struct class *class = tag__alloc(sizeof(*class)); + uint32_t tag = is_union ? DW_TAG_union_type : DW_TAG_structure_type; if (class != NULL) { - type__init(&class->type, DW_TAG_structure_type, name, size); + type__init(&class->type, tag, name, size); INIT_LIST_HEAD(&class->vtable); } @@ -228,7 +229,7 @@ static int create_members(struct btf_elf *btfe, const struct btf_type *tp, static int create_new_class(struct btf_elf *btfe, const struct btf_type *tp, uint32_t id) { - struct class *class = class__new(tp->name_off, tp->size); + struct class *class = class__new(tp->name_off, tp->size, false); int member_size = create_members(btfe, tp, &class->type); if (member_size < 0) @@ -313,7 +314,7 @@ static int create_new_subroutine_type(struct btf_elf *btfe, const struct btf_typ static int create_new_forward_decl(struct btf_elf *btfe, const struct btf_type *tp, uint32_t id) { - struct class *fwd = class__new(tp->name_off, 0); + struct class *fwd = class__new(tp->name_off, 0, btf_kind(tp)); if (fwd == NULL) return -ENOMEM;