From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EE543459DD; Fri, 20 Sep 2024 08:34:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0F853433E4; Fri, 20 Sep 2024 08:34:01 +0200 (CEST) Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2081.outbound.protection.outlook.com [40.107.105.81]) by mails.dpdk.org (Postfix) with ESMTP id 73B4B40A87 for ; Fri, 20 Sep 2024 08:33:58 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Y8YC7Q1hUO1D9kADyp5nciSOZv4zRC9fbP36vtaOYG1vPxSBp3s77amR8sNAb7iLBm3UK2QaIg6n7X9LIwMG+77oWu/Te4+OQReA9ODf/5A7zt6KRytH45qG9y2SlBBxtqiO6b29eKGYXsBcspGofrFQUs1FfTcuBNJIJ37obP3RN1TuR0vk0dYAol13hlXXoMLNLV/GH/9lqGGadZzIZAyQykA8gOBPSEQm0tk3uWC9qLkUdJ8fcqd8h3nWqtNL92FVFU9Bnhw04ehk2UBzIFpUh6d3GXCnL2SChWlzKmX3jTsxRMWPQaS5iXndu8VxuvGxd5OiDqMPBaR0n/DDOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=hZgLen4A+BBWd12Ga6afxy0kxDaAlPub+Wrp6NWJS5s=; b=NzbKZHWcWGRWTXjneUFSd6Jo6AU9i67VzZUL0aLxbej+TaU83V+inzfyairFuqiFQ7+pDXsblqSiEhyHD2yg7F5nYzPNiXaBSfjvBGagm0cbLJkWnfDLbQuy+RXOucESpwiZ1wem8b9Xk7dmlvUel0EJOLHhK5yIwS3nth4ec5DdLtjdS9I2bLzAyCpe3+SeeBxkusrqbuvSNnlKXcrMHHqm57XjyHjuX7GzDYsRD2VCxvP3bUnqB/mCd+XyVlFponhaFwWkmRqkd9tbpxJG9xn1JK6TkTaN0jvDeNAAjtfdRXIElOa2NeNlyM1jqC6Wk8lhGedOP/zNRaTu5InSVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=dpdk.org smtp.mailfrom=ericsson.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ericsson.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hZgLen4A+BBWd12Ga6afxy0kxDaAlPub+Wrp6NWJS5s=; b=odr0/LtskdRxgYMPX8LRO2tYsf68/PvZ6q62q/p7pwwsTuPb48YEgr7SGJWNPbdjAKjWbj9k8V+Gn5hIUcZfSthtGCE8kVd/YKJQW+aLzPeh9ByIighj4TXPSjDkygzOGbfxeVHotCjdYqmb/G+ElXibIVizCFYFywLGdHWOVWIRHQrT5YJrui8H1w7brI+2ykXSqpNcZo++A9lyGAQGlZrkPkwDjr4Hr4Zo/KQK3m6xQcJBNi8teZDFdyG44Vz7/+TMaoQ8xrszFsJNvOFyOddJc9gINFTw+CAMYrOd+Jr/eKgi84jNiItMc7SajUY6udBEm3j5zTk5y5roaEX+5Q== Received: from DUZPR01CA0297.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b7::8) by AM9PR07MB7713.eurprd07.prod.outlook.com (2603:10a6:20b:2ff::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.22; Fri, 20 Sep 2024 06:33:55 +0000 Received: from DU2PEPF00028D0E.eurprd03.prod.outlook.com (2603:10a6:10:4b7:cafe::80) by DUZPR01CA0297.outlook.office365.com (2603:10a6:10:4b7::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.29 via Frontend Transport; Fri, 20 Sep 2024 06:33:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by DU2PEPF00028D0E.mail.protection.outlook.com (10.167.242.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 20 Sep 2024 06:33:55 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.64) with Microsoft SMTP Server id 15.2.1544.11; Fri, 20 Sep 2024 08:33:53 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id 7B0181C006D; Fri, 20 Sep 2024 08:33:53 +0200 (CEST) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: CC: , Heng Wang , "Stephen Hemminger" , Tyler Retzlaff , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Jack Bond-Preston , David Marchand , Chengwen Feng , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [PATCH v11 1/7] buildtools/chkincs: relax C linkage requirement Date: Fri, 20 Sep 2024 08:24:31 +0200 Message-ID: <20240920062437.738706-2-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240920062437.738706-1-mattias.ronnblom@ericsson.com> References: <20240919193124.737943-2-mattias.ronnblom@ericsson.com> <20240920062437.738706-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D0E:EE_|AM9PR07MB7713:EE_ X-MS-Office365-Filtering-Correlation-Id: 610fb58d-1dff-4c91-b474-08dcd93e3346 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?B?M1FmQTlHM1hqQlUyKzRpU2pQT1ZpSTNxbWd1NGJ3Z2sxRFJ6T29MTjhtTFpy?= =?utf-8?B?TjdERGNudERYNFk2VVA4bi9aZEl6TXBRRDJzREtVdzNtYjBOZmpXbUhBNCt5?= =?utf-8?B?WWJlOFFGd2pxM2hld0dSV2hRelV4WEN5OCt1MzVPQ0VoYjAwdm95ZDRIMy9H?= =?utf-8?B?ZXJLT2pXN1ZzSkRwVHRhREpDaW5MSEx2TGN1SDZVQitpbWUyRWFCdy9hWHJT?= =?utf-8?B?a285dVQ5NUFtMjIzcWFKNmxQVFpWS2xGdXprNGhIRkZoVDdpZ2M1eThobDFq?= =?utf-8?B?elJPVEFwTnJPc1c5ZUdiLzVyeG10UllGdjdxQzJwVllaOXdpWm42bmJGYldz?= =?utf-8?B?b04raW5LYVZvVUJmQ2VqV1hlYXFBallhMElET3BBaHpvNG5SSStLbDBrLy9O?= =?utf-8?B?Mlg3ZWh6N0ZKSGcwYUlFZ1k2cDl5dURYU3luRmFrRGdrS0lTc2psNGF0ZnN4?= =?utf-8?B?SmFKbGhRQXNTclkyZklOYW9KKy9WZnZ6L2FLZ3RhOWxvbndvcUNCVmZUU3py?= =?utf-8?B?aUZKSFdEWnltYi9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?TWc3aWsxcHFkMWRUcjgwaHpkMXoyRmRUanZ1ekxFay80SWJBVnJxUTlISHRI?= =?utf-8?B?dWoxUWJNRStqNVNDOFRuSmtHY1R6MnJhcUdLR3JRaUNtTE9pemdGMXg3VXhz?= =?utf-8?B?L053cXRMVWtYSGtGbzM3SEpKaytIYWhoZnpJOUVqLzZWTWhRUjhEcWhzWWFo?= =?utf-8?B?d3c0SkpmemJZVk0yc3d3U21VRHZDaEFiTERGWWxKalFBK1NjQjNXYmYrMWc5?= =?utf-8?B?eHFMNlp0Q1o0SDBmWXNDUUVYYnVPRHdienlDdW5nckp6UVFrdUwrYzFvTDNW?= =?utf-8?B?UDJpZmZybkc4WElTM29YOGh2VC9ZNGV3MzNsSUZWYllFNVNXa1BwTy8yNlhr?= =?utf-8?B?Q2hUTUdVb0NOUER6TkJMSmExUk44NUtZbkJ5dXZKMDAveXI1YXRVQVFPek1R?= =?utf-8?Q?Cx4+WHAjOHrRU?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2024 06:33:55.0458 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 610fb58d-1dff-4c91-b474-08dcd93e3346 X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=92e84ceb-fbfd-47ab-be52-080c6b87953f; Ip=[192.176.1.74]; Helo=[oa.msg.ericsson.com] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028D0E.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR07MB7713 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Relax chkincs requirement of all DPDK header files having to contain 'extern "C"'. Instructing a C++ toolchain to use C linkage is only necessarily if the header file declares symbols (i.e., functions or global variables). With this change, chkincs tries to find if any functions or references to global variables are declared in the header file, and if not, no C linkage is required. Signed-off-by: Mattias Rönnblom -- PATCH v11: * Detect functions from the Windows POSIX wrappers, to avoid false positives for redundant 'extern "C"'. --- buildtools/chkincs/chkextern.py | 88 +++++++++++++++++++++++++++++++++ buildtools/chkincs/meson.build | 14 +++--- 2 files changed, 95 insertions(+), 7 deletions(-) create mode 100755 buildtools/chkincs/chkextern.py diff --git a/buildtools/chkincs/chkextern.py b/buildtools/chkincs/chkextern.py new file mode 100755 index 0000000000..5374ce1c72 --- /dev/null +++ b/buildtools/chkincs/chkextern.py @@ -0,0 +1,88 @@ +#! /usr/bin/env python3 +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2024 Ericsson AB + +import sys +import re + +def strip_cpp(header): + no_cpp = "" + header = header.replace("\\\n", " ") + + for line in header.split("\n"): + if re.match(r'^\s*#.*', line) is None and len(line) > 0: + no_cpp += "%s\n" % line + + return no_cpp + + +def strip_comments(header): + no_c_comments = re.sub(r'/\*.*?\*/', '', header, flags=re.DOTALL) + no_cxx_comments = re.sub(r'//.*', '', no_c_comments) + return no_cxx_comments + + +def strip(header): + header = strip_comments(header) + header = strip_cpp(header) + return header + + +def has_extern_c(header): + return header.find('extern "C"') != -1 + + +def has_vars(header): + return re.search(r'^extern\s+[a-z0-9_]+\s.*;', header, flags=re.MULTILINE) is not None + + +FUNCTION_RES = [ + r'rte_[a-z0-9_]+\(', + r'cmdline_[a-z0-9_]+\(', + r'vt100_[a-z0-9_]+\(', + r'rdline_[a-z0-9_]+\(', + r'cirbuf_[a-z0-9_]+\(', + # Windows UNIX compatibility + r'pthread_[a-z0-9_]+\(', + r'regcomp\(', + r'count_cpu\(' +] + + +def has_functions(header): + for function_re in FUNCTION_RES: + if re.search(function_re, header) is not None: + return True + return False + + +def has_symbols(header): + return has_functions(header) or has_vars(header) + + +def chk_missing(filename): + header = open(filename).read() + if has_symbols(header) and not has_extern_c(header): + print(filename) + + +def chk_redundant(filename): + header = open(filename).read() + if not has_symbols(header) and has_extern_c(header): + print(filename) + +if len(sys.argv) < 3: + print("%s missing|redundant ..." % sys.argv[0]) + sys.exit(1) + +op = sys.argv[1] +headers = sys.argv[2:] + +for header in headers: + if op == 'missing': + chk_missing(header) + elif op == 'redundant': + chk_redundant(header) + else: + print("Unknown operation.") + sys.exit(1) diff --git a/buildtools/chkincs/meson.build b/buildtools/chkincs/meson.build index f2dadcae18..762f85efe5 100644 --- a/buildtools/chkincs/meson.build +++ b/buildtools/chkincs/meson.build @@ -38,13 +38,13 @@ if not add_languages('cpp', required: false) endif # check for extern C in files, since this is not detected as an error by the compiler -grep = find_program('grep', required: false) -if grep.found() - errlist = run_command([grep, '--files-without-match', '^extern "C"', dpdk_chkinc_headers], - check: false, capture: true).stdout().split() - if errlist != [] - error('Files missing C++ \'extern "C"\' guards:\n- ' + '\n- '.join(errlist)) - endif +chkextern = find_program('chkextern.py') + +missing_extern_headers = run_command(chkextern, 'missing', dpdk_chkinc_headers, + capture: true, check: true).stdout().split() + +if missing_extern_headers != [] + error('Files missing C++ \'extern "C"\' guards:\n- ' + '\n- '.join(missing_extern_headers)) endif gen_cpp_files = generator(gen_c_file_for_header, -- 2.34.1