From patchwork Tue Dec 21 19:29:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Guillermo E. Martinez" X-Patchwork-Id: 49157 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 74CB53858036 for ; Tue, 21 Dec 2021 19:30:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 74CB53858036 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1640115023; bh=BRsBFXr5y3XmwVbaDUIHclrAJbD/pBvtDP0iq0Rnbh4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:From; b=bmD9ngsZAWeF+nc4TFdDM9R6cJkOaXeR4s5z7Rt+vSh4sZQbnt+50r/S8N18xjJFl ULw03LN/TdTGGwEcnm17AplV8D682s4UsXZxuEmTlWODaWsNjDX77O5+TKg6mChUGr bsJ/XrNhVRe0733FFbBFK7WYfmqpN6oCcSW0G46w= 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 CB0953858425 for ; Tue, 21 Dec 2021 19:30:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CB0953858425 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1BLHKHTc022242 for ; Tue, 21 Dec 2021 19:30:15 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3d3f4ms22b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 21 Dec 2021 19:30:15 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 1BLJL7uG112090 for ; Tue, 21 Dec 2021 19:30:14 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2175.outbound.protection.outlook.com [104.47.59.175]) by aserp3020.oracle.com with ESMTP id 3d17f4ar6f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 21 Dec 2021 19:30:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SgzcEowu8sZ8nCpGXils+cnbiKPp8i4EQc/X0PAwQ93GDFZF9ey/XPQlk7MTFJJE1hqAGpwN3haDlji1VYvcSlvAoxwRTBK+ZcUhOMIx/+3dJiX2wD5ivhGjCGzPDK7Kd0xC8Lgl6SDxOB5fh1znPd+pmAy6GIiAthWqk9+qENIS7WjlMu2Whb46f2+LoYGxNFzFvSrseodFTpCVJUjRB6l99Ld3PGiuce0PyGTygqEQoTajdE4HHV75jT0sgKSQ5P2UZZw7RXIlx2ot5Mt/Kzfi8YJxH021qxJGvzPffcrPmO6ERcHkqMimssjZEjLNJCQjpS7A0NtAAPncDcmQcg== 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=BRsBFXr5y3XmwVbaDUIHclrAJbD/pBvtDP0iq0Rnbh4=; b=YBmPBhiofcExxsY1PWJAK7z5BdMAwHYvb0xdBi0XZq2lRen4WQudhvC6Cn2wch2ur9EEN978l+yzyflzvXIdZS5RhHSPz5iwFg3kl3iJqmL9okXZiJu9mjTKUmnOatcO5AAb90GLNhDfSNgDH15tTcygbUxSwfpM24WZt0QnSnMbxaYPT65lLHJbv9wCD48h9Am8iObcXzCe0OPJCLLBAnL2npHmezPdqw9aJXK4dR7vhaHBeylWaHhfnarpBYuausaxR3yjXoqdozgKG60fZ1K2L0Xfu0CuE9tiJaBhgt2kipWDd4FIBwic8TYRQ+hbL+jME0usc97NnZqjfdk0IA== 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 BL0PR10MB2852.namprd10.prod.outlook.com (2603:10b6:208:76::22) by BL0PR10MB2995.namprd10.prod.outlook.com (2603:10b6:208:75::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4823.17; Tue, 21 Dec 2021 19:30:11 +0000 Received: from BL0PR10MB2852.namprd10.prod.outlook.com ([fe80::6927:5e6b:31ff:14bd]) by BL0PR10MB2852.namprd10.prod.outlook.com ([fe80::6927:5e6b:31ff:14bd%3]) with mapi id 15.20.4801.022; Tue, 21 Dec 2021 19:30:11 +0000 To: libabigail@sourceware.org Subject: [PATCH v2] ctf-reader: Assert on ir::hash_as_canonical_type_or_constant Date: Tue, 21 Dec 2021 13:29:55 -0600 Message-Id: <20211221192955.173416-1-guillermo.e.martinez@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211210025252.2309157-1-guillermo.e.martinez@oracle.com> References: <20211210025252.2309157-1-guillermo.e.martinez@oracle.com> X-ClientProxiedBy: SN1PR12CA0056.namprd12.prod.outlook.com (2603:10b6:802:20::27) To BL0PR10MB2852.namprd10.prod.outlook.com (2603:10b6:208:76::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b9d71816-ae2f-4bab-d593-08d9c4b84df3 X-MS-TrafficTypeDiagnostic: BL0PR10MB2995:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:288; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Rls1b5uWwlnGq2JxpZU6+C/M1R01RzO+ZfaN5vUG3hp5HiARpiHBcUaQ1eH0gOJXch/eDNiESXTeWc2s7hRbJLHU32PtD27ait+ApiHjkl3MXbFcjWJe+pI/8WWT6t7AuMXeSQIGpy2Fp/fDsgpcnuRDjhENtXcHdwguY/Lmj3YXs0GlPyxCTtnqC6+YyDVY5/6Uz24aThXCQ/JQKxgx2LyKeJEFnNdGlZ/Hc9/uTvPx7JnDFAou65461KRs2twAY2Us2TVhl47dnAokRhS5C1lTw2jWF3ITuqMEDyfGDqcGIJWVmuTgXHIkOWrWq5kQxC3NQeEKSFO6ttp+wwB3ZAdn6I+lK+z8Ox7eqyIOidvxsjFAw4U9ETujyRq80FbRAz46LHc/bg687R/JhMUrtEgjqoKIeGV+9/0tsbhrt57+WHRamAPkkUwsMr9H794iK79wqydHZ2XqFO32LkLHX7HhoJETdk40+UPCOv2EGHa2cbwbsY6OD7hJWwjILcO+pCr4Nfk3hp9za2IZdvwErlAY/Y75drtJM2vu9L17sa/lZkkvfLr6UXz90o4SXFP/lel0Dze9kfF3N4WeZsk3zIBAZP9t7jBYcKFGuzZoeArkkYKP+aV26qcXDLP8dzdxvmoDETr4u+N6+hYKRhklGA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BL0PR10MB2852.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(38100700002)(508600001)(6486002)(19627235002)(316002)(8676002)(4326008)(5660300002)(2616005)(86362001)(6916009)(8936002)(2906002)(52116002)(66476007)(66556008)(83380400001)(30864003)(107886003)(6666004)(1076003)(103116003)(66946007)(6506007)(36756003)(186003)(6512007)(579004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fNETfyDg+IlmUHWXliMogO7f5r599GqFAPWInSqF8yzMW76o3QoA9JpFjDqkSsBAkKo6HE1Hn3nedjxvS6ZYnVy0dSo8sa4OHKoY86srC2Rj9eA/SZ5nbboxuju0ihdwV4GDDkim+gmlest5N7Lu6Ani468uVSRVN9ys6T5jxJr57kpMBpHNmIMIbMpbsZobXUcbGLYOHffBsrjbPrOPo0j/S88B05CMD56dmCNVFJmAR58XdE9rKj8nCnQduBEPBUrv2F+Kxk8KJB1hf5c+BKJ/+4KQFflSyWXtOriOFnoxgnkK2sIbmAsE8rwrfw5byk6j4lXv1bLKmNREDNKLCqc6XN3af581LXTHpUgcUvmaPPtjA/zCeeWZNugqSAZu4vYCu78Wj5fSapXmRYVu5Y5jp/qcDcRm07Oo8X+e4bzkk+l33vfpHSJMUVvCcqcCPDsg32ImYWtDjJTyK+UNU7lKG9MqBuFJIznB14t3LhHHmx15uwptGr2aWhVRR+SVlZaItQa2HTeR8MaE2N6WSSSbRbGxz4mA0FRC/UXEoVaq2G7DBOyOR6DJl6IEQhvoDRaPClCNcY+lI8Qwif5nlI5lW8qmF4YgqkTABFNAYFHwC3155OXG2NDboXRUIWhTO27RU9XxzrOeqQm+snLzFGZLwqAyEnanY6ZW5uUnI5fAwVjpZrxn3CEvvvxpiUfoBeNm8LTnoyCyalSfQl05Pu5yF2iVvpGQDCJkB+arDoLCggnY1kLhtuhqbJCALg0pRwR5PmAWD/yRO/uvihzd8uqCe3mwc/mhe17puIQhj4+Nm3U2s2Mb6CrkjhrPnTCZdTBuupCp9s6VzfLZQbs6o1olvFhmuTVCwjbcI1ajxdXTlMe5pD8W1TH41g3p3hI6nDgzHa1/7khH1tf7hjrvihHufuFGJ3YP84c9tp+P6UnxhS/jqcMrwR8+lwEBpNRfSP9yj5MlS+mp+CfelrgBie4HzAeJ1dPL+de912f7NEoHgjcx17EV1DHHJFy9ylVUo6yqARQ9UP4Lof52J6VLXws9OSLrDcz7mK5W4JTmHr58huRcA4PNHhmAnSFG+1QGAWh2KsPEJAWq6MXCTmstrNr1t+qPzS4ao/E7s5MDQvm/PhTu7PHqS4MPEDWpQzw+C4Epd9xyvjbFOpYZw17LIHiLies+FEUHimpkaIS+r67ImFcJf/QOVdBMwJaF9pEydM7XZ6pEWdVeBU0dDcHojfMphQEvCcPpZz7oxFX1cgTPfEZrsK+iF/jRndBG1D98z/QTYX0F57RrSezqElPf62sXNlYAIDNvYLF+sPniSGFwDwpLtVDCPeiQlkKAeHfTpOioFxPGclzOAyUNoGZCvZRH++aiBRkaB5Hs38e8orQUJ95C+1Shnh90vqhXM7K4Cz5+B+DaKzd02Qq61K147tMv8LTjQXJHfkY+MrsAhCkejkP+CxQKZLXnKBrmIXkqdiUoxehM/zoeKFoNTUHY9+gMo0Febg/Tz0n9W2/NpicxIQXvgo2ptkk5I4sh+rEd+STzBS72Y+KrUhVH+ICC1MEFD2HV7D5vTaw1D/bT7rs9RIFMCHKxSlUbaw4G/64F3x14V2bHeQqsLvGxPwUCdeRY0Wf9U59ChMJvJF5GBhqUmJfrQcnWvFQrZvsuemCTp86fc7StyJveuMergoU5SacAASkucJAzX6FojetXyS0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9d71816-ae2f-4bab-d593-08d9c4b84df3 X-MS-Exchange-CrossTenant-AuthSource: BL0PR10MB2852.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2021 19:30:11.4445 (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: mnnsdYIM2/KYWkjhvnDCHwE3lWzbzMIP+91iuA0yxyT+oRITNpiqhWOBZoVcU11lEWgycX7ztjqItuNWV/3c+CCMHcJkJQn55k4sPhM4bPE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR10MB2995 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10205 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 spamscore=0 phishscore=0 mlxscore=0 bulkscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2112210095 X-Proofpoint-ORIG-GUID: c0cH0AsyDh63inHfz86vcAmL1Ey9X9UU X-Proofpoint-GUID: c0cH0AsyDh63inHfz86vcAmL1Ey9X9UU 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, KAM_LOTSOFHASH, 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: "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's the patch v2 to fix assertions in ctf reader back-end, improvements for v1: * Add missing file inputs for ctf test harness. * Update Makefile.am in `tests/data' directory. * Complient with `distcheck-fast'. I'll appreciate your comments. Kind Regards, Guillermo In some scenarios where we declare same data types `recursively' such as: like linked list, functions that accept the same pointer to function as arguments, forward types declarations to build structures with member fields with mutual dependencies, etc., an assertion is trigger: abidw: ../../../libabigail-upstream/src/abg-ir.cc:25251: size_t abigail::ir::hash_as_canonical_type_or_constant(const abigail::ir::type_base*): Assertion `__abg_cond__' failed. It is happening because the recursively behavior of `process_ctf_type' and `process_ctf_*' used to register ctf types doesn't verify when a ctf_type was processed and registered before by their subsequence _recursive_ calls, so `type_base' object is built more than once and the second time when it is inserted in `types_maps', it refuses in a silent way, being that the key was already inserted, however `add_decl_to_scope', `bind_function_type_life_time' successfully registered the ctf type object. In this patch `process_ctf_type' delegates register types task to `process_ctf_*' functions guaranteeing a single ctf type registration, also it improves the performance looking for the type before start to build it again. * src/abg-ctf-reader.cc (process_ctf_base_type): Add new `translation_unit_sptr' parameter. Add condition to validate success 'base_type' construction and register type object. (process_ctf_typedef): Add `lookup_type' to get a `type_base' object when this was previously created, if this is not the case, register ctf type. Add condition to validate success 'base_type' construction and register type object. (process_ctf_function_type): Likewise. (process_ctf_array_type): Likewise. (process_ctf_qualified_type): Likewise. (process_ctf_pointer_type): Likewise. (process_ctf_struct_type): Add `add_decl_to_scope'. (process_ctf_union_type): Likewise. (process_ctf_type): Add `lookup_type' to get a `type_base' object when this was previously created. Delegate register type object to `process_ctf_*'. * tests/data/Makefile.am: Add tests I/O and expected files. * tests/data/test-read-ctf/test-array-of-pointers.[co]: New testcase. * tests/data/test-read-ctf/test-list-struct.[co]: Likewise. * tests/data/test-read-ctf/test-callback.[co]: Likewise. * tests/data/test-read-ctf/test-callback2.[co]: Likewise. * tests/data/test-read-ctf/test-functions-declaration.[co]: Likewise. * tests/data/test-read-ctf/test-forward-type-decl.[co]: Likewise. * tests/data/test-read-ctf/test-array-of-pointers.abi: Expected test output. * tests/data/test-read-ctf/test-callback.abi: Likewise. * tests/data/test-read-ctf/test-callback2.abi: Likewise. * tests/data/test-read-ctf/test-forward-type-decl.abi: Likewise. * tests/data/test-read-ctf/test-functions-declaration.abi: Likewise. * tests/data/test-read-ctf/test-list-struct.abi: Likewise. * tests/test-read-ctf.cc: Add testcases to CTF test harness. Signed-off-by: Guillermo E. Martinez --- src/abg-ctf-reader.cc | 149 ++++++++++-------- tests/data/Makefile.am | 18 +++ .../test-read-ctf/test-array-of-pointers.abi | 36 +++++ .../test-read-ctf/test-array-of-pointers.c | 20 +++ .../test-read-ctf/test-array-of-pointers.o | Bin 0 -> 1464 bytes tests/data/test-read-ctf/test-callback.abi | 31 ++++ tests/data/test-read-ctf/test-callback.c | 16 ++ tests/data/test-read-ctf/test-callback.o | Bin 0 -> 1856 bytes tests/data/test-read-ctf/test-callback2.abi | 20 +++ tests/data/test-read-ctf/test-callback2.c | 11 ++ tests/data/test-read-ctf/test-callback2.o | Bin 0 -> 1312 bytes .../test-read-ctf/test-forward-type-decl.abi | 29 ++++ .../test-read-ctf/test-forward-type-decl.c | 23 +++ .../test-read-ctf/test-forward-type-decl.o | Bin 0 -> 1408 bytes .../test-functions-declaration.abi | 25 +++ .../test-functions-declaration.c | 16 ++ .../test-functions-declaration.o | Bin 0 -> 1848 bytes tests/data/test-read-ctf/test-list-struct.abi | 20 +++ tests/data/test-read-ctf/test-list-struct.c | 11 ++ tests/data/test-read-ctf/test-list-struct.o | Bin 0 -> 1344 bytes tests/test-read-ctf.cc | 48 ++++++ 21 files changed, 406 insertions(+), 67 deletions(-) create mode 100644 tests/data/test-read-ctf/test-array-of-pointers.abi create mode 100644 tests/data/test-read-ctf/test-array-of-pointers.c create mode 100644 tests/data/test-read-ctf/test-array-of-pointers.o create mode 100644 tests/data/test-read-ctf/test-callback.abi create mode 100644 tests/data/test-read-ctf/test-callback.c create mode 100644 tests/data/test-read-ctf/test-callback.o create mode 100644 tests/data/test-read-ctf/test-callback2.abi create mode 100644 tests/data/test-read-ctf/test-callback2.c create mode 100644 tests/data/test-read-ctf/test-callback2.o create mode 100644 tests/data/test-read-ctf/test-forward-type-decl.abi create mode 100644 tests/data/test-read-ctf/test-forward-type-decl.c create mode 100644 tests/data/test-read-ctf/test-forward-type-decl.o create mode 100644 tests/data/test-read-ctf/test-functions-declaration.abi create mode 100644 tests/data/test-read-ctf/test-functions-declaration.c create mode 100644 tests/data/test-read-ctf/test-functions-declaration.o create mode 100644 tests/data/test-read-ctf/test-list-struct.abi create mode 100644 tests/data/test-read-ctf/test-list-struct.c create mode 100644 tests/data/test-read-ctf/test-list-struct.o diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc index fbf6baef..e5ea0ca2 100644 --- a/src/abg-ctf-reader.cc +++ b/src/abg-ctf-reader.cc @@ -15,6 +15,7 @@ #include /* For open(3) */ #include +#include #include "ctf-api.h" @@ -39,6 +40,7 @@ namespace abigail { namespace ctf_reader { +using std::dynamic_pointer_cast; class read_context { @@ -157,6 +159,10 @@ process_ctf_typedef(read_context *ctxt, if (!utype) return result; + result = dynamic_pointer_cast(ctxt->lookup_type(ctf_type)); + if (result) + return result; + result.reset(new typedef_decl(typedef_name, utype, location(), typedef_name /* mangled_name */)); @@ -171,6 +177,12 @@ process_ctf_typedef(read_context *ctxt, decl->set_naming_typedef(result); } + if (result) + { + add_decl_to_scope(result, tunit->get_global_scope()); + ctxt->add_type(ctf_type, result); + } + return result; } @@ -187,6 +199,7 @@ process_ctf_typedef(read_context *ctxt, static type_decl_sptr process_ctf_base_type(read_context *ctxt, corpus_sptr corp, + translation_unit_sptr tunit, ctf_dict_t *ctf_dictionary, ctf_id_t ctf_type) { @@ -226,6 +239,12 @@ process_ctf_base_type(read_context *ctxt, } + if (result) + { + add_decl_to_scope(result, tunit->get_global_scope()); + ctxt->add_type(ctf_type, result); + } + return result; } @@ -284,6 +303,9 @@ process_ctf_function_type(read_context *ctxt, function_parms.push_back(parm); } + result = dynamic_pointer_cast(ctxt->lookup_type(ctf_type)); + if (result) + return result; /* Ok now the function type itself. */ result.reset(new function_type(ret_type, @@ -291,8 +313,15 @@ process_ctf_function_type(read_context *ctxt, tunit->get_address_size(), ctf_type_align(ctf_dictionary, ctf_type))); - tunit->bind_function_type_life_time(result); - result->set_is_artificial(true); + if (result) + { + tunit->bind_function_type_life_time(result); + result->set_is_artificial(true); + decl_base_sptr function_type_decl = get_type_declaration(result); + add_decl_to_scope(function_type_decl, tunit->get_global_scope()); + ctxt->add_type(ctf_type, result); + } + return result; } @@ -394,6 +423,7 @@ process_ctf_struct_type(read_context *ctxt, refer to this struct, we have to make it available in the cache at this point even if the members haven't been added to the IR node yet. */ + add_decl_to_scope(result, tunit->get_global_scope()); ctxt->add_type(ctf_type, result); /* Now add the struct members as specified in the CTF type description. @@ -442,6 +472,7 @@ process_ctf_union_type(read_context *ctxt, refer to this union, we have to make it available in the cache at this point even if the members haven't been added to the IR node yet. */ + add_decl_to_scope(result, tunit->get_global_scope()); ctxt->add_type(ctf_type, result); /* Now add the union members as specified in the CTF type description. @@ -498,6 +529,10 @@ process_ctf_array_type(read_context *ctxt, if (!index_type) return result; + result = dynamic_pointer_cast(ctxt->lookup_type(ctf_type)); + if (result) + return result; + /* The number of elements of the array determines the IR subranges type to build. */ array_type_def::subranges_type subranges; @@ -529,6 +564,13 @@ process_ctf_array_type(read_context *ctxt, /* Finally build the IR for the array type and return it. */ result.reset(new array_type_def(element_type, subranges, location())); + if (result) + { + decl_base_sptr array_type_decl = get_type_declaration(result); + add_decl_to_scope(array_type_decl, tunit->get_global_scope()); + ctxt->add_type(ctf_type, result); + } + return result; } @@ -566,6 +608,14 @@ process_ctf_qualified_type(read_context *ctxt, ABG_ASSERT_NOT_REACHED; result.reset(new qualified_type_def(utype, qualifiers, location())); + + if (result) + { + decl_base_sptr qualified_type_decl = get_type_declaration(result); + add_decl_to_scope(qualified_type_decl, tunit->get_global_scope()); + ctxt->add_type(ctf_type, result); + } + return result; } @@ -597,10 +647,20 @@ process_ctf_pointer_type(read_context *ctxt, if (!target_type) return result; + result = dynamic_pointer_cast(ctxt->lookup_type(ctf_type)); + if (result) + return result; + result.reset(new pointer_type_def(target_type, ctf_type_size(ctf_dictionary, ctf_type) * 8, ctf_type_align(ctf_dictionary, ctf_type) * 8, location())); + if (result) + { + add_decl_to_scope(result, tunit->get_global_scope()); + ctxt->add_type(ctf_type, result); + } + return result; } @@ -657,6 +717,12 @@ process_ctf_enum_type(read_context *ctxt, const char *enum_name = ctf_type_name_raw(ctf_dictionary, ctf_type); result.reset(new enum_type_decl(enum_name, location(), utype, enms, enum_name)); + if (result) + { + add_decl_to_scope(result, tunit->get_global_scope()); + ctxt->add_type(ctf_type, result); + } + return result; } @@ -683,43 +749,31 @@ process_ctf_type(read_context *ctxt, int type_kind = ctf_type_kind(ctf_dictionary, ctf_type); type_base_sptr result; + if ((result = ctxt->lookup_type(ctf_type))) + return result; + switch (type_kind) { case CTF_K_INTEGER: case CTF_K_FLOAT: { type_decl_sptr type_decl - = process_ctf_base_type(ctxt, corp, ctf_dictionary, ctf_type); - - if (type_decl) - { - add_decl_to_scope(type_decl, tunit->get_global_scope()); - result = is_type(type_decl); - } + = process_ctf_base_type(ctxt, corp, tunit, ctf_dictionary, ctf_type); + result = is_type(type_decl); break; } case CTF_K_TYPEDEF: { typedef_decl_sptr typedef_decl = process_ctf_typedef(ctxt, corp, tunit, ctf_dictionary, ctf_type); - - if (typedef_decl) - { - add_decl_to_scope(typedef_decl, tunit->get_global_scope()); - result = is_type(typedef_decl); - } + result = is_type(typedef_decl); break; } case CTF_K_POINTER: { pointer_type_def_sptr pointer_type = process_ctf_pointer_type(ctxt, corp, tunit, ctf_dictionary, ctf_type); - - if (pointer_type) - { - add_decl_to_scope(pointer_type, tunit->get_global_scope()); - result = pointer_type; - } + result = pointer_type; break; } case CTF_K_CONST: @@ -728,79 +782,42 @@ process_ctf_type(read_context *ctxt, { type_base_sptr qualified_type = process_ctf_qualified_type(ctxt, corp, tunit, ctf_dictionary, ctf_type); - - if (qualified_type) - { - decl_base_sptr qualified_type_decl = get_type_declaration(qualified_type); - - add_decl_to_scope(qualified_type_decl, tunit->get_global_scope()); - result = qualified_type; - } + result = qualified_type; break; } case CTF_K_ARRAY: { array_type_def_sptr array_type = process_ctf_array_type(ctxt, corp, tunit, ctf_dictionary, ctf_type); - - if (array_type) - { - decl_base_sptr array_type_decl = get_type_declaration(array_type); - - add_decl_to_scope(array_type_decl, tunit->get_global_scope()); - result = array_type; - } + result = array_type; break; } case CTF_K_ENUM: { enum_type_decl_sptr enum_type = process_ctf_enum_type(ctxt, tunit, ctf_dictionary, ctf_type); - - if (enum_type) - { - add_decl_to_scope(enum_type, tunit->get_global_scope()); - result = enum_type; - } - + result = enum_type; break; } case CTF_K_FUNCTION: { function_type_sptr function_type = process_ctf_function_type(ctxt, corp, tunit, ctf_dictionary, ctf_type); - - if (function_type) - { - decl_base_sptr function_type_decl = get_type_declaration(function_type); - - add_decl_to_scope(function_type_decl, tunit->get_global_scope()); - result = function_type; - } + result = function_type; break; } case CTF_K_STRUCT: { class_decl_sptr struct_decl = process_ctf_struct_type(ctxt, corp, tunit, ctf_dictionary, ctf_type); - - if (struct_decl) - { - add_decl_to_scope(struct_decl, tunit->get_global_scope()); - result = is_type(struct_decl); - } + result = is_type(struct_decl); break; } case CTF_K_UNION: { union_decl_sptr union_decl = process_ctf_union_type(ctxt, corp, tunit, ctf_dictionary, ctf_type); - - if (union_decl) - { - add_decl_to_scope(union_decl, tunit->get_global_scope()); - result = is_type(union_decl); - } + result = is_type(union_decl); break; } case CTF_K_UNKNOWN: @@ -809,9 +826,7 @@ process_ctf_type(read_context *ctxt, break; } - if (result) - ctxt->add_type(ctf_type, result); - else + if (!result) fprintf(stderr, "NOT PROCESSED TYPE %lu\n", ctf_type); return result; diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 686bbf13..42d43c96 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -648,6 +648,24 @@ test-read-ctf/test-struct-iteration.c \ test-read-ctf/test-struct-iteration.o.abi \ test-read-ctf/PR27700/test-PR27700.abi \ test-read-ctf/PR26261/PR26261-exe.abi \ +test-read-ctf/test-callback.c \ +test-read-ctf/test-callback.abi \ +test-read-ctf/test-callback.o \ +test-read-ctf/test-array-of-pointers.c \ +test-read-ctf/test-array-of-pointers.o \ +test-read-ctf/test-array-of-pointers.abi \ +test-read-ctf/test-functions-declaration.abi \ +test-read-ctf/test-functions-declaration.c \ +test-read-ctf/test-functions-declaration.o \ +test-read-ctf/test-forward-type-decl.abi \ +test-read-ctf/test-forward-type-decl.o \ +test-read-ctf/test-forward-type-decl.c \ +test-read-ctf/test-list-struct.c \ +test-read-ctf/test-list-struct.o \ +test-read-ctf/test-list-struct.abi \ +test-read-ctf/test-callback2.c \ +test-read-ctf/test-callback2.o \ +test-read-ctf/test-callback2.abi \ \ test-annotate/test0.abi \ test-annotate/test1.abi \ diff --git a/tests/data/test-read-ctf/test-array-of-pointers.abi b/tests/data/test-read-ctf/test-array-of-pointers.abi new file mode 100644 index 00000000..920da28b --- /dev/null +++ b/tests/data/test-read-ctf/test-array-of-pointers.abi @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-read-ctf/test-array-of-pointers.c b/tests/data/test-read-ctf/test-array-of-pointers.c new file mode 100644 index 00000000..560ce354 --- /dev/null +++ b/tests/data/test-read-ctf/test-array-of-pointers.c @@ -0,0 +1,20 @@ +/* Test a array of pointer definition as struct member + * gcc -gctf -c test-array-of-pointers.c -o test-array-of-pointer.o + */ +struct task { + struct css_set *s; +}; + +struct state { + struct cgroup *cg; +}; + +struct css_set { + struct state *s0[4]; +}; + +struct cgroup { + struct state *s1[4]; +}; + +struct task *t; diff --git a/tests/data/test-read-ctf/test-array-of-pointers.o b/tests/data/test-read-ctf/test-array-of-pointers.o new file mode 100644 index 0000000000000000000000000000000000000000..4ec239e23ee835555d994b5ac1d3aecae581b440 GIT binary patch literal 1464 zcmbtUO>fgc5S@fjphyu#98lq4PP77lBuEJLfGkx|gb+852(6uMYBjMV??y^a{0D^i zJsdgn2lx$e;)3A4*iNi%dg4iMcjnEEcV}Yf}KLLqrU>|JqBZ>fP z?|@CdPZ3~#js6uF_bO+H`Eg})z0Kt+$TNBG8vVAtZWLF*IU-h>b4iW)V6+uumDQ4t z%VIv0Ns*7ed2X_Cu18*$BRoJ%Oe99EglEN6hsiQohDE8;i4IMfhLbE&Nj6s5#GlWM zEw!44RvT-=k+N!K`VdEcYELUqm8Dwx#i>6laE2~TkcylfA0K%KCvV>!dV^sQ1(7$5 zhJyj<9q7eOm)TV3R!t7s0{ino_Kp(iO6O~K7>8t6706D_Or&adSNBtJS0erkpQ#6QcT&C1bJa~fIfWu8tHlMkMnsj zD+_dPm(B72yYoF_&wO9nh}%xfcIWp1F>0I1RLOC*U0B`vhsfY8FRNeAxqg!CKZfo; zlc_Nm;FA+{Tp1vTTJ!y}hWK75KC0aH+SE5Y|0^1Modo00HgQYtYiRtoTi+zSjo{wP z?Vrb7sD&2Q;wwH2;QtV%rv5HPfVw+->WjMmKAjfaw)PO)R{y!Kf8VO5>DK=P9Oi#k literal 0 HcmV?d00001 diff --git a/tests/data/test-read-ctf/test-callback.abi b/tests/data/test-read-ctf/test-callback.abi new file mode 100644 index 00000000..704c4971 --- /dev/null +++ b/tests/data/test-read-ctf/test-callback.abi @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-read-ctf/test-callback.c b/tests/data/test-read-ctf/test-callback.c new file mode 100644 index 00000000..a5fc7df2 --- /dev/null +++ b/tests/data/test-read-ctf/test-callback.c @@ -0,0 +1,16 @@ +/* Test a simple callback as a struct member + * gcc -gctf -c test-callback.c -o test-callback.o + */ +struct test { + void (*fn1)(int, long); +}; + +void f2(int a, long b) +{ +} + +void assign() +{ + struct test *tt; + tt->fn1 = f2; +} diff --git a/tests/data/test-read-ctf/test-callback.o b/tests/data/test-read-ctf/test-callback.o new file mode 100644 index 0000000000000000000000000000000000000000..cf853845e018ca7607f9c2520bfa2a4465cc38be GIT binary patch literal 1856 zcmbtUPixdr5TCTQt=O(>5vkTgK#&&QWOol9M0BOpuHYXO3SPt}+w5*Io7Ci0b_MY! z6fgY{egVHh!Gm8yuov&@$%CNtOWx3D$Vmt0&CGB9z4zuNZ#M4TnX)VrvgjrqTY?fD zP9N)?Tn(JWFt0^Lv&P z<~in*%omw2F=Ic>7ZAJ544Tz^EQ)P&vvX)T!+e7I6f@H-Y@5rRhQ&5&b&ArkYd9YI zG3EJ%N;UMx9?Eq|1(~9kNw`B{tSCz2feob}x5&$~a1c|!P3|xm1+G8wCvK8@y(n?RcT7Cq5?))w|htFXh0u!>djdOy|7J{r-kI5R> zt(Aqj`2%+1ZuI@|+?j6I>Tjpk7iaHsfcD)0&a{L@{Pzn#pejP&8T$Ua$~Rq%^e@*L zww4S$-wR{dH*m4@Js=Yo+c55rr=sTrFP+cV;+^0P2-#Y}TLKGpv?93lBPW}Tl;^Wl zX(5NAr9tF5Di|wrFko{0EF*`9%S$rCw8)7Q6*xSgMy7bq+8)Gv&Tg9UOx1*(yi72B z)=#}rAp7}WX>$S00N;~I9c|bq$hy1}fmc|;d+G=vQeUQgulNp;i?;$29RCF1=H0`; zjirLh{jYKiYW{0}i*w60(RLdP)1#8JWYRT`0oFvYK_7JB6$67R`66!_m>K$60!*+X z_90{VUz%?eDMvcLyf3+b#DE6O2rcK=HSh#M29@)D_EpV)Sr0_|WB&N3OTNs%syEsV pb^kF8rUhn{Ea#(UdG-v^k8_@7kecQyFJOlG~D{|9qBlT!cy literal 0 HcmV?d00001 diff --git a/tests/data/test-read-ctf/test-callback2.abi b/tests/data/test-read-ctf/test-callback2.abi new file mode 100644 index 00000000..bdd4ad33 --- /dev/null +++ b/tests/data/test-read-ctf/test-callback2.abi @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-read-ctf/test-callback2.c b/tests/data/test-read-ctf/test-callback2.c new file mode 100644 index 00000000..6d33780f --- /dev/null +++ b/tests/data/test-read-ctf/test-callback2.c @@ -0,0 +1,11 @@ +/* Test a simple callback as a struct member + * that takes a pointer to a struct parent as + * argument + * gcc -gctf -c test-callback2.c -o test-callback2.o + */ +struct s0 +{ + int (*mem_fun)(struct s0 *); +}; + +struct s0 *s0; diff --git a/tests/data/test-read-ctf/test-callback2.o b/tests/data/test-read-ctf/test-callback2.o new file mode 100644 index 0000000000000000000000000000000000000000..abebb3b81bc1612aed9bb1b0311fdb9325a764db GIT binary patch literal 1312 zcmbtTOK;Oa5FUq6UQ*SEKnO18)K;z6Nsc`fOA!Pi#Em1OYiFCf_z`(GQgh<3^r!Go zxb|A^2xjcr*x8m-M;gz}H{ZM4yV${+6@q# z28lUqqC{p{ER*jekpN7_<70n+^7+ewKOBjH82F>XXgEam_toWGRcWpYBeMg(9M4kE zhgHx6?`L-wkK@ifT)A#2--nyO>nOku0^3k;pia?FYoVEf?$vQ4AoMafGDd5v#-3Zx zs7nKab^s#Q8U)UdpE9R;Koq4>0tX1R!BucPD;8p2l{mFo+H>z|Ut>MZy5aPRoY;o$ z-rit>uy!L2GiuDOuUo%|4BFxU>R0>aPHudJxZ9Jc5q(hH2XwhZ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-read-ctf/test-forward-type-decl.c b/tests/data/test-read-ctf/test-forward-type-decl.c new file mode 100644 index 00000000..742b24ad --- /dev/null +++ b/tests/data/test-read-ctf/test-forward-type-decl.c @@ -0,0 +1,23 @@ +/* Test a forward type declaration as a struct member + * to exercise circular dependencies. + * gcc -gctf -c test-forward-type-decl.c -o \ + * test-forward-type-decl.o + */ +typedef struct page *page_t; + +struct rb_node { + struct rb_node *rb_left; +}; + +struct address_space; + +struct page { + struct address_space *mapping; +}; + +struct address_space { + struct rb_node *rb_root; + struct page *page; +}; + +struct address_space *addr; diff --git a/tests/data/test-read-ctf/test-forward-type-decl.o b/tests/data/test-read-ctf/test-forward-type-decl.o new file mode 100644 index 0000000000000000000000000000000000000000..3d6e5f89422fee9bbf56d4d37b72fb9f75f58839 GIT binary patch literal 1408 zcmbtT&2G~`5T2CqFGW=90R<$CghVUwI?0V5DoYgma-@e)!jlkIm4xrCm72s^Ek7Ewj))Q05jzN{ zeTXp`ajZ?Qxd>n~m}_Dly5Va9Jjwy4GN*C2yL%S{n&O z$8{;9q)pnWmOL#)q+}WudBT%?&GRBWX_S_Nmys4qt0?1|n=r&;7N&aDWvg0#<}wR) z+lVj|X~9x}qr=1fVE5?V`@LYkU^6xg7PG~CjtF+eX(MD_ic0fh&y7bj2MF2;%5ZO^ zv%wy4M_oSH0Wz-|-H+k-g?}@}!Z!5Vq<3YEh6^{%KzjvXsx387&}-TGV;5<0s)5m3 zfF()+! + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-read-ctf/test-functions-declaration.c b/tests/data/test-read-ctf/test-functions-declaration.c new file mode 100644 index 00000000..36776bbb --- /dev/null +++ b/tests/data/test-read-ctf/test-functions-declaration.c @@ -0,0 +1,16 @@ +/* Test declaring twice a function pinter a struct member + * gcc -gctf -c test-functions-declaration.c -o \ + * test-functions-declaration.o + */ +void +attribute_container_add_device( + void (*fn1)(int, long)) +{ +} + +void +attribute_container_device_trigger( + void (*fn2)(int , long)) +{ + +} diff --git a/tests/data/test-read-ctf/test-functions-declaration.o b/tests/data/test-read-ctf/test-functions-declaration.o new file mode 100644 index 0000000000000000000000000000000000000000..4ffe85248b080b80fd75debbfb457578bea9ef7d GIT binary patch literal 1848 zcmbtUL2J}d5T3NPt=dWzDMCf!$rjDaZVw)c%1W^)82Guci#5-x+3VnyqWoCzBkExle~ZOY-7Unz=#Kr;4CsIK!5Vg zZw%Z9%)=aPZykT%I)2wb+5KX>+5U&^5*mH6~DeJ zYNF<^)>i9vRDW4@4^)}96~0HtrvrRCgA+p*o}%}eFe4tvd<$@$6W-ew;B^`OvZO=_gUj=@LIBdT6o%LoL{!O-p-Pphs5K_dYo zswxmT4!9I;x>68%p_RZp3@R<-*BrOW2C0{(z_Bj>4(4gT{*`|Zx$d6S()54hB%KiI%&!s2 zlCNBN*TTp(d}G%v%q~4O1vWUQ_9ebAOJ|03gDHZpzYzZxM!$351o2)naG Ol}8L_L)vI{`M&^>zQy(c literal 0 HcmV?d00001 diff --git a/tests/data/test-read-ctf/test-list-struct.abi b/tests/data/test-read-ctf/test-list-struct.abi new file mode 100644 index 00000000..196a79a1 --- /dev/null +++ b/tests/data/test-read-ctf/test-list-struct.abi @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-read-ctf/test-list-struct.c b/tests/data/test-read-ctf/test-list-struct.c new file mode 100644 index 00000000..a1161923 --- /dev/null +++ b/tests/data/test-read-ctf/test-list-struct.c @@ -0,0 +1,11 @@ +/* Test a ADT where a struct member is a pointer to + * itself. + * gcc -gctf -c test-callback.c -o test-callback.o + */ + +struct rb_node_b { + struct rb_node_b *this; + int a; +}; + +struct rb_node_b n1, n2; diff --git a/tests/data/test-read-ctf/test-list-struct.o b/tests/data/test-read-ctf/test-list-struct.o new file mode 100644 index 0000000000000000000000000000000000000000..7741f37f1fd925b761ae850b6da12924f7fdd64d GIT binary patch literal 1344 zcmb7D%We}f6unbIC{#jJLOcqKfeo!-Jee%JKqFPO5<=`)qSiAp&4_uVV@FC>@Hu=2 zf5JDw55PT%-567lxYDujJ@*{PzM6b`_2zghipWJoFKJUbmgw`=CeK%CPCImqeta8T zb{=mew9Pqi$0FwajL|c2KJbun&%)KN$A|90yTd@>NA5Cm#x;hG+t5SDF&yv`u>c01v@$?vaPPmF|K zHbxe_n|{4dU1rq6kid*c6k3zu`S8*;crA&xGfMF5cu=zZXzTNKE@pklGcn8X*8g8W zVhd(446J!jyE2^T6K;U>zNwWoU#)*Gq5m06@SXq79|uQV&fD@Ycn{A+E62hy44Oen z8Ee3eAok+e3ZHu%Qs;O3p~v~s3n%c&E3~hfyTQQ!(~pJqhxfv){D3U