From nobody Fri Apr 19 22:04:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1678907451; cv=none; d=zohomail.com; s=zohoarc; b=cRGVwSZDFGhsdIHB6AXg8L1yJYrMpjzIxuUuvolP2y2EGwv13YVVcn9rsi9RiK8MkWCEm8jB7/zmIhiQFfVeNseiD+eeQZqixr/6lUPvpETj3QWGaTWF1P8cI/b0S9gAZJ0RMKZ6vwN39NzPrMqVRadqqJ/YgujyYviZsMwAKuU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678907451; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aEVD7ZcEtZRgMmVRxIwWA8FRvmWquCL1xL6LnGohUXM=; b=HaFjuGWJMsh7d4qUZQItIxKAEbQFRGujgKZRtEnaJNZnsabziltezR/Dbzn9+LI00IjHfrLxZc22+3aF4P1iZ9Fu0whEgDBUl1M4T5l7HWy6h6da1ljlabbJ/hFWskWCRMVtCekEFvtQnfIOx9n6MNPH7QX11TUtcu3CuojRlPE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1678907451646594.7816675089712; Wed, 15 Mar 2023 12:10:51 -0700 (PDT) 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-38-LkP55DdxOtaukiD6mdO-Ug-1; Wed, 15 Mar 2023 15:10:46 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5392F1C0513D; Wed, 15 Mar 2023 19:10:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC9F740C6E68; Wed, 15 Mar 2023 19:10:39 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7DFC71946A40; Wed, 15 Mar 2023 19:10:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2F61A1946597 for ; Wed, 15 Mar 2023 19:10:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 05A371121315; Wed, 15 Mar 2023 19:10:37 +0000 (UTC) Received: from localhost.localdomain (unknown [10.45.224.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 962681121314 for ; Wed, 15 Mar 2023 19:10:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678907450; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=aEVD7ZcEtZRgMmVRxIwWA8FRvmWquCL1xL6LnGohUXM=; b=KRIkIg2L7IhJP42zmqLxa/sRYt5WlfxXqq4QbL8xurLheL/yt9zHfq3eDmo6wIvKNEpKqB 20f4sSpDBJxjrXWFA5uv+jIZxPEpSJYae07NuF538ydcEUE9yPVZRDJMrKqbol/HqHvXqg uCorfBhuZyLIL+2bgKBdRc1eCWN3A9g= X-MC-Unique: LkP55DdxOtaukiD6mdO-Ug-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] internal.h: Invent VIR_OPTNONE Date: Wed, 15 Mar 2023 20:10:27 +0100 Message-Id: <9b05ec1df83d3c9a87d906897addcdbaf63fe0b3.1678905782.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678907452194100005 Content-Type: text/plain; charset="utf-8"; x-default="true" The clang compiler behaves very aggressively when optimizing some functions. So much so that it in fact breaks our mocking (or any LD preloading for that matter). For instance, for the following code: int X(void) G_NO_INLINE; int Y(void); int X(void) { return -1; } int Y(void) { if (X() < 0) return -1; return 42; } the following assembler is generated: 0000000000118090 : 118090: b8 ff ff ff ff mov $0xffffffff,%eax 118095: c3 ret 00000000001180a0 : 1180a0: b8 ff ff ff ff mov $0xffffffff,%eax 1180a5: c3 ret It's clear that Y() does not even attempt to call X(). Therefore, even if we provided an alternative implementation (or anybody else for that matter), it is not even called. Note, this happens only with optimizations enabled, i.e. -O1 and bigger. For -O0 clang does the right thing. Fortunately, it offers a way to disable optimizations on a per-function basis. From our example, if X() and Y() are written like this: int __attribute__((optnone)) X(void) { return -1; } int __attribute__((optnone)) Y(void) { if (X() < 0) return -1; return 42; } then the expected happen, regardless of optimization setting. Therefore, introduce VIR_OPTNONE macro which sets this attribute when building with clang. Fortunately, other compilers realize that they can not do this optimization for non-static functions and thus VIR_OPTNONE can be empty for them. Signed-off-by: Michal Privoznik --- src/internal.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/internal.h b/src/internal.h index 9dc34a0bf5..cf6f314648 100644 --- a/src/internal.h +++ b/src/internal.h @@ -552,3 +552,23 @@ enum { # define fprintf(fh, ...) g_fprintf(fh, __VA_ARGS__) =20 #endif /* VIR_NO_GLIB_STDIO */ + +/* Ideally, we would not need this. But, we want to work with + * broken compilers. Use this to disable optimizations for a + * function, like this: + * + * int VIR_OPTNONE + * virMyFunction(int arg) + * { + * ... + * } + * + * Do NOT use in the header file as it has no effect there. This + * is intended to be used for functions that (might) call or be + * called from mocked function. + */ +#if defined(__clang__) +# define VIR_OPTNONE __attribute__((optnone)) +#else +# define VIR_OPTNONE +#endif --=20 2.39.2 From nobody Fri Apr 19 22:04:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1678907448; cv=none; d=zohomail.com; s=zohoarc; b=TqXY1/wSPvcCJk3FlP6kx7sh7YYK6QrbKCq95b4hR8F+Q1/MfimNdzb83a/SeyXWmu9JPhmKW8krDxdrzTmfWZx6Obuj3hitzzGoQc5VBqOqYzZdNAdgxlqX7HvHKQA+a4ZV663mZrIu5P9BOSt6pSs2YMr18MFFIKBdre9jEuY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678907448; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JaZ6JmAXPQnjPTtk3PQFRVpXSx8b5XjRY5kdtbfMgOE=; b=Me79JWuvYTbO1ZwLPKUE22BpjDNoTn+47Rq0R2DbvmaAdCjlU1ZC4zM9Q672Jj7zMg0rFrbUyqR2RJf2Q39mWfqVOYfQVp0dxAcy89eRdnmD1zQ3TaBvW7AJ47kyvtE2mkfkePJ3ibQ9vXHogp4inz2cqS/Gb9QWwXWS65Mddvo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1678907448687260.4128863698422; Wed, 15 Mar 2023 12:10:48 -0700 (PDT) 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-649-lbIXdQpoPNmInNDIhffYEw-1; Wed, 15 Mar 2023 15:10:43 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 530AD3C1178D; Wed, 15 Mar 2023 19:10:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 231D61121320; Wed, 15 Mar 2023 19:10:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E29071946A42; Wed, 15 Mar 2023 19:10:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B2E701946A47 for ; Wed, 15 Mar 2023 19:10:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A3D841121314; Wed, 15 Mar 2023 19:10:37 +0000 (UTC) Received: from localhost.localdomain (unknown [10.45.224.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 416C01121315 for ; Wed, 15 Mar 2023 19:10:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678907447; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=JaZ6JmAXPQnjPTtk3PQFRVpXSx8b5XjRY5kdtbfMgOE=; b=Ob1q38jmBTSr1ZeZGiUqJvEU73wgHH9pcKwY167yZm4hVgiid9+04oh9n6+0U2OSUL1a26 kuB7CIhjneJpdfAWhaUmvY9Q1tHZ1GTm+5Aqn3yRBApiPmhecGl6ICJfhOTd9L5mIAovO9 D2KRi3Vt/pcgIbBEe9QJ4+0fgKu3BKs= X-MC-Unique: lbIXdQpoPNmInNDIhffYEw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/2] virnuma: Annotate some functions as VIR_OPTNONE Date: Wed, 15 Mar 2023 20:10:28 +0100 Message-Id: <73ed49d1b19c23e8931b2b79596d7fd4f3afbcff.1678905782.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678907450187100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Use newly introduced VIR_OPTNONE to stop clang from optimizing our code so much that it ends up doing something else than it's supposed to do. The chosen functions are "random", until qemuxml2argvtest stops failing (modulo one test case which uses virNumaCPUSetToNodeset() and no matter what clang ignores optnone request). Signed-off-by: Michal Privoznik --- src/util/virnuma.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/util/virnuma.c b/src/util/virnuma.c index 4a15bf32c8..156b2e7bca 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -339,14 +339,14 @@ virNumaSetupMemoryPolicy(virDomainNumatuneMemMode mod= e G_GNUC_UNUSED, return 0; } =20 -bool +bool VIR_OPTNONE virNumaIsAvailable(void) { return false; } =20 =20 -int +int VIR_OPTNONE virNumaGetMaxNode(void) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -355,7 +355,7 @@ virNumaGetMaxNode(void) } =20 =20 -int +int VIR_OPTNONE virNumaGetNodeMemory(int node G_GNUC_UNUSED, unsigned long long *memsize, unsigned long long *memfree) @@ -371,7 +371,7 @@ virNumaGetNodeMemory(int node G_GNUC_UNUSED, } =20 =20 -int +int VIR_OPTNONE virNumaGetNodeCPUs(int node G_GNUC_UNUSED, virBitmap **cpus) { @@ -382,7 +382,7 @@ virNumaGetNodeCPUs(int node G_GNUC_UNUSED, return -1; } =20 -int +int VIR_OPTNONE virNumaGetNodeOfCPU(int cpu G_GNUC_UNUSED) { errno =3D ENOSYS; @@ -476,7 +476,7 @@ virNumaGetDistances(int node, =20 #else /* !WITH_NUMACTL */ =20 -bool +bool VIR_OPTNONE virNumaNodeIsAvailable(int node) { int max_node =3D virNumaGetMaxNode(); @@ -489,7 +489,7 @@ virNumaNodeIsAvailable(int node) } =20 =20 -int +int VIR_OPTNONE virNumaGetDistances(int node G_GNUC_UNUSED, int **distances, int *ndistances) @@ -938,7 +938,7 @@ virNumaGetPageInfo(int node G_GNUC_UNUSED, } =20 =20 -int +int VIR_OPTNONE virNumaGetPages(int node G_GNUC_UNUSED, unsigned int **pages_size G_GNUC_UNUSED, unsigned long long **pages_avail G_GNUC_UNUSED, @@ -963,7 +963,7 @@ virNumaSetPagePoolSize(int node G_GNUC_UNUSED, } #endif /* #ifdef __linux__ */ =20 -bool +bool VIR_OPTNONE virNumaNodesetIsAvailable(virBitmap *nodeset) { ssize_t bit =3D -1; @@ -1024,7 +1024,7 @@ virNumaGetHostMemoryNodeset(void) * Returns: 0 on success, * -1 on failure (with error reported) */ -int +int VIR_OPTNONE virNumaCPUSetToNodeset(virBitmap *cpuset, virBitmap **nodeset) { --=20 2.39.2