From nobody Mon Apr 29 17:06:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1603992462; cv=none; d=zohomail.com; s=zohoarc; b=Ru2Dl/oRKyB0wRdvBDXulh1g3d8yC4S0EzShrbfoTIE5TLcOEGeTo/16L7JV6XZRx1almUbCjmUjUd3Uk+lohNxG7vm21/YmkNWIjCjlwEDxh3ldzsHBYX8LTbVOyz42PbOIbDv3yGxjkCd20UR2Kc0RDOpvI4LkRdMExofEkGg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992462; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=PVSjM6oxx1iIpgZgP4pqCvY4+op+oeh3knGULYjfd68=; b=AWY+2CfRTfaHmhQTIhaxDJIcedAOx7qjITxr6KKMW46h6OolByb7sY3XPjnv45uhZEPQt1b7ilTsyURQX7Vw+tHFuR4fM+JW6HGjwYwMoJ5E0mCw7FdfhPs6P/R/FrROBVlv2/w3p87QcVOficMJf32s3DxEmOA/wqhKVCiSkPU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1603992462981100.73323144295875; Thu, 29 Oct 2020 10:27:42 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-453-R8G1B-h8PhePj1SXWJ7J5Q-1; Thu, 29 Oct 2020 13:27:29 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AD1158014C1; Thu, 29 Oct 2020 17:27:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 41B4360CCC; Thu, 29 Oct 2020 17:27:21 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1A70D5810D; Thu, 29 Oct 2020 17:27:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09THPCD5008688 for ; Thu, 29 Oct 2020 13:25:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id AAF095B4BC; Thu, 29 Oct 2020 17:25:12 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-115-62.ams2.redhat.com [10.36.115.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4AFB5B4B2; Thu, 29 Oct 2020 17:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603992461; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=PVSjM6oxx1iIpgZgP4pqCvY4+op+oeh3knGULYjfd68=; b=gw7Pbem5HHixn8ZWky7zDotwgSypw9OkcAH9bqBHxyISJeS93Tnxy30f4D7WGR9izDeC5e wFrf46yOqSkkE/P9STajpJoS/o86sJVQO0qWUmNo1Oan3JoJtaBW9LDhpUivVgdQi/x9+y D+K9MTTApj5EjD4br94H9KC1Tl2t3zE= X-MC-Unique: R8G1B-h8PhePj1SXWJ7J5Q-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH] tests: fix stat mocking with Fedora rawhide Date: Thu, 29 Oct 2020 17:25:07 +0000 Message-Id: <20201029172507.96634-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Michal Privoznik X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) GLibC has a really complicated way of dealing with the 'stat' function historically, which means our mocks in turn have to look at four different possible functions to replace, stat, stat64, __xstat, __xstat64. In Fedora 33 and earlier: - libvirt.so links to __xstat64 - libc.so library exports stat, stat64, __xstat, __xstat64 - sys/stat.h header exposes stat and __xstat In Fedora 34 rawhide: - libvirt.so links to stat64 - libc.so library exports stat, stat64, __xstat, __xstat64 - sys/stat.h header exposes stat Historically we only looked at the exported symbols from libc.so to decide which to mock. In F34 though we must not consider __xstat / __xstat64 though because they only existance for binary compatibility. Newly built binaries won't reference them. Thus we must introduce a header file check into our logic for deciding which symbol to mock. We must ignore the __xstat / __xstat64 symbols if they don't appear in the sys/stat.h header, even if they appear in libc.so Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- Validated with this pipeline: https://gitlab.com/berrange/libvirt/-/pipelines/209361200 meson.build | 28 ++++++++++++----- tests/virmockstathelpers.c | 62 ++++++++++++++++++++++---------------- 2 files changed, 56 insertions(+), 34 deletions(-) diff --git a/meson.build b/meson.build index c3ba34bbe0..365c16d167 100644 --- a/meson.build +++ b/meson.build @@ -636,10 +636,6 @@ libvirt_export_dynamic =3D cc.first_supported_link_arg= ument([ # check availability of various common functions (non-fatal if missing) =20 functions =3D [ - '__lxstat', - '__lxstat64', - '__xstat', - '__xstat64', 'elf_aux_info', 'fallocate', 'getauxval', @@ -653,8 +649,6 @@ functions =3D [ 'getuid', 'getutxid', 'if_indextoname', - 'lstat', - 'lstat64', 'mmap', 'newlocale', 'pipe2', @@ -666,12 +660,23 @@ functions =3D [ 'setgroups', 'setns', 'setrlimit', - 'stat', - 'stat64', 'symlink', 'sysctlbyname', ] =20 +stat_functions =3D [ + '__lxstat', + '__lxstat64', + '__xstat', + '__xstat64', + 'lstat', + 'lstat64', + 'stat', + 'stat64', +] + +functions +=3D stat_functions + foreach function : functions if cc.has_function(function) conf.set('WITH_@0@'.format(function.to_upper()), 1) @@ -679,6 +684,13 @@ foreach function : functions endforeach =20 =20 +foreach function : stat_functions + if cc.has_header_symbol('sys/stat.h', function) + conf.set('WITH_@0@_DECL'.format(function.to_upper()), 1) + endif +endforeach + + # various header checks =20 headers =3D [ diff --git a/tests/virmockstathelpers.c b/tests/virmockstathelpers.c index 5c9759551d..3bd2437ffe 100644 --- a/tests/virmockstathelpers.c +++ b/tests/virmockstathelpers.c @@ -67,39 +67,49 @@ * - If __xstat & __xstat64 exist, then stat & stat64 will not exist * as symbols in the library, so the latter should not be mocked. * + * - If __xstat exists in the library, but not the header than it + * it is just there for binary back compat and should not be + * mocked + * * The same all applies to lstat() */ =20 =20 +#if !defined(WITH___XSTAT_DECL) +# if defined(WITH_STAT) +# if !defined(WITH___XSTAT) && !defined(WITH_STAT64) || defined(__APPLE__) +# define MOCK_STAT +# endif +# endif +# if defined(WITH_STAT64) +# define MOCK_STAT64 +# endif +#else /* WITH___XSTAT_DECL */ +# if defined(WITH___XSTAT) && !defined(WITH___XSTAT64) +# define MOCK___XSTAT +# endif +# if defined(WITH___XSTAT64) +# define MOCK___XSTAT64 +# endif +#endif /* WITH___XSTAT_DECL */ =20 -#if defined(WITH_STAT) -# if !defined(WITH___XSTAT) && !defined(WITH_STAT64) || defined(__APPLE__) -# define MOCK_STAT +#if !defined(WITH___LXSTAT_DECL) +# if defined(WITH_LSTAT) +# if !defined(WITH___LXSTAT) && !defined(WITH_LSTAT64) || defined(__APPLE= __) +# define MOCK_LSTAT +# endif # endif -#endif -#if defined(WITH_STAT64) && !defined(WITH___XSTAT64) -# define MOCK_STAT64 -#endif -#if defined(WITH___XSTAT) && !defined(WITH___XSTAT64) -# define MOCK___XSTAT -#endif -#if defined(WITH___XSTAT64) -# define MOCK___XSTAT64 -#endif -#if defined(WITH_LSTAT) -# if !defined(WITH___LXSTAT) && !defined(WITH_LSTAT64) || defined(__APPLE_= _) -# define MOCK_LSTAT +# if defined(WITH_LSTAT64) +# define MOCK_LSTAT64 # endif -#endif -#if defined(WITH_LSTAT64) && !defined(WITH___LXSTAT64) -# define MOCK_LSTAT64 -#endif -#if defined(WITH___LXSTAT) && !defined(WITH___LXSTAT64) -# define MOCK___LXSTAT -#endif -#if defined(WITH___LXSTAT64) -# define MOCK___LXSTAT64 -#endif +#else /* WITH___LXSTAT_DECL */ +# if defined(WITH___LXSTAT) && !defined(WITH___LXSTAT64) +# define MOCK___LXSTAT +# endif +# if defined(WITH___LXSTAT64) +# define MOCK___LXSTAT64 +# endif +#endif /* WITH___LXSTAT_DECL */ =20 #ifdef MOCK_STAT static int (*real_stat)(const char *path, struct stat *sb); --=20 2.28.0