From nobody Wed Dec 17 08:54:40 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1745846528; cv=none; d=zohomail.com; s=zohoarc; b=n0ATvl8zsahRozgFZiRij2yTjgQPcLFTpLfOdc8OFgndcaOot31KBLars6O2qFVG68vvfFiXcwxl/qp8+7JFYfpuw+Mg02b3fNPUsw13FBvTd55sCfOCsinxF//wS4bklGUkjDgXCPuxylaI6T5QCYk/zwhPg2JqSgGykEDlIOU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745846528; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=uDs8GktRKWHwkhphV/v2pTEhUi3h3gL2rEoDPiB6QWc=; b=kCNeepZXLX6+HOWA+gLXq/s2ULOo03dCb/TMUHosiagXI/m23akpPbVB+WnhEHZLbk2Mru6Ge1/Mn77PBwtZGXD5XErCumfHTi/p0Fh96dHVIECiWiPoZRH7xFFnlwyBM1mHD9sVaX51lK1i79BTy6Bguy0Gp5b5d/BClHNgZlM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1745846528954909.3632204756125; Mon, 28 Apr 2025 06:22:08 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E6892E8A; Mon, 28 Apr 2025 09:22:07 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2040511AC; Mon, 28 Apr 2025 09:21:14 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 5390FAE4; Mon, 28 Apr 2025 09:21:10 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 3843D996 for ; Mon, 28 Apr 2025 09:21:06 -0400 (EDT) Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-639-CSvlM6MJNGCcjDJn5IEshw-1; Mon, 28 Apr 2025 09:21:04 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A911119560A1 for ; Mon, 28 Apr 2025 13:21:03 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.3.236]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1113419560A3 for ; Mon, 28 Apr 2025 13:21:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745846465; h=from:from: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; bh=AiVhgK0URMmoGYODikskgVxaobZp/JZbMrhBozC2KuI=; b=MJooAYwUCF6lW6yxpoYAOi/HqDNGhurWMMKgwG1lKqXWvB5dlAHaJG8WlYqxocaOJohTfs 0J2X3QisRz2SdAYGCuhBjz7APi2lrpWUar/KQ64rbnIKKY9x9tC0BHR1/OW80ZrTCtxeK7 G4TgmH1iNIW00iCnQIkK03hxjmp10mo= X-MC-Unique: CSvlM6MJNGCcjDJn5IEshw-1 X-Mimecast-MFC-AGG-ID: CSvlM6MJNGCcjDJn5IEshw_1745846463 To: devel@lists.libvirt.org Subject: [PATCH 1/3] internal: Introduce ATTRIBUTE_NOIPA Date: Mon, 28 Apr 2025 15:20:56 +0200 Message-ID: <1b00aeaec5af92bfc0dda9cf4c352cd63c86ac96.1745846174.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: iDGDUrXaQc5NF_EOP3ytNz-NqWyMwrS6Ypnxe3EMiSw_1745846463 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: JTPHGITWR2VCTJGCKQVUGY7TF6LVO52F X-Message-ID-Hash: JTPHGITWR2VCTJGCKQVUGY7TF6LVO52F X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1745846530288019100 Content-Type: text/plain; charset="utf-8" From: Michal Privoznik Currently, if we want to mock a function the noinline attribute is appended after the function (via G_NO_INLINE macro). This used to work for non pure functions. But there are some trivial functions (for instance virQEMUCapsProbeHVF()) that are pure, i.e. have no side effect, and while their call from other parts of the code is not optimized out, their call from within the same compilation unit (qemu_capabilities.c) is optimized out. This is because inlining and semantic interposition are two different things. Even GCC's documentation for noinline attribute [1] states that clearly: This function attribute prevents a function from being considered for inlining. It also disables some other interprocedural optimizations; it=E2=80=99s preferable to use the more comprehensive noipa attribute instead if that is your goal. Even if a function is declared with the noinline attribute, there are optimizations other than inlining that can cause calls to be optimized away if it does not have side effects, although the function call is live. Unfortunately, despite attempts [2] Clang still does not support the attribute and thus we have to rely on noinline + -fsemantic-interposition combo. 1: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index= -noinline-function-attribute 2: https://reviews.llvm.org/D101011 Signed-off-by: Michal Privoznik --- docs/coding-style.rst | 2 +- scripts/cocci-macro-file.h | 1 + src/internal.h | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/docs/coding-style.rst b/docs/coding-style.rst index fe5fe9a906..81382f11d4 100644 --- a/docs/coding-style.rst +++ b/docs/coding-style.rst @@ -633,7 +633,7 @@ analysis tools understand the code better: ``G_GNUC_FALLTHROUGH`` allow code reuse by multiple switch cases =20 -``G_NO_INLINE`` +``ATTRIBUTE_NOIPA`` the function is mocked in the test suite =20 ``G_GNUC_NORETURN`` diff --git a/scripts/cocci-macro-file.h b/scripts/cocci-macro-file.h index c3112663d1..b26018c20b 100644 --- a/scripts/cocci-macro-file.h +++ b/scripts/cocci-macro-file.h @@ -21,6 +21,7 @@ =20 #pragma once =20 +#define ATTRIBUTE_NOIPA #define ATTRIBUTE_NONNULL(x) #define ATTRIBUTE_PACKED =20 diff --git a/src/internal.h b/src/internal.h index 20aa9b1d41..b96661249e 100644 --- a/src/internal.h +++ b/src/internal.h @@ -177,6 +177,27 @@ # endif #endif =20 +/** + * + * ATTRIBUTE_NOIPA + * + * Force compiler to disable interprocedural optimizations between the + * function with this attribute and its callers. This implies noinline + * attribute and some others and allows us to mock functions even if + * they are pure. + * + * WARNING: on compilers which don't support the attribute (clang) this + * is silently declared as noinline which in combination with + * -fsemantic-interposition option does roughly the same. + */ +#ifndef ATTRIBUTE_NOIPA +# if defined(__has_attribute) && __has_attribute(noipa) +# define ATTRIBUTE_NOIPA __attribute__((noipa)) +# else +# define ATTRIBUTE_NOIPA G_NO_INLINE +# endif +#endif + #define VIR_WARNINGS_NO_CAST_ALIGN \ _Pragma ("GCC diagnostic push") \ _Pragma ("GCC diagnostic ignored \"-Wcast-align\"") --=20 2.49.0