From patchwork Wed Nov 3 13:58:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jose E. Marchesi" X-Patchwork-Id: 46989 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 817D23858005 for ; Wed, 3 Nov 2021 13:58:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 817D23858005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1635947916; bh=T1YpL77PqfzQUlMcjxygkUXIellUzO9F32BwYkZ9hsg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:From; b=PbQXSFsCgd8diMws2MehDZ+FG0iNLMkA9anHy5nX1meXYp/h6WyEvHaFWdWvgCXvd abVFVkH3T5zz40lf7sh/BzjyvGSbe+rpxH1SDJvqT4oPEMll+4CfdH2mpEpSWajFg7 u7sHpSs8jU2ja1qm4uloTbmnQzImeHyA1ndA5SRY= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 6F4503858405 for ; Wed, 3 Nov 2021 13:58:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6F4503858405 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1A3DfMGH020534 for ; Wed, 3 Nov 2021 13:58:30 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3c3n9xj0nc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 03 Nov 2021 13:58:29 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1A3DeOi6166709 for ; Wed, 3 Nov 2021 13:58:28 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2101.outbound.protection.outlook.com [104.47.70.101]) by userp3020.oracle.com with ESMTP id 3c1khvk5xs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 03 Nov 2021 13:58:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OR9vGn38t/zZvJXnKsGbTe8eaMiBuLRDBuMSs7Mx/EwQpuHwjy40IqsHNwCrQ8bsAGrKQNB+rZ1UgDRY+svat1/OHpuppkM8kDwdKF/zk0JmXq4GpPJvhel2PiqRcobQstAr2VQm9Z1kHh9tX69er6VtqJl8Yst612HxMDnmehYnKMr7UO6L7j1CIBWJca483O2FWljZLVmZnRj0JndJIbBI92EdjjHHmaNDCB1U4rBS9JOSPA1DavCviByDPcE5X1FS83/9MkbVRYYNsYRhrPnnIGTkhJ3l0hfOX/B4mq5uQujxMswFLPmWLLhU1wTNHCZXMwf/3lCgGP71Jb7z7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=T1YpL77PqfzQUlMcjxygkUXIellUzO9F32BwYkZ9hsg=; b=dr2LsulrjJSA3MRI+F9PoY4HXRXtn3Kk3MPRr2J90x/+Ljw2T4baicFtmDUohY1yZpBwflnisjdfnaLpuhh6zWYEYnrjcl6vECfI7EtcV7tch0lFJHwJ8JSA+Oidwk76eOGQuifbQsRS1N6Ibsu3M4d433iWpAc1N6rXrTZR4MLuVuoL2r2ZxOqal383dRQ0ukQ+RaS2clAL3hi+YHyqbdSKrzFIwpMmzOgRcP16FxicJn8eT1QDvqq0ISpyJbyrNY3drwFOWOhW+938DQuZ58Afhki4TREeUXXwRChlADRBU4LClrKO8TkZWQkVbF2OhQYCmxXJMhrh0wlh4yHiIw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) by SJ0PR10MB5519.namprd10.prod.outlook.com (2603:10b6:a03:3fa::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11; Wed, 3 Nov 2021 13:58:26 +0000 Received: from BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::48bf:86b4:32e1:6574]) by BYAPR10MB2888.namprd10.prod.outlook.com ([fe80::48bf:86b4:32e1:6574%4]) with mapi id 15.20.4649.019; Wed, 3 Nov 2021 13:58:26 +0000 To: libabigail@sourceware.org Subject: [PATCH V2] ctf: make libabigail::ctf_reader::read_corpus reentrant Date: Wed, 3 Nov 2021 14:58:20 +0100 Message-Id: <20211103135820.6233-1-jose.marchesi@oracle.com> X-Mailer: git-send-email 2.11.0 X-ClientProxiedBy: LO4P123CA0104.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:191::19) To BYAPR10MB2888.namprd10.prod.outlook.com (2603:10b6:a03:88::32) MIME-Version: 1.0 Received: from termi.localdomain (141.143.193.71) by LO4P123CA0104.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:191::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.10 via Frontend Transport; Wed, 3 Nov 2021 13:58:25 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 49f86463-543b-4754-1c05-08d99ed201dd X-MS-TrafficTypeDiagnostic: SJ0PR10MB5519: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1186; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mqFIqPzldK55PGdj0Y3BFw8eJZUMNaI7mpZjy16DudcmbJ2spR3yCNGBKdCWBFFlQzqQrf6UF+vwRCOEBCX1JVaGZeijXgaR9OWItXZ4CLJz7E1JF7dr81PfLv+Qw2GjCgedH8qg72M1nHXoQ4ozuLyiONQ71CRQol/RqNW8DFVXZ75F5/ofXXIgXV2XblCw+qnYx+4RJkoWvRHo5hUwljLyLQlSd4KJFZrFQRX8Zwurz9vg8WRd0W5pxag+ka8CquP57MniJUJCWSgrI+oIUT6luJI+pcH1eS18pzhDQRvK5S2fEBTL9UVCVjqVrQaogdvSUKHphTVDodMZUOa/U369qtlA90AHXtUmOMEt/l/PvoRaE3RdzzXXrZpbjaT72IJRmTdIFsyc7JodJglE3at40yFluxrX/LW19Y80eKul6n4536EdvU44g2rkGZDnjA9FkDEg0Ec7Dp9q2EAYowUtICk7OXeOpuFuWeV3TK8o7raZ8q33Wum+oD5HMkNTTdTZqUqNlWV0jEioy7BgpSsIKL9yr0UBjRwXZrDdA1rQxm1WGCkMFRdWVVudMpSAdQ2PaWk6HMWJDiFLW+kMjoifAlsfbQXJAy0EYpExTrNRe2X2WQQniycCKkgNEdYgIrMGjZ08Jp2iv06H9kgfq1uUNdEtekkqaCjrgjR88rKBQxund6J3py2EhgWBbQ0KZnTFf7kro+2155cpg3dLrg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB2888.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(6512007)(66556008)(6916009)(26005)(83380400001)(66476007)(8936002)(36756003)(956004)(5660300002)(86362001)(8676002)(2616005)(6486002)(66946007)(52116002)(38100700002)(6666004)(38350700002)(1076003)(2906002)(508600001)(6506007)(316002)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: z2NVfK2wpZOwpf7J2KYmLp+4JS6IVtT7TLQ1ZIxVWyxBtMq7pepJQUzRjquckVS/ulP/PAUBOnBxN2jLxc4AN4k/HiRPlppJ+EFHxEq+9Z7eK0wm9moqX9/yxcvVTetgHPaGoDie2W8XbCNkv8aDZPcSVNtqaf169y8Z9dpE6bl55nsFdvVvWRaRXZ22jvEIIo2BdTKmJqOcovYNMJPXds7PrGdhYGvcCb9G8F2NqNzqsRs2oQJf9tcdu5I1WtBp8kgHPAdcE3pQDfMaHBevHkDeNylqs48kpl+crhwAzB1l0eZbD0K5+F2ffwLNpYKFFXBWzNQB+pE/dbS6RQoq3WvU9wacza+TGjzy5r5CHc72LgyC6ZwmdaFpl3wRzYxpTHOnKfzy7hntJPFaM1K9rcmMnHI7QwbJcph2DHdksU9cpGsKaTtytejB7dUC1nnDDHpGDSYnOd0jCfzrSRbkJFVuAaP0aDOaJhZVux7w++UrHZUtNhTvulGcRQ7xsBtHqvkIOn60ucK4MukiS2H/cgb8o4QYU3nOAGTUJNiJ+dNXyBWIVdCDHCJi3eiJU0W+1cjPL4I3bdRv3dm4p9IMHLwlLQ40LAp2xE5K/9kznz5lcdDUpYIrtwtBnSivHc1QNfpom3aNtYHaLJcCYx5DMDPVmUe9RXYrMXvLh6k+rbx2nq6fkB3seAlw7eXrJSvqCJfor2pR9xuYA7SzXjrofSf2TbJJ1/PsofDTjpETT4qOPqwcIVCPCUVbhXjC7N3bxYmpDV2mI0ZxHvZmQ23PzUNUIezDG3iuVuYgVvPfXP6CK1zE/uud2EilVLFEtw08Vo6llV+41nt4eYOzMjNsUZHyt4OOA1uDHjXR/uSz9AgSPE3WOl59up47AZb6/QO1pLxPfMdGeHjpqvCgf6ETsmR2kbzC9XB7XVnUC7DJRfMY2DgnRbNq07+9yufOoatnPHVFNY9GQAh3qIxI1xPZDj4NR25hlLicA3m99xx3RkjITXlP5Bwe++UgYK4+Wb2DKTMBl9yertlfqe5GyckbxoX1xhxeg35Qr7srgJm+8a9M6AjTntTDjqBbxG1TubG8blC1VCmFFkOOZvgmh5ZtGFKZLvIlbitsZ9CpZ8kqvMK0M4e317EIrjg/bOID/BTvcOISH7MoWYv7fTkv7cVswik6fhVMtpBFLxkPoM0x7sFu+XJVb0YED/GHvTpFQIJ7hxSVCqyxqtTJNnZmhE4fZIiIJFa0GdjqLggZRrZ7Ke1fBC3ULaDidSWQGflO/ra8OUpvTSdKxpy3epLZ7sKU5jQcKz7/SWEfo9h/udu1+4l7yLORLRjfSi/hQVL3rZb1RyrOsC34NOM1pU5IpM4khQNeXk6hyCKae2t9Rr2PPIsT77g+dbC4rGWtcVeLyZfP7KZDLC5w/bMVomMi76bRMBEAkcTm93QiBEgbX51tIzggqYZlu/IE/qTMvMCfFFGa7qvP4jXGXcsKwWgBH+XR4wk2WNKq+3MbBnK7luK9lspjMcsSSG1SSu68ScfxpqKyki55mZSYmoMgGEjKFYwJRI+Oo2us9b5r8P6ADMiTfF5TvRkhAqauOZ5x/I2cEB0UYajTXxJ4qMPOC5MsZrG1iSnWLMVG+rdtYdjKj0XaGiGqkOYIGqDdPwz8iz777stsks89NbSAwWcjFQR0WAAj/g== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 49f86463-543b-4754-1c05-08d99ed201dd X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB2888.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Nov 2021 13:58:26.3842 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SP85pbjLnh/FYySd0ueNLzL2rqXF5fqaYZcZ7ma5o4pO2v04wvsTJH5Z6qsvrjMuLo35nSlVTU9mOQMCcV5Sy32iPbcpSuRFQyi22wvIa64= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5519 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10156 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111030079 X-Proofpoint-ORIG-GUID: sZzN1QNsJtt05vvjVv34y62DSN_sHQpr X-Proofpoint-GUID: sZzN1QNsJtt05vvjVv34y62DSN_sHQpr X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: "Jose E. Marchesi via Libabigail" From: "Jose E. Marchesi" Reply-To: "Jose E. Marchesi" Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" [Changes from V1: - Make sure that the string table passed to libctf is the one related to the symbol table.] The libctf call ctf_open is not reentrant. This is because it uses bfd_open (and other BFD calls) internally in order to fetch the different bits of CTF from the ELF file. This is unfortunate, as it makes libabigail::ctf_reader::read_corpus non-reentrant. We detected this problem thanks to one of the libabigail test driver, that exercises tests in parallel using threads. Fortunately libctf provides an alternate way to decode CTF data, that involves the user to provide the raw contents of the relevant ELF sections (.ctf, the symtab, the string table) to ctf_arc_bufopen call. This patch changes the CTF reader in libabigail to use this mechanism. libelf is used in order to extract the contents of these sections. * src/abg-ctf-reader.cc (class read_context): New attributes elf_handler, elf_fd, ctf_sect, symtab_sec and strtab_sect. (read_context): Do not read the CTF archive here. (slurp_elf_info): Adjust to use attributes instead of locals, and fetch the raw ELF section contents for libctf. (close_elf_handler): New function. (fill_ctf_section): Likewise. (read_corpus): Call open_elf_handler, close_elf_handler and build the CTF archive using ctf_arc_bufopen instead of ctf_open. Signed-by: Jose E. Marchesi Signed-off-by: Dodji Seketeli Signed-off-by: Jose E. Marchesi --- src/abg-ctf-reader.cc | 143 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 112 insertions(+), 31 deletions(-) diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc index 1c41ea02..d107fac8 100644 --- a/src/abg-ctf-reader.cc +++ b/src/abg-ctf-reader.cc @@ -58,9 +58,20 @@ public: /// is used to reuse already generated types. unordered_map types_map; + /// libelf handler for the ELF file from which we read the CTF data, + /// and the corresponding file descriptor. + Elf *elf_handler; + int elf_fd; + /// The symtab read from the ELF file. symtab_reader::symtab_sptr symtab; + /// Raw contents of several sections from the ELF file. These are + /// used by libctf. + ctf_sect_t ctf_sect; + ctf_sect_t symtab_sect; + ctf_sect_t strtab_sect; + /// Associate a given CTF type ID with a given libabigail IR type. void add_type(ctf_id_t ctf_type, type_base_sptr type) { @@ -93,15 +104,12 @@ public: /// @param elf_path the path to the ELF file. read_context(string elf_path, ir::environment *env) { - int err; - types_map.clear(); filename = elf_path; ir_env = env; - ctfa = ctf_open(filename.c_str(), NULL /* BFD target */, &err); - - if (ctfa == NULL) - fprintf(stderr, "cannot open %s: %s\n", filename.c_str(), ctf_errmsg(err)); + elf_handler = NULL; + elf_fd = -1; + ctfa = NULL; } /// Destructor of the @ref read_context type. @@ -939,50 +947,115 @@ process_ctf_archive(read_context *ctxt, corpus_sptr corp) } -/// Slurp certain information from the ELF file described by a given -/// read context and install it in a libabigail corpus. -/// -/// @param ctxt the read context -/// @param corp the libabigail corpus in which to install the info. +/// Open the ELF file described by the given read context. /// -/// @return 0 if there is an error. +/// @param ctxt the read context. +/// @return 0 if the ELF file can't be opened. /// @return 1 otherwise. static int -slurp_elf_info(read_context *ctxt, corpus_sptr corp) +open_elf_handler (read_context *ctxt) { /* libelf requires to negotiate/set the version of ELF. */ if (elf_version(EV_CURRENT) == EV_NONE) return 0; /* Open an ELF handler. */ - int elf_fd = open(ctxt->filename.c_str(), O_RDONLY); - if (elf_fd == -1) + ctxt->elf_fd = open(ctxt->filename.c_str(), O_RDONLY); + if (ctxt->elf_fd == -1) return 0; - Elf *elf_handler = elf_begin(elf_fd, ELF_C_READ, NULL); - if (elf_handler == NULL) + ctxt->elf_handler = elf_begin(ctxt->elf_fd, ELF_C_READ, NULL); + if (ctxt->elf_handler == NULL) { fprintf(stderr, "cannot open %s: %s\n", ctxt->filename.c_str(), elf_errmsg(elf_errno())); - close(elf_fd); + close(ctxt->elf_fd); return 0; } + return 1; +} + +/// Close the ELF file described by the given read context. +/// +/// @param ctxt the read context. + +static void +close_elf_handler (read_context *ctxt) +{ + /* Finish the ELF handler and close the associated file. */ + elf_end(ctxt->elf_handler); + close(ctxt->elf_fd); +} + +/// Fill a CTF section description with the information in a given ELF +/// section. +/// +/// @param ctxt the read context. +/// @param elf_section the ELF section from which to get. +/// @param ctf_section the CTF section to fill with the raw data. + +static void +fill_ctf_section(read_context *ctxt, Elf_Scn *elf_section, ctf_sect_t *ctf_section) +{ + GElf_Shdr section_header_mem, *section_header; + Elf_Data *section_data; + + section_header = gelf_getshdr(elf_section, §ion_header_mem); + section_data = elf_getdata(elf_section, 0); + + ABG_ASSERT (section_header != NULL); + ABG_ASSERT (section_data != NULL); + + ctf_section->cts_name = ""; /* This is not actually used by libctf. */ + ctf_section->cts_data = (char *) section_data->d_buf; + ctf_section->cts_size = section_data->d_size; + ctf_section->cts_entsize = section_header->sh_entsize; +} + +/// Slurp certain information from the ELF file described by a given +/// read context and install it in a libabigail corpus. +/// +/// @param ctxt the read context +/// @param corp the libabigail corpus in which to install the info. +/// +/// @return 0 if there is an error. +/// @return 1 otherwise. + +static int +slurp_elf_info(read_context *ctxt, corpus_sptr corp) +{ /* Set the ELF architecture. */ GElf_Ehdr eh_mem; - GElf_Ehdr *ehdr = gelf_getehdr(elf_handler, &eh_mem); + GElf_Ehdr *ehdr = gelf_getehdr(ctxt->elf_handler, &eh_mem); corp->set_architecture_name(elf_helpers::e_machine_to_string(ehdr->e_machine)); /* Read the symtab from the ELF file and set it in the corpus. */ ctxt->symtab = - symtab_reader::symtab::load(elf_handler, ctxt->ir_env, + symtab_reader::symtab::load(ctxt->elf_handler, ctxt->ir_env, 0 /* No suppressions. */); corp->set_symtab(ctxt->symtab); - /* Finish the ELF handler and close the associated file. */ - elf_end(elf_handler); - close(elf_fd); + /* Get the raw ELF section contents for libctf. The .ctf section + and the symtab are straightforward enough. */ + Elf_Scn *ctf_scn = elf_helpers::find_section(ctxt->elf_handler, ".ctf", SHT_PROGBITS); + Elf_Scn *symtab_scn = elf_helpers::find_symbol_table_section(ctxt->elf_handler); + + if (ctf_scn == NULL || symtab_scn == NULL) + return 0; + + /* The string table that libctf expects is the one related to the + symbol table by virtue of sh_link. */ + GElf_Shdr symtab_shdr_mem, *symtab_shdr = gelf_getshdr(symtab_scn, &symtab_shdr_mem); + Elf_Scn *strtab_scn = elf_getscn(ctxt->elf_handler, symtab_shdr->sh_link); + + if (strtab_scn == NULL) + return 0; + + fill_ctf_section(ctxt, ctf_scn, &ctxt->ctf_sect); + fill_ctf_section(ctxt, symtab_scn, &ctxt->symtab_sect); + fill_ctf_section(ctxt, strtab_scn, &ctxt->strtab_sect); return 1; } @@ -1012,19 +1085,27 @@ read_corpus(read_context *ctxt) corpus_sptr corp = std::make_shared(ctxt->ir_env, ctxt->filename); + /* Open the ELF file. */ + if (!open_elf_handler(ctxt)) + return corp; + /* Set some properties of the corpus first. */ corp->set_origin(corpus::CTF_ORIGIN); if (!slurp_elf_info(ctxt, corp)) return corp; - /* Get out now if no CTF debug info is found. */ - if (ctxt->ctfa == NULL) - return corp; - - /* Process the CTF archive in the read context, if any. Information - about the types, variables, functions, etc contained in the - archive are added to the given corpus. */ - process_ctf_archive(ctxt, corp); + /* Build the cfta from the contents of the relevant ELF sections, + and process the CTF archive in the read context, if any. + Information about the types, variables, functions, etc contained + in the archive are added to the given corpus. */ + int errp; + ctxt->ctfa = ctf_arc_bufopen(&ctxt->ctf_sect, &ctxt->symtab_sect, + &ctxt->strtab_sect, &errp); + if (ctxt->ctfa != NULL) + process_ctf_archive(ctxt, corp); + + /* Cleanup and return. */ + close_elf_handler(ctxt); return corp; }