Skip to contentSkip to conversation

eal: enforce internal API check with Clang

PATCH In review Thomas Monjalon 3 participants 10 messages Oct 14 – Oct 20 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

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.

Fixes 4ab63cd60ceb ("eal: fix internal ABI tag with clang")
---
 lib/eal/include/rte_compat.h | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
lib/eal/include/rte_compat.h +11 -11
index 97c1540bd0..b62e49d676 100644
@@ -32,17 +32,7 @@ __attribute__((section(".text.experimental")))
 #define __has_attribute(x) 0
 #endif
 
-#if !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
-
-#elif !defined ALLOW_INTERNAL_API && __has_attribute(diagnose_if) /* For clang */
+#if !defined ALLOW_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
Acked-by on v1 1/1
#1 lore raw
Quoted 13 lines · Thomas Monjalon

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.

Quoted 8 lines

Prefer diagnose_if when available to keep strong Clang diagnostics. Retain the error attribute as a fallback for GCC.

Fixes 4ab63cd60ceb ("eal: fix internal ABI tag with clang")

---

Signature · 2 lines
Thanks,
Anatoly
#2 lore raw
In reply to Thomas Monjalon
Quoted 14 lines · Thomas Monjalon

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.

Quoted 7 lines

Prefer diagnose_if when available to keep strong Clang diagnostics. Retain the error attribute as a fallback for GCC.

Fixes 4ab63cd60ceb ("eal: fix internal ABI tag with clang")

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
#3 lore raw

PATCH v2 1/3 buildtools/chkincs: relax checks on driver headers

In reply to Thomas Monjalon

Driver 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
index 9a84c1cc25..df674f74ee 100644
@@ -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
#4 lore raw

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
index 97c1540bd0..cb7836a190 100644
@@ -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 !defined ALLOW_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 !defined ALLOW_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
#5 lore raw

PATCH v2 3/3 eal: enforce internal API check with Clang 14

In reply to David Marchand

From: 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.

Fixes 4ab63cd60ceb ("eal: fix internal ABI tag with clang")
---
 lib/eal/include/rte_compat.h | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
lib/eal/include/rte_compat.h +7 -7
index cb7836a190..89c3465245 100644
@@ -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
Acked-by on v2 3/3
#6 lore raw

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_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.

Quoted 8 lines

Prefer diagnose_if when available to keep strong Clang diagnostics. Retain the error attribute as a fallback for GCC.

Fixes 4ab63cd60ceb ("eal: fix internal ABI tag with clang")

---

Missing my ack

Signature · 2 lines
Thanks,
Anatoly
#7 lore raw

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_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.

Fixes 4ab63cd60ceb ("eal: fix internal ABI tag with clang")
Quoted 6 lines
Quoted 2 lines

---

Missing my ack

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
#8 lore raw

Re: [PATCH v2 3/3] eal: enforce internal API check with Clang 14

In reply to David Marchand
Quoted 16 lines · David Marchand

From: 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.

Quoted 7 lines

Prefer diagnose_if when available to keep strong Clang diagnostics. Retain the error attribute as a fallback for GCC.

Fixes 4ab63cd60ceb ("eal: fix internal ABI tag with clang")

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
#9 lore raw

Re: [PATCH v2 3/3] eal: enforce internal API check with Clang 14

In reply to David Marchand
Quoted 16 lines · David Marchand

From: 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.

Quoted 8 lines

Prefer diagnose_if when available to keep strong Clang diagnostics. Retain the error attribute as a fallback for GCC.

Fixes 4ab63cd60ceb ("eal: fix internal ABI tag with clang")

Series applied, thanks.

Signature · 1 line
David Marchand