From patchwork Sat May 7 01:50:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guillermo E. Martinez" X-Patchwork-Id: 53569 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 E05953857357 for ; Sat, 7 May 2022 01:50:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E05953857357 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1651888255; bh=jOy1T1Q3WzbNA0ppAvgzYNnMKlw64uivj04aUPGUBPo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:From; b=gMVQhK1jaW+dK2PeFKFvN3E7s3qMihlDhIULeUhAktSh1ZbOoYv86fn6LrlWQjODo CDsMIpkUBM5Xa3T4bPzneeDtrzFSChsmvUf05K6LhjH2VQQMqJjj6mrs9IkaLssXtL +f0sqy38eKWZbWJb5duihn6VL6i5ASB1VZinNWJE= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 636B03858C53 for ; Sat, 7 May 2022 01:50:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 636B03858C53 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2471hbc5024470 for ; Sat, 7 May 2022 01:50:47 GMT Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3fwfc0g07e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 07 May 2022 01:50:47 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 2471jUKx014426 for ; Sat, 7 May 2022 01:50:46 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam08lp2049.outbound.protection.outlook.com [104.47.73.49]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fwf7007k5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 07 May 2022 01:50:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VOamZj54cIqkcwhEVfIhVzRnYVP4KKDTxqxyDbD37n9IjKkDdHG64tiCJxj++Z8NnFGUAZMZEdMC7EO43kPgYiDnsBc1N4eQILUe5NuqNGaawNAeK7Lcb8r4ZhropB8sajqSjT11nt1IEWd1tlLr9fr6lqm4fmtv+6WAv9UW92nmdNcHiNnbDKPY2fRTkESQxgtu32Q6NzTSvzSSX3CDF/I0CuYKtGzWk2w+4mmrngdWGUrVM5fcOHapYKd4fFsQh6xodX8CEQebbRbFPxht60yN1aDsal02ixu/zqdSe+DKT2vbcPsom0rOMwFmftZNsjuqrdtbZakPniqasUmd6A== 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=jOy1T1Q3WzbNA0ppAvgzYNnMKlw64uivj04aUPGUBPo=; b=cwnfxxfmVLuXzXohwgEn/vxfMv2lsMjZKp0rK306YykD6nhxmmNanX4pOoDW8OiPNPBsM8R2GlAL8nDUH3lFe8gOVxP0AokwhE+wFfTSKvv9A08PW7bUZFfCAyMxlxl/M/bbCpBhPdEdjqU5EXsvMyiL9cz8wlairzJtCe6bj10mpxF5yUbH7yMlXU4/7Kto91C6HXQXF5KqDNS6meHojyS3/HCUXCioF9EBMOvh7Y02Qz/WImaprvWXowAdgG3s8cwzIgbnVXVsCN2NMRqZ5oGcv8UPogeVQceuzyGeBGprZS4DHqOR6b3F2rwjGSdMCms7bstKCsSYSkz1fN+s0g== 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 MWHPR10MB1407.namprd10.prod.outlook.com (2603:10b6:300:23::20) by BLAPR10MB5347.namprd10.prod.outlook.com (2603:10b6:208:328::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.20; Sat, 7 May 2022 01:50:44 +0000 Received: from MWHPR10MB1407.namprd10.prod.outlook.com ([fe80::c88b:fab4:f199:fc1b]) by MWHPR10MB1407.namprd10.prod.outlook.com ([fe80::c88b:fab4:f199:fc1b%4]) with mapi id 15.20.5227.021; Sat, 7 May 2022 01:50:44 +0000 To: libabigail@sourceware.org Subject: [PATCH] ctf-reader: CTF debug info for some symbols is not found Date: Fri, 6 May 2022 20:50:25 -0500 Message-Id: <20220507015025.1416958-1-guillermo.e.martinez@oracle.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: BYAPR07CA0086.namprd07.prod.outlook.com (2603:10b6:a03:12b::27) To MWHPR10MB1407.namprd10.prod.outlook.com (2603:10b6:300:23::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8af03ffa-3961-4043-a1c7-08da2fcbffa7 X-MS-TrafficTypeDiagnostic: BLAPR10MB5347:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DTLWhEdimANEbIWZPC/ooaKH+QCjm54Sm7rWL7Ig+39TYLMn+a4TSRPUHja8F+b7fbimW6vW6P2KeRN8WMSCXq7oUNjiwosEXVw7G+CkOdbpRIzDGTQSgsjVvw3hf9lokZtPmU7oX39YSkGuKdlgwwHdTZsB1UMGYlVq3rfgy0W656RQ78qV2+day4jpn/BwxqgpiLMlku+B4l+yOfg2HQ4rx27KJ3NGfPAYTZQR7wEV7vvbdz5VemgGZLbA9BGr7uK69Ffq92lhYjVF0+Yu/W2ucgMG4XhrPdmcCAMlzxEXq2AKvZZUE1B7SuzTFE53oM/nU0NddtcbZ2tKcLsvisWYiVBlF8264IRScjTxp39lt19KfGrt41SB5VM4FWlE0EajT9sh4uLn+I8iXasbGNNXvMlB3WK9AjesJqEQfm1W+JR5E7pZHJPozjQiahuuT5ehn610M/NyUIP5wa6tYRp7syw7eXrSLaDflhi1olsS5Ft5BvNKFzM71DySwufnylyVr26/ZCahD3HFnDcppnygNGiHdlfmYcbnD6qN5smgINYfe5R9PR0HxpYhV6ntkvyO+WBYqiRevOwuidDOxHet8PzPWZLNn4yxt9IfFRgbkMvdqd/ZARdpoZvYiDw14KZAjDyQJ1rqPTx2NKiIYO6WXx0ZMkD6YbFBIZOF5omHwR5zB0sWdTNz/hsHa1Seq/xvXGqH4hOo6QmfsUbclB86ZvGjIVuU5zQojxNF487ReLX5k5qkWTvsn++cynXWYBqlJg4qLMtIC/nqRJjKRQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR10MB1407.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(6506007)(6916009)(6512007)(6486002)(508600001)(6666004)(52116002)(2906002)(966005)(316002)(86362001)(38100700002)(103116003)(107886003)(36756003)(83380400001)(2616005)(8676002)(66476007)(66556008)(66946007)(1076003)(8936002)(4326008)(186003)(5660300002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: O6RFRuKOJc27RFEdaYjdeLejZn46009LHlcR8uDtEn19ZzI24uo5wY1NjhPvxPPpJDvws7Bej9dlnXRWqR2q8tEC5rRDEDP+VkBM6/l4DQ8IPbuP986o4jXgMo7AbdJRMneFcmT41gWql1eTDxaoA4+ZL7SELXYEf3N7HY8QbtOJMByx6uVs1dLQfvh7bH7XaThx9kWAVYZLtHE1jgRC3j5uqcB572lc8p0BbT6EuHBI+wPLOT+EnCrSodUQzRrS3o164DzPtWMZI1w/h34FvWskoFW5B7Av/nBZJMIGVKfCCZHre52Q36PiWmTVsqPRy7YR8j/9LpRfBQpJRzrDtrMVym2qeFp70aIogfgDmf/R8EUp9N8vZd/zAe15G3baJgunZuB7YB/y/EwBYbhvD/fvpCj+WzzOcTJc9UNA5RgSwZmgUPHW1BlgUwe4elohAdo2nP2Tlc4tBhzwnZmreZj8bf9yYoY2/ssm6JRxuAYaMGVJbUL/HYLEdJa5n2A9DmuJBdYGr0RbtxrfU0+2yY0Xw86uPzNJiqbWs9geqGYipb3MdvINRepZuDr40uRL+0gCcuTtJf1UJVEBJTpn7yEVGQUCHNZI58xNdWi3EKY2kig6KifKsMZhgcGOqoCEGSs//IluEfmC24GwRItqVb/ApIQl9u+UFa/XlB5OKfiSZRaCtPlXGe5H2hhM0EQKCsnmRWmxgNrAlA3WvCTCtmtBquCpnuwaaJL4IOZNWTLHCtIhgZTClrOiTsZuW7uQfKakCjX3Xyk1k78+Rt72gMv5OFpkBBZWj+eaaH+lMKy+r8f+pq0TsoLuV9w+McZD57Wx+5i+bKR8KkWysWEXfnOEx6rcqmt70fYkOVEyoTI7e7CPmN3jKzr/ozJm9vRPaI0vHqmO8oUm/u7QThgxMnbovrIUMxjaXSsWA5B064II/16hdhlSzL3j2PNZAg+7ooeWXoPIen1eE0wRpu/HS19OJy9ifVd/NCY6QK68CC0TJrbcBNf/Pj1c4KyN0a2JjJMPb2cbEYAXnLpqMMOa5kJMg5KDV1t1YCFVDMFQeEp0dNnAgMC6I4HBW8aZnyufmpfwiSCW60Y6AaA1RLa50lim5rDaqrM5TQYpPZZml98jtfwsph990RhuK8krh67xQInYG7QSbn+O+lUR7xar7JJbQTQicvZ5uat2jI38bFhfk6lOzMqS5vQRij/6DVTe/kjzHpCMThsf0uOHccw/ErPfCKZcnxwLnCydaRBB03deVc3AzcsWn3RFHfhqdLPxeOxP165aI4l2qX7qd3Qmxx9AOCaWXjMZ+PCHQZq46Wq/pFDT/wuiQFLZ/r7OI0T650YNUa0kE+7cgXzToPYXLXUxZFtNkaQdEbKKcdIMnMOpASTSoO7PxfnoaR5s5FGPX9mYuBbz7lDhaSpWnmGYqgRqB9fNhZUFEyvtT353GS8sXNT1U2TBJnUja5z6wErRpPvT2oivg1g9te4n1Jb+E1FQ6Ns8lVxVWYC1fXA7mdctIfMQxGjkRz5Tcw0diCnH5NioWMru2tpum1hoY1xDkDOiWHVJtxsshrd/Mbs7NlcnzfK8LmFDcShQK84rf9TCHepig2AesjazE0Z+dUJJKK306NQQ7DfMGxjWxPp5jjJIbaxM+BnmE0lYDzaP3ZAMqndATO0zoSinF3BeRDXbbcbemo9MpvxSzxzNu9h4cyp52YCiEe5FdQTWmXYzcNwCy9eLge+qmmFJI5fRt13qtzmue3K1baMLO1M3LbcMcqsmuiyDL6TDAOh7AJZHHUsDx8oXwNKu X-MS-Exchange-AntiSpam-MessageData-1: veu0Gl8JO3BaxQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8af03ffa-3961-4043-a1c7-08da2fcbffa7 X-MS-Exchange-CrossTenant-AuthSource: MWHPR10MB1407.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2022 01:50:44.2576 (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: 1Q39j+7Z7qkyv37Sb6t+tjWCl8r8wmBGQHl2CovD5tS1rDpMkT1HPC1uJKuDXw8xUHAqzQNvpTRqwJARQwUgHfifUtqGwqrLsjJ0RD4vRRQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB5347 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.486, 18.0.858 definitions=2022-05-06_07:2022-05-05, 2022-05-06 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205070008 X-Proofpoint-ORIG-GUID: WobD3at-Yyu6g_ENSCZ0FgYadGW1wFvH X-Proofpoint-GUID: WobD3at-Yyu6g_ENSCZ0FgYadGW1wFvH X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: "Guillermo E. Martinez via Libabigail" From: "Guillermo E. Martinez" Reply-To: "Guillermo E. Martinez" Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" Hello libabigail team, This patch fix missing symbols in the CTF reader backend. It depends of: * https://sourceware.org/pipermail/libabigail/2022q2/004340.html * https://sourceware.org/pipermail/libabigail/2022q2/004343.html Please let me know your comments, I'll really appreciate them. Kind regards, Guillermo Running `abidw --ctf' tool for some executable ELF files, seems that ctf reader is unable to get debug information for some symbols so, they will not be neither the corpus nor in abixml file. This is happening because internally the reader uses `ctf_arc_bufopen' expecting as argument the sections: symbol table (.dynsym) and string table (.dynstr) for ELF types: ET_{EXEC,DYN}, currently those sections are read by `elf_helpers' but it uses .symtab when it is present and `symtab_shdr->sh_link' to get .strtab, instead. * src/abg-ctf-reader.cc (read_context::is_elf_exec): Remove data member. (ctf_reader::process_ctf_qualified_type): Add condition to avoid use qualifier in functions. (ctf_reader::process_ctf_archive): Use `ctf_lookup_by_symbol_name' to find debug information when `ctf_lookup_variable' was not lucky iff `corpus::CTF_ORIGIN'. (ctf_reader::slurp_elf_info): Use `elf_helpers::find_section_by_name' to read .dynsym and .dynstr when {EXEC,DYN}. * src/abg-elf-helpers.h (elf_helpers::find_section_by_name): Add new declaration. * src/abg-elf-helpers.cc (elf_helpers::find_section_by_name): Add new definition. Signed-off-by: Guillermo E. Martinez --- src/abg-ctf-reader.cc | 53 ++++++++++++++++++++++++++++-------------- src/abg-elf-helpers.cc | 29 +++++++++++++++++++++++ src/abg-elf-helpers.h | 3 +++ 3 files changed, 67 insertions(+), 18 deletions(-) base-commit: c96463e1ad974b7c4561886d7a3aa8a3c9a35607 prerequisite-patch-id: 781b026536589341e1e4378d9529fe258633bb53 prerequisite-patch-id: e6191c510bc90e225bd0858d333e2e01b6e52a62 diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc index 5cb6fe19..3f8c3d03 100644 --- a/src/abg-ctf-reader.cc +++ b/src/abg-ctf-reader.cc @@ -70,8 +70,6 @@ public: Elf *elf_handler; int elf_fd; - /// set when ELF is ET_EXEC - bool is_elf_exec; /// The symtab read from the ELF file. symtab_reader::symtab_sptr symtab; @@ -240,9 +238,13 @@ public: /// Constructor. /// - /// ctfa data member can be used per courpus group. - /// /// @param elf_path the path to the ELF file. + /// + /// @param environment the environment used by the current context. + /// This environment contains resources needed by the reader and by + /// the types and declarations that are to be created later. Note + /// that ABI artifacts that are to be compared all need to be + /// created within the same environment. read_context(const string& elf_path, ir::environment *env) : ctfa(NULL) { @@ -271,7 +273,6 @@ public: ir_env = env; elf_handler = NULL; elf_fd = -1; - is_elf_exec = false; symtab.reset(); cur_corpus_group_.reset(); exported_decls_builder_ = 0; @@ -895,8 +896,11 @@ process_ctf_qualified_type(read_context *ctxt, else ABG_ASSERT_NOT_REACHED; - result.reset(new qualified_type_def(utype, qualifiers, location())); + // qualifiers are not be use in functions + if (is_function_type(utype)) + return result; + result.reset(new qualified_type_def(utype, qualifiers, location())); if (result) { decl_base_sptr qualified_type_decl = get_type_declaration(result); @@ -1213,16 +1217,16 @@ process_ctf_archive(read_context *ctxt, corpus_sptr corp) std::string sym_name = symbol->get_name(); ctf_id_t ctf_sym_type; - if ((corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN) - || ctxt->is_elf_exec) - ctf_sym_type= ctf_lookup_variable (ctf_dict, sym_name.c_str()); - else + ctf_sym_type = ctf_lookup_variable(ctf_dict, sym_name.c_str()); + if (ctf_sym_type == (ctf_id_t) -1 + && !(corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)) + // lookup in function objects ctf_sym_type = ctf_lookup_by_symbol_name(ctf_dict, sym_name.c_str()); if (ctf_sym_type == (ctf_id_t) -1) continue; - if (ctf_type_kind (ctf_dict, ctf_sym_type) != CTF_K_FUNCTION) + if (ctf_type_kind(ctf_dict, ctf_sym_type) != CTF_K_FUNCTION) { const char *var_name = sym_name.c_str(); type_base_sptr var_type = lookup_type(ctxt, corp, ir_translation_unit, @@ -1262,7 +1266,7 @@ process_ctf_archive(read_context *ctxt, corpus_sptr corp) func_declaration->set_symbol(symbol); add_decl_to_scope(func_declaration, ir_translation_unit->get_global_scope()); - func_declaration->set_is_in_public_symbol_table(true); + func_declaration->set_is_in_public_symbol_table(true); ctxt->maybe_add_fn_to_exported_decls(func_declaration.get()); } } @@ -1353,10 +1357,13 @@ fill_ctf_section(Elf_Scn *elf_section, ctf_sect_t *ctf_section) static int slurp_elf_info(read_context *ctxt, corpus_sptr corp) { - /* Set the ELF architecture. */ + Elf_Scn *symtab_scn; + Elf_Scn *ctf_scn; + Elf_Scn *strtab_scn; GElf_Ehdr eh_mem; GElf_Ehdr *ehdr = gelf_getehdr(ctxt->elf_handler, &eh_mem); - ctxt->is_elf_exec = (ehdr->e_type == ET_EXEC); + + /* Set the ELF architecture. */ 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. */ @@ -1369,10 +1376,20 @@ slurp_elf_info(read_context *ctxt, corpus_sptr corp) return 1; /* Get the raw ELF section contents for libctf. */ - 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); - Elf_Scn *strtab_scn = elf_helpers::find_strtab_for_symtab_section(ctxt->elf_handler, - symtab_scn); + ctf_scn = elf_helpers::find_section(ctxt->elf_handler, ".ctf", SHT_PROGBITS); + + // ET_{EXEC,DYN} needs .dyn{sym,str} in ctf_arc_bufopen + const char *symtab_name = ".dynsym"; + const char *strtab_name = ".dynstr"; + + if (ehdr->e_type == ET_REL) + { + symtab_name = ".symtab"; + strtab_name = ".strtab"; + } + + symtab_scn = elf_helpers::find_section_by_name(ctxt->elf_handler, symtab_name); + strtab_scn = elf_helpers::find_section_by_name(ctxt->elf_handler, strtab_name); if (ctf_scn == NULL || symtab_scn == NULL || strtab_scn == NULL) return 0; diff --git a/src/abg-elf-helpers.cc b/src/abg-elf-helpers.cc index 787a05ff..a1fd4e6c 100644 --- a/src/abg-elf-helpers.cc +++ b/src/abg-elf-helpers.cc @@ -296,6 +296,35 @@ e_machine_to_string(GElf_Half e_machine) } } +/// Find and return a section by its name. +/// +/// @param elf_handle the elf handle to use. +/// +/// @return the section found, nor nil if none was found. +Elf_Scn* +find_section_by_name(Elf* elf_handle, const std::string& name) +{ + size_t section_header_string_index = 0; + if (elf_getshdrstrndx (elf_handle, §ion_header_string_index) < 0) + return 0; + + Elf_Scn* section = 0; + GElf_Shdr header_mem, *header; + while ((section = elf_nextscn(elf_handle, section)) != 0) + { + header = gelf_getshdr(section, &header_mem); + if (header == NULL) + continue; + + const char* section_name = + elf_strptr(elf_handle, section_header_string_index, header->sh_name); + if (section_name && name == section_name) + return section; + } + + return 0; +} + /// Find and return a section by its name and its type. /// /// @param elf_handle the elf handle to use. diff --git a/src/abg-elf-helpers.h b/src/abg-elf-helpers.h index afaff24a..ee406863 100644 --- a/src/abg-elf-helpers.h +++ b/src/abg-elf-helpers.h @@ -49,6 +49,9 @@ find_section(Elf* elf_handle, const std::string& name, Elf64_Word section_type); +Elf_Scn* +find_section_by_name(Elf* elf_handle, const std::string& name); + Elf_Scn* find_section(Elf* elf_handle, Elf64_Word section_type);