From nobody Mon May 20 19:51:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1685442721; cv=none; d=zohomail.com; s=zohoarc; b=YS6/fHN4tx5P7lxkqfpJ2l98ubHHk8liZQ+J+EQ3aw5nQ9K51Ild/GubkAoZ/yhGMw7xDfpL0IG6d5EYqzsgVRwD8N6aAgOEAIG4TPUEtWtx7PJFm/vTm8lZD7riOlxPUCGIOfrc1d4EYmsf9o6+hZPpi8gnGCcOqaKRF1GC2Ts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685442721; h=Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=HGnsKT/BoLxlgtGEWcpQLPM840S7huGV4UWXiK6XqWA=; b=l6v1yx+kP9emClWnME0p4ect2WZFyrAW76K0HGIDXvj27jvJhW267LNo2oGVwLZvRfUQ5cAa6C0PCjfGsMcCpBJKT8dOqYva5jmqZAPEz9fCUPMeT9ZvGw7fDod71/pBKEor1FhlTMCOuZ31nGHC9GZPWP5pHkU76zLV668dx9g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685442721978507.65107230460933; Tue, 30 May 2023 03:32:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q3wdd-00038a-Id; Tue, 30 May 2023 06:31:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q3wdX-00037C-5C for qemu-devel@nongnu.org; Tue, 30 May 2023 06:31:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q3wdV-0005PE-ID for qemu-devel@nongnu.org; Tue, 30 May 2023 06:31:30 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-142-YssouvvfOGuOhZbV5R0L2w-1; Tue, 30 May 2023 06:31:26 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CFE1C381D4C5 for ; Tue, 30 May 2023 10:31:25 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A7EAC154D1 for ; Tue, 30 May 2023 10:31:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685442688; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=HGnsKT/BoLxlgtGEWcpQLPM840S7huGV4UWXiK6XqWA=; b=fTnEM2RViwVEULVaYA0a2BsqfkW39LJ0SwELEpFLLRBlShFVhMvI0CIVayoGn1713lcR+I TKQFd3EHqhuNC6LF+dLUUR6Xqg6byMZepKcqI6caZYdW8QhWCuydANl9Q/QCuLUMRF3RQd 05p6zVzcr5rOkD5o1iowsH8/UlCXGpw= X-MC-Unique: YssouvvfOGuOhZbV5R0L2w-1 From: Michal Privoznik To: qemu-devel@nongnu.org Subject: [PATCH v3] meson: Avoid implicit declaration of functions Date: Tue, 30 May 2023 12:31:23 +0200 Message-Id: <8e02776d18595a1c575c90a189ff65f1785f76ca.1685442612.git.mprivozn@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=mprivozn@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.16, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1685442722280100001 Content-Type: text/plain; charset="utf-8" While detecting a presence of a function via 'cc.links()' gives desired result (i.e. detects whether function is present), it also produces a warning on systems where the function is not present (into meson-log.txt), e.g.: qemu.git/build/meson-private/tmph74x3p38/testfile.c:2:34: \ warning: implicit declaration of function 'malloc_trim' [-Wimplicit-funct= ion-declaration] And some distributions (e.g. Gentoo) parse the meson log and consider these erroneous because it can lead to feature misdetection (see [1]). We can check whether given function exists via 'cc.has_function()' or whether STATX_* macros exist via 'cc.has_header_symbol()'. 1: https://wiki.gentoo.org/wiki/Modern_C_porting Resolves: https://bugs.gentoo.org/898810 Signed-off-by: Michal Privoznik --- v3 of https://lists.gnu.org/archive/html/qemu-devel/2023-05/msg07210.html diff to v2: - Expanded commit message to explain why we need this. meson.build | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/meson.build b/meson.build index 2d48aa1e2e..21061b19d4 100644 --- a/meson.build +++ b/meson.build @@ -1797,8 +1797,7 @@ malloc =3D [] if get_option('malloc') =3D=3D 'system' has_malloc_trim =3D \ get_option('malloc_trim').allowed() and \ - cc.links('''#include - int main(void) { malloc_trim(0); return 0; }''') + cc.has_function('malloc_trim', prefix: '#include ') else has_malloc_trim =3D false malloc =3D cc.find_library(get_option('malloc'), required: true) @@ -1811,34 +1810,19 @@ if not has_malloc_trim and get_option('malloc_trim'= ).enabled() endif endif =20 -# Check whether the glibc provides statx() - gnu_source_prefix =3D ''' #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif ''' -statx_test =3D gnu_source_prefix + ''' - #include - int main(void) { - struct statx statxbuf; - statx(0, "", 0, STATX_BASIC_STATS, &statxbuf); - return 0; - }''' =20 -has_statx =3D cc.links(statx_test) +# Check whether the glibc provides STATX_BASIC_STATS + +has_statx =3D cc.has_header_symbol('sys/stat.h', 'STATX_BASIC_STATS', pref= ix: gnu_source_prefix) =20 # Check whether statx() provides mount ID information =20 -statx_mnt_id_test =3D gnu_source_prefix + ''' - #include - int main(void) { - struct statx statxbuf; - statx(0, "", 0, STATX_BASIC_STATS | STATX_MNT_ID, &statxbuf); - return statxbuf.stx_mnt_id; - }''' - -has_statx_mnt_id =3D cc.links(statx_mnt_id_test) +has_statx_mnt_id =3D cc.has_header_symbol('sys/stat.h', 'STATX_MNT_ID', pr= efix: gnu_source_prefix) =20 have_vhost_user_blk_server =3D get_option('vhost_user_blk_server') \ .require(targetos =3D=3D 'linux', --=20 2.39.3