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 550A3A09E4; Thu, 28 Jan 2021 14:36:42 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 06CB84067A; Thu, 28 Jan 2021 14:36:42 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id 40C8840395 for ; Thu, 28 Jan 2021 14:36:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611840999; h=from:from: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: in-reply-to:in-reply-to:references:references; bh=BWPCUFIpRQHzd6LjEHWfR8TIaclE65Gr5x9KKYeQwlc=; b=fAyqAeg0tr+AIuTDw0iOl4/tsAY5442JiY+mce2IX1EMX3+k23ziqJdPKlyzCKFWxtANso NIbgdZwZtlcgRCc8n26fgNPl/Zk+qrRjIPQ4zEM/RrUUoi75C9Jh/79lTsUOG0CLWoZ06C khtAVaoNlgpxvflErjIZYyDjDqrqv6A= Received: from mail-ua1-f70.google.com (mail-ua1-f70.google.com [209.85.222.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-63-mKJvEKUpODOLC4NdnAdfCg-1; Thu, 28 Jan 2021 08:36:36 -0500 X-MC-Unique: mKJvEKUpODOLC4NdnAdfCg-1 Received: by mail-ua1-f70.google.com with SMTP id c18so1537721uao.20 for ; Thu, 28 Jan 2021 05:36:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=BWPCUFIpRQHzd6LjEHWfR8TIaclE65Gr5x9KKYeQwlc=; b=CHVj3DOj1Qo1R4juTQ+tkWebfD5iCf05CaKndbMixlM7BuLG9pCksZ0u49vsSq759W +I/sD3WE9S6+eWY/7lTlD1gLEf31+xxeA00ogL/Q8sYgJDSjSnX5tUJhutAwM5Q1cGyg IW07OzLN2TvTp65naAyN37jwEPNMmbGxa9z7laMf75UTm17zsjaI0tql0I5L4NxPckdn xGS8Kp3bPuvt0gpZzSWJnMLy1E6bstnqrGxbosKb6wYs5dNprVZkmN5TL+sYG2zafi8d vNASgaYhmZ8TrvRzhgPVxKSkyTazleOBSjwhsinw8hFttmYZY6qQBbqZOY+49BsRsL5j A3uA== X-Gm-Message-State: AOAM530HBvNEe+PtsY2EvNhz13sWQnDsP2YqL7aiqJxqKPnID3qHmWAn Ig19ickxDPzWSJKARU5RFuWjS4pX1OWWgnSTiBI5WffkW9lDA1LO8kujX/3TTUVrFIuSFZDE29H 3JWZauWorz4MUazke5mc= X-Received: by 2002:a1f:cec1:: with SMTP id e184mr11234399vkg.17.1611840996366; Thu, 28 Jan 2021 05:36:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJw99DlKsgdheGa0+CD+iduONLLWgXPpG696XwxxxGB1h24/a3EX9BmRx9WrysQOE+zqUa1EtbGnQNnzxxHDpiM= X-Received: by 2002:a1f:cec1:: with SMTP id e184mr11234381vkg.17.1611840996089; Thu, 28 Jan 2021 05:36:36 -0800 (PST) MIME-Version: 1.0 References: <20210114110606.21142-1-bruce.richardson@intel.com> <20210127173330.1671341-1-bruce.richardson@intel.com> <20210127173330.1671341-3-bruce.richardson@intel.com> <20210128112007.GA899@bricha3-MOBL.ger.corp.intel.com> In-Reply-To: <20210128112007.GA899@bricha3-MOBL.ger.corp.intel.com> From: David Marchand Date: Thu, 28 Jan 2021 14:36:25 +0100 Message-ID: To: Bruce Richardson Cc: dev , "Wang, Haiyue" , Ray Kinsella , Neil Horman Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmarchan@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [dpdk-dev] [PATCH v6 2/8] eal: fix error attribute use for clang 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 Sender: "dev" On Thu, Jan 28, 2021 at 12:20 PM Bruce Richardson wrote: > > If the compiler has neither error or diagnose_if support, an internal > > API can be called without ALLOW_INTERNAL_API. > > I prefer a build error complaining on an unknown attribute rather than > > silence a check. > > > > I.e. > > > > #ifndef ALLOW_INTERNAL_API > > > > #if __has_attribute(diagnose_if) /* For clang */ > > #define __rte_internal \ > > __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \ > > section(".text.internal"))) > > > > #else > > #define __rte_internal \ > > __attribute__((error("Symbol is not public ABI"), \ > > section(".text.internal"))) > > > > #endif > > > > #else /* ALLOW_INTERNAL_API */ > > > > #define __rte_internal \ > > section(".text.internal"))) > > > > #endif > > > > Would this not mean that if someone was using a compiler that supported > neither that they could never include any header file which contained any > internal functions? I'd rather err on the side of allowing this, on the > basis that the symbol should be already documented as internal and this i= s > only an additional sanity check. - Still not a fan. We will never know about those compilers behavior, like how we caught the clang issue and found an alternative. - I just caught a build error with RHEL7 gcc: [1/2127] Compiling C object lib/librte_eal.a.p/librte_eal_common_eal_common_config.c.o FAILED: lib/librte_eal.a.p/librte_eal_common_eal_common_config.c.o ccache cc -Ilib/librte_eal.a.p -Ilib -I../lib -I. -I.. -Iconfig -I../config -Ilib/librte_eal/include -I../lib/librte_eal/include -Ilib/librte_eal/linux/include -I../lib/librte_eal/linux/include -Ilib/librte_eal/x86/include -I../lib/librte_eal/x86/include -Ilib/librte_eal/common -I../lib/librte_eal/common -Ilib/librte_eal -I../lib/librte_eal -Ilib/librte_kvargs -I../lib/librte_kvargs -Ilib/librte_metrics -I../lib/librte_metrics -Ilib/librte_telemetry -I../lib/librte_telemetry -pipe -D_FILE_OFFSET_BITS=3D64 -Wall -Winvalid-pch -O3 -include rte_config.h -Wextra -Wcast-qual -Wdeprecated -Wformat -Wformat-nonliteral -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wpointer-arith -Wsign-compare -Wstrict-prototypes -Wundef -Wwrite-strings -Wno-missing-field-initializers -D_GNU_SOURCE -fPIC -march=3Dnative -DALLOW_EXPERIMENTAL_API -DALLOW_INTERNAL_API '-DABI_VERSION=3D"21.1"' -MD -MQ lib/librte_eal.a.p/librte_eal_common_eal_common_config.c.o -MF lib/librte_eal.a.p/librte_eal_common_eal_common_config.c.o.d -o lib/librte_eal.a.p/librte_eal_common_eal_common_config.c.o -c ../lib/librte_eal/common/eal_common_config.c In file included from ../lib/librte_eal/include/rte_dev.h:24:0, from ../lib/librte_eal/common/eal_private.h:12, from ../lib/librte_eal/common/eal_common_config.c:9: ../lib/librte_eal/include/rte_compat.h:22:51: error: missing binary operator before token "(" #if !defined ALLOW_INTERNAL_API && __has_attribute(error) /* For GCC */ ^ ../lib/librte_eal/include/rte_compat.h:28:53: error: missing binary operator before token "(" #elif !defined ALLOW_INTERNAL_API && __has_attribute(diagnose_if) /* For clang */ ^ I can see that gcc doc recommends checking for __has_attribute availability= . Pasting from google cache, since the gcc.gnu.org doc website seems unavaila= ble. """ 4.2.6 __has_attribute The special operator __has_attribute (operand) may be used in =E2=80=98#if= =E2=80=99 and =E2=80=98#elif=E2=80=99 expressions to test whether the attribute refer= enced by its operand is recognized by GCC. Using the operator in other contexts is not valid. In C code, if compiling for strict conformance to standards before C2x, operand must be a valid identifier. Otherwise, operand may be optionally introduced by the attribute-scope:: prefix. The attribute-scope prefix identifies the =E2=80=9Cnamespace=E2=80=9D withi= n which the attribute is recognized. The scope of GCC attributes is =E2=80=98gnu=E2=80= =99 or =E2=80=98__gnu__=E2=80=99. The __has_attribute operator by itself, without = any operand or parentheses, acts as a predefined macro so that support for it can be tested in portable code. Thus, the recommended use of the operator is as follows: #if defined __has_attribute # if __has_attribute (nonnull) # define ATTR_NONNULL __attribute__ ((nonnull)) # endif #endif The first =E2=80=98#if=E2=80=99 test succeeds only when the operator is sup= ported by the version of GCC (or another compiler) being used. Only when that test succeeds is it valid to use __has_attribute as a preprocessor operator. As a result, combining the two tests into a single expression as shown below would only be valid with a compiler that supports the operator but not with others that don=E2=80=99t. #if defined __has_attribute && __has_attribute (nonnull) /* not portable = */ =E2=80=A6 #endif """ --=20 David Marchand