eal: enforce internal API check with Clang
PATCH 1/1 eal: enforce internal API check with Clang
The __rte_internal macro is intended to prevent calls to internal API functions unless ALLOW_INTERNAL_API is defined. Unfortunately the check misses some calls to internal API when built with GCC or Clang.
Clang can be better to diagnose such cases.
Clang 14 and later support the error attribute
and therefore select it instead of diagnose_if for __rte_internal. Unlike diagnose_if, the error attribute only rejects internal API calls that remain after optimization. Internal API calls can therefore go easily unnoticed, making internal API checks less strict with recent Clang.
Prefer diagnose_if when available to keep strong Clang diagnostics. Retain the error attribute as a fallback for GCC.
--- lib/eal/include/rte_compat.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
lib/eal/include/rte_compat.h +11 -11
@@ -32,17 +32,7 @@ __attribute__((section(".text.experimental")))#define __has_attribute (x) 0#endif -#if !definedALLOW_INTERNAL_API &&__has_attribute (error)/* For GCC */ - -#ifdef RTE_TOOLCHAIN_MSVC -#define __rte_internal -#else -#define __rte_internal \ -__attribute__((error("Symbol is not public ABI"), \ -section(".text.internal"))) -#endif - -#elif !definedALLOW_INTERNAL_API &&__has_attribute (diagnose_if)/* For clang */ +#if !definedALLOW_INTERNAL_API &&__has_attribute (diagnose_if)/* For Clang */ #ifdef RTE_TOOLCHAIN_MSVC #define __rte_internal
@@ -55,6 +45,16 @@ section(".text.internal"))) \ _Pragma("GCC diagnostic pop")#endif +#elif !defined ALLOW_INTERNAL_API && __has_attribute(error)/* For GCC */ + +#ifdef RTE_TOOLCHAIN_MSVC +#define __rte_internal +#else +#define __rte_internal \ +__attribute__((error("Symbol is not public ABI"), \ +section(".text.internal"))) +#endif +#else #ifdef RTE_TOOLCHAIN_MSVC
Signature · 1 line
2.55.0
Quoted 13 lines · Thomas Monjalon
The
__rte_internalmacro is intended to prevent calls to internal API functions unlessALLOW_INTERNAL_APIis defined. Unfortunately the check misses some calls to internal API when built with GCC or Clang.
Clang can be better to diagnose such cases.Clang 14 and later support the error attribute
and therefore select it instead ofdiagnose_iffor__rte_internal. Unlikediagnose_if, the error attribute only rejects internal API calls that remain after optimization. Internal API calls can therefore go easily unnoticed, making internal API checks less strict with recent Clang.
Quoted 8 lines
Prefer
diagnose_ifwhen available to keep strong Clang diagnostics. Retain the error attribute as a fallback for GCC.Fixes 4ab63cd60ceb ("eal: fix internal ABI tag with clang")Signed-off-by Thomas Monjalon <[email protected]>---
Signature · 2 lines
Thanks, Anatoly
Quoted 14 lines · Thomas Monjalon
The
__rte_internalmacro is intended to prevent calls to internal API functions unlessALLOW_INTERNAL_APIis defined. Unfortunately the check misses some calls to internal API when built with GCC or Clang.
Clang can be better to diagnose such cases.Clang 14 and later support the error attribute
and therefore select it instead ofdiagnose_iffor__rte_internal. Unlikediagnose_if, the error attribute only rejects internal API calls that remain after optimization. Internal API calls can therefore go easily unnoticed, making internal API checks less strict with recent Clang.
Quoted 7 lines
Prefer
diagnose_ifwhen available to keep strong Clang diagnostics. Retain the error attribute as a fallback for GCC.Fixes 4ab63cd60ceb ("eal: fix internal ABI tag with clang")Signed-off-by Thomas Monjalon <[email protected]>
What a mess this header has become :-).
I have a little cleanup to propose, and this patch actually does not pass the chkinc test with recent clang now, as it raises warnings that were not seen so far.
I'll post a v2, as we discussed offlist.
Signature · 1 line
David Marchand
PATCH v2 1/3 buildtools/chkincs: relax checks on driver headers
In reply to Thomas MonjalonDriver headers are common consumers of internal APIs, like for example the ethdev_pci.h header consumed by net PCI drivers, which calls internal symbols for allocating/releasing a ethdev port.
Checking that a driver header compiles without allowing internal APIs is then highly likely to fail.
Relax the check and stop expecting driver headers could compile without ALLOW_INTERNAL_API.
--- buildtools/chkincs/meson.build | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-)
buildtools/chkincs/meson.build +5 -17
@@ -49,19 +49,13 @@ sources_drivers = files('main.c') sources_drivers += gen_c_files.process(dpdk_drivers_headers) executable('chkincs-drv', sources_drivers, - c_args: cflags, - include_directories: includes + includes_drivers, - dependencies: deps + deps_drivers, - install: false) - -executable('chkincs-drv-exp', sources_drivers, - c_args: [cflags, '-DALLOW_EXPERIMENTAL_API'], + c_args: [cflags, '-DALLOW_INTERNAL_API'], include_directories: includes + includes_drivers, dependencies: deps + deps_drivers, install: false) executable('chkincs-drv-all', sources_drivers, - c_args: [cflags, '-DALLOW_EXPERIMENTAL_API', '-DALLOW_INTERNAL_API'], + c_args: [cflags, '-DALLOW_INTERNAL_API', '-DALLOW_EXPERIMENTAL_API'], include_directories: includes + includes_drivers, dependencies: deps + deps_drivers, install: false)
@@ -101,20 +95,14 @@ cpp_sources_drivers = files('main.cpp') cpp_sources_drivers += gen_cpp_files.process(dpdk_drivers_headers) executable('chkincs-drv-cpp', cpp_sources_drivers, - cpp_args: ['-include', 'rte_config.h', cflags], - include_directories: includes + includes_drivers, - dependencies: deps + deps_drivers, - install: false) - -executable('chkincs-drv-cpp-exp', cpp_sources_drivers, - cpp_args: ['-include', 'rte_config.h', cflags, '-DALLOW_EXPERIMENTAL_API'], + cpp_args: ['-include', 'rte_config.h', cflags, '-DALLOW_INTERNAL_API'], include_directories: includes + includes_drivers, dependencies: deps + deps_drivers, install: false) executable('chkincs-drv-cpp-all', cpp_sources_drivers, - cpp_args: ['-include', 'rte_config.h', cflags, '-DALLOW_EXPERIMENTAL_API', - '-DALLOW_INTERNAL_API'], + cpp_args: ['-include', 'rte_config.h', cflags, '-DALLOW_INTERNAL_API', + '-DALLOW_EXPERIMENTAL_API'], include_directories: includes + includes_drivers, dependencies: deps + deps_drivers, install: false)
Signature · 1 line
2.54.0
PATCH v2 2/3 eal: simplify internal/experimental tags definitions
The tags definitions have become hard to read after adding support for various compilers.
Let's reorder the definitions:
- put MSVC first, as it offers neither the section attribute nor helps with detecting wrong use of symbols,
- then for each tag
- start with error/diagnostic tweaks for the respective !ALLOW cases,
- if no tweak is available, and for the ALLOW cases, fallback to moving the symbol to a section,
--- lib/eal/include/rte_compat.h | 39 +++++++++++++++--------------------- 1 file changed, 16 insertions(+), 23 deletions(-)
lib/eal/include/rte_compat.h +16 -23
@@ -6,64 +6,57 @@#ifndef _RTE_COMPAT_H_#define _RTE_COMPAT_H_ -#ifndef ALLOW_EXPERIMENTAL_API -#ifdef RTE_TOOLCHAIN_MSVC +#define __rte_experimental -#else +#define __rte_internal + +#else /* !RTE_TOOLCHAIN_MSVC */ + +#ifndef ALLOW_EXPERIMENTAL_API +#define __rte_experimental \ __attribute__((deprecated("Symbol is not yet part of stable ABI"), \ section(".text.experimental"))) -#endif -#else +#endif /* !ALLOW_EXPERIMENTAL_API */ -#ifdef RTE_TOOLCHAIN_MSVC -#define __rte_experimental -#else +#ifndef __rte_experimental#define __rte_experimental \ __attribute__((section(".text.experimental")))#endif -#endif +#ifndef ALLOW_INTERNAL_API #ifndef __has_attribute/* if no has_attribute assume no support for attribute too */ #define __has_attribute (x) 0#endif -#if !definedALLOW_INTERNAL_API &&__has_attribute (error)/* For GCC */ +#if __has_attribute (error)/* For GCC */ -#ifdef RTE_TOOLCHAIN_MSVC -#define __rte_internal -#else #define __rte_internal \ __attribute__((error("Symbol is not public ABI"), \ section(".text.internal"))) -#endif -#elif !definedALLOW_INTERNAL_API &&__has_attribute (diagnose_if)/* For clang */ +#elif __has_attribute (diagnose_if)/* For clang */ -#ifdef RTE_TOOLCHAIN_MSVC -#define __rte_internal -#else #define __rte_internal \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wgcc-compat\"") \ __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \ section(".text.internal"))) \ _Pragma("GCC diagnostic pop") +#endif -#else +#endif /* !ALLOW_INTERNAL_API */ -#ifdef RTE_TOOLCHAIN_MSVC -#define __rte_internal -#else +#ifndef __rte_internal#define __rte_internal \ __attribute__((section(".text.internal")))#endif -#endif +#endif /* !RTE_TOOLCHAIN_MSVC */ #endif /* _RTE_COMPAT_H_ */
Signature · 1 line
2.54.0
PATCH v2 3/3 eal: enforce internal API check with Clang 14
In reply to David MarchandFrom: Thomas Monjalon <[email protected]>
The __rte_internal macro is intended to prevent calls to internal API functions unless ALLOW_INTERNAL_API is defined. Unfortunately the check misses some calls to internal API when built with GCC or Clang.
Clang can be better to diagnose such cases.
Clang 14 and later support the error attribute
and therefore select it instead of diagnose_if for __rte_internal. Unlike diagnose_if, the error attribute only rejects internal API calls that remain after optimization. Internal API calls can therefore go easily unnoticed, making internal API checks less strict with recent Clang.
Prefer diagnose_if when available to keep strong Clang diagnostics. Retain the error attribute as a fallback for GCC.
--- lib/eal/include/rte_compat.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
lib/eal/include/rte_compat.h +7 -7
@@ -33,13 +33,7 @@ __attribute__((section(".text.experimental")))#define __has_attribute (x) 0#endif -#if __has_attribute (error)/* For GCC */ - -#define __rte_internal \ -__attribute__((error("Symbol is not public ABI"), \ -section(".text.internal"))) - -#elif __has_attribute (diagnose_if)/* For clang */ +#if __has_attribute (diagnose_if)/* For Clang */ #define __rte_internal \ _Pragma("GCC diagnostic push") \
@@ -48,6 +42,12 @@ __attribute__((diagnose_if(1, "Symbol is not public ABI", "error"), \ section(".text.internal"))) \ _Pragma("GCC diagnostic pop") +#elif __has_attribute (error)/* For GCC */ + +#define __rte_internal \ +__attribute__((error("Symbol is not public ABI"), \ +section(".text.internal"))) +#endif #endif /* !ALLOW_INTERNAL_API */
Signature · 1 line
2.54.0
Re: [PATCH v2 3/3] eal: enforce internal API check with Clang 14
Quoted 15 lines · David Marchand
From: Thomas Monjalon <[email protected]>
The
__rte_internalmacro is intended to prevent calls to internal API functions unlessALLOW_INTERNAL_APIis defined. Unfortunately the check misses some calls to internal API when built with GCC or Clang.
Clang can be better to diagnose such cases.Clang 14 and later support the error attribute
and therefore select it instead ofdiagnose_iffor__rte_internal. Unlikediagnose_if, the error attribute only rejects internal API calls that remain after optimization. Internal API calls can therefore go easily unnoticed, making internal API checks less strict with recent Clang.
Quoted 8 lines
Prefer
diagnose_ifwhen available to keep strong Clang diagnostics. Retain the error attribute as a fallback for GCC.Fixes 4ab63cd60ceb ("eal: fix internal ABI tag with clang")Signed-off-by Thomas Monjalon <[email protected]>---
Missing my ack
Signature · 2 lines
Thanks, Anatoly
Re: [PATCH v2 3/3] eal: enforce internal API check with Clang 14
Quoted 23 lines · Anatoly
Quoted 21 lines · David Marchand
From: Thomas Monjalon <[email protected]>
The
__rte_internalmacro is intended to prevent calls to internal API functions unlessALLOW_INTERNAL_APIis defined. Unfortunately the check misses some calls to internal API when built with GCC or Clang.
Clang can be better to diagnose such cases.Clang 14 and later support the error attribute
and therefore select it instead ofdiagnose_iffor__rte_internal. Unlikediagnose_if, the error attribute only rejects internal API calls that remain after optimization. Internal API calls can therefore go easily unnoticed, making internal API checks less strict with recent Clang.Prefer
diagnose_ifwhen available to keep strong Clang diagnostics. Retain the error attribute as a fallback for GCC.Fixes 4ab63cd60ceb ("eal: fix internal ABI tag with clang")
Quoted 6 lines
Quoted 2 lines
Signed-off-by Thomas Monjalon <[email protected]>---
Missing my ack
Acked-by Anatoly Burakov <[email protected]>
I changed the original patch a bit, and well, I had trouble with all those nested #ifdef ;-), so I preferred not preserving the ack. Thanks for checking again.
Signature · 1 line
David Marchand
Re: [PATCH v2 3/3] eal: enforce internal API check with Clang 14
In reply to David MarchandQuoted 16 lines · David Marchand
From: Thomas Monjalon <[email protected]>
The
__rte_internalmacro is intended to prevent calls to internal API functions unlessALLOW_INTERNAL_APIis defined. Unfortunately the check misses some calls to internal API when built with GCC or Clang.
Clang can be better to diagnose such cases.Clang 14 and later support the error attribute
and therefore select it instead ofdiagnose_iffor__rte_internal. Unlikediagnose_if, the error attribute only rejects internal API calls that remain after optimization. Internal API calls can therefore go easily unnoticed, making internal API checks less strict with recent Clang.
Quoted 7 lines
Prefer
diagnose_ifwhen available to keep strong Clang diagnostics. Retain the error attribute as a fallback for GCC.Fixes 4ab63cd60ceb ("eal: fix internal ABI tag with clang")Signed-off-by Thomas Monjalon <[email protected]>
Just a note about CI.
It seems we have some trouble with the ovsrobot but this series passes GHA in my repo:
https://github.com/david-marchand/dpdk/actions/runs/38725255308
Signature · 1 line
David Marchand
Re: [PATCH v2 3/3] eal: enforce internal API check with Clang 14
In reply to David MarchandQuoted 16 lines · David Marchand
From: Thomas Monjalon <[email protected]>
The
__rte_internalmacro is intended to prevent calls to internal API functions unlessALLOW_INTERNAL_APIis defined. Unfortunately the check misses some calls to internal API when built with GCC or Clang.
Clang can be better to diagnose such cases.Clang 14 and later support the error attribute
and therefore select it instead ofdiagnose_iffor__rte_internal. Unlikediagnose_if, the error attribute only rejects internal API calls that remain after optimization. Internal API calls can therefore go easily unnoticed, making internal API checks less strict with recent Clang.
Quoted 8 lines
Prefer
diagnose_ifwhen available to keep strong Clang diagnostics. Retain the error attribute as a fallback for GCC.Fixes 4ab63cd60ceb ("eal: fix internal ABI tag with clang")Signed-off-by Thomas Monjalon <[email protected]>Acked-by Anatoly Burakov <[email protected]>
Series applied, thanks.
Signature · 1 line
David Marchand