From patchwork Thu Mar 25 06:53:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonghong Song X-Patchwork-Id: 12163137 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=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,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 33DDDC433E4 for ; Thu, 25 Mar 2021 06:54:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 03EE761A21 for ; Thu, 25 Mar 2021 06:54:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229547AbhCYGxy (ORCPT ); Thu, 25 Mar 2021 02:53:54 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:60754 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229662AbhCYGxd (ORCPT ); Thu, 25 Mar 2021 02:53:33 -0400 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 12P6i8MG012094 for ; Wed, 24 Mar 2021 23:53:33 -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=MBeP5zF/AXazYMbbkVm421GWjxInhr5Fh1zvcgIM5Ng=; b=p1QceDf4Frunouqan3UHdfYbeHPe1KXofo1HFH+gwecHap6ekjQJJLjwY8rDzdJuSotO SVeqfSfNJKoGT10CcCWjdaqatN2EU4Y8OIkX6UPtO+yK3fT/kJ8crTjWds8nMYaWISzA aBD5v6LnfejPzTlmM9rtfq4eE2M5esvq38o= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 37fn33tm64-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 24 Mar 2021 23:53:32 -0700 Received: from intmgw001.25.frc3.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:11d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 24 Mar 2021 23:53:31 -0700 Received: by devbig003.ftw2.facebook.com (Postfix, from userid 128203) id 5296AAE26C7; Wed, 24 Mar 2021 23:53:27 -0700 (PDT) From: Yonghong Song To: Arnaldo Carvalho de Melo , CC: Alexei Starovoitov , Andrii Nakryiko , Bill Wendling , , Subject: [PATCH dwarves 2/3] dwarf_loader: factor out common code to initialize a cu Date: Wed, 24 Mar 2021 23:53:27 -0700 Message-ID: <20210325065327.3122071-1-yhs@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210325065316.3121287-1-yhs@fb.com> References: <20210325065316.3121287-1-yhs@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.369,18.0.761 definitions=2021-03-25_01:2021-03-24,2021-03-25 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 bulkscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=999 phishscore=0 spamscore=0 suspectscore=0 adultscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2103250049 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Both cus__load_debug_types() and cus__load_module() created new cu's followed by initialization. The initialization codes are identical so let us refactor into a common function which can be used later as well when dealing with merging cu's. Signed-off-by: Yonghong Song --- dwarf_loader.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index a02ef23..dc66df0 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -2411,6 +2411,23 @@ static int finalize_cu_immediately(struct cus *cus, struct cu *cu, return lsk; } +static int cu__set_common(struct cu *cu, struct conf_load *conf, + Dwfl_Module *mod, Elf *elf) +{ + cu->uses_global_strings = true; + cu->elf = elf; + cu->dwfl = mod; + cu->extra_dbg_info = conf ? conf->extra_dbg_info : 0; + cu->has_addr_info = conf ? conf->get_addr_info : 0; + + GElf_Ehdr ehdr; + if (gelf_getehdr(elf, &ehdr) == NULL) + return DWARF_CB_ABORT; + + cu->little_endian = ehdr.e_ident[EI_DATA] == ELFDATA2LSB; + return 0; +} + static int cus__load_debug_types(struct cus *cus, struct conf_load *conf, Dwfl_Module *mod, Dwarf *dw, Elf *elf, const char *filename, @@ -2434,22 +2451,11 @@ static int cus__load_debug_types(struct cus *cus, struct conf_load *conf, cu = cu__new("", pointer_size, build_id, build_id_len, filename); - if (cu == NULL) { + if (cu == NULL || + cu__set_common(cu, conf, mod, elf) != 0) { return DWARF_CB_ABORT; } - cu->uses_global_strings = true; - cu->elf = elf; - cu->dwfl = mod; - cu->extra_dbg_info = conf ? conf->extra_dbg_info : 0; - cu->has_addr_info = conf ? conf->get_addr_info : 0; - - GElf_Ehdr ehdr; - if (gelf_getehdr(elf, &ehdr) == NULL) { - return DWARF_CB_ABORT; - } - cu->little_endian = ehdr.e_ident[EI_DATA] == ELFDATA2LSB; - if (dwarf_cu__init(dcup) != 0) return DWARF_CB_ABORT; @@ -2528,19 +2534,8 @@ static int cus__load_module(struct cus *cus, struct conf_load *conf, const char *name = attr_string(cu_die, DW_AT_name); struct cu *cu = cu__new(name ?: "", pointer_size, build_id, build_id_len, filename); - if (cu == NULL) - return DWARF_CB_ABORT; - cu->uses_global_strings = true; - cu->elf = elf; - cu->dwfl = mod; - cu->extra_dbg_info = conf ? conf->extra_dbg_info : 0; - cu->has_addr_info = conf ? conf->get_addr_info : 0; - - GElf_Ehdr ehdr; - if (gelf_getehdr(elf, &ehdr) == NULL) { + if (cu == NULL || cu__set_common(cu, conf, mod, elf) != 0) return DWARF_CB_ABORT; - } - cu->little_endian = ehdr.e_ident[EI_DATA] == ELFDATA2LSB; struct dwarf_cu dcu;