Skip to contentSkip to conversation

bpf_helpers.h: define bpf_tail_call_static when building with GCC

PATCH Superseded Jose E. Marchesi 3 participants 4 messages Jan 23, 2024 – Jan 24, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf_helpers.h: define bpf_tail_call_static when building with GCC

The definition of bpf_tail_call_static in tools/lib/bpf/bpf_helpers.h is guarded by a preprocessor check to assure that clang is recent enough to support it. This patch updates the guard so the function is compiled when using GCC as well.

Tested in bpf-next master.
No regressions.

---
 tools/lib/bpf/bpf_helpers.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/bpf_helpers.h +1 -1
index 2324cc42b017..3306f50c5081 100644
@@ -136,7 +136,7 @@
 /*
  * Helper function to perform a tail call with a constant/immediate map slot.
  */
-#if __clang_major__ >= 8 && defined(__bpf__)
+#if (!defined(__clang__) || __clang_major__ >= 8) && defined(__bpf__)
 static __always_inline void
 bpf_tail_call_static(void *ctx, const void *map, const __u32 slot)
 {
Signature · 1 line
2.30.2
reviewer
#1 lore raw
Quoted 22 lines · Jose E. Marchesi

The definition of bpf_tail_call_static in tools/lib/bpf/bpf_helpers.h is guarded by a preprocessor check to assure that clang is recent enough to support it. This patch updates the guard so the function is compiled when using GCC as well.

Tested in bpf-next master.
No regressions.

---
  tools/lib/bpf/bpf_helpers.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/bpf_helpers.h +0 -0
index 2324cc42b017..3306f50c5081 100644

tools/lib/bpf/bpf_helpers.h line 139

Quoted 5 lines
tools/lib/bpf/bpf_helpers.h +1 -1
@@ -136,7 +136,7 @@
  /*
   * Helper function to perform a tail call with a constant/immediate map slot.
   */
-#if __clang_major__ >= 8 && defined(__bpf__)
+#if (!defined(__clang__) || __clang_major__ >= 8) && defined(__bpf__)

Do you want to guard with a gcc version as well here or you assume any gcc which supports bpf should be okay here?

Quoted 3 lines
tools/lib/bpf/bpf_helpers.h +0 -0
  static __always_inline void
  bpf_tail_call_static(void *ctx, const void *map, const __u32 slot)
  {
#2 lore raw
Quoted 19 lines · Jose E. Marchesi
Quoted 17 lines

The definition of bpf_tail_call_static in tools/lib/bpf/bpf_helpers.h is guarded by a preprocessor check to assure that clang is recent enough to support it. This patch updates the guard so the function is compiled when using GCC as well.

Tested in bpf-next master.
No regressions.

---
  tools/lib/bpf/bpf_helpers.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

tools/lib/bpf/bpf_helpers.h line 139

Quoted 10 lines
tools/lib/bpf/bpf_helpers.h +1 -1
index 2324cc42b017..3306f50c5081 100644
@@ -136,7 +136,7 @@
  /*
   * Helper function to perform a tail call with a constant/immediate map slot.
   */
-#if __clang_major__ >= 8 && defined(__bpf__)
+#if (!defined(__clang__) || __clang_major__ >= 8) && defined(__bpf__)

Do you want to guard with a gcc version as well here or you assume any gcc which supports bpf should be okay here?

The second, because GCC versions that do not support bpf_tail_call_static are not capable of building the selftests for many other reasons, so there is little point to support them.

Quoted 4 lines
Quoted 4 lines
tools/lib/bpf/bpf_helpers.h +0 -0
  static __always_inline void
  bpf_tail_call_static(void *ctx, const void *map, const __u32 slot)
  {
#3 lore raw
Quoted 34 lines · Jose E. Marchesi
Quoted 20 lines · Jose E. Marchesi
Quoted 17 lines

The definition of bpf_tail_call_static in tools/lib/bpf/bpf_helpers.h is guarded by a preprocessor check to assure that clang is recent enough to support it. This patch updates the guard so the function is compiled when using GCC as well.

Tested in bpf-next master.
No regressions.

---
  tools/lib/bpf/bpf_helpers.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

tools/lib/bpf/bpf_helpers.h line 139

Quoted 10 lines
tools/lib/bpf/bpf_helpers.h +1 -1
index 2324cc42b017..3306f50c5081 100644
@@ -136,7 +136,7 @@
  /*
   * Helper function to perform a tail call with a constant/immediate map slot.
   */
-#if __clang_major__ >= 8 && defined(__bpf__)
+#if (!defined(__clang__) || __clang_major__ >= 8) && defined(__bpf__)

Do you want to guard with a gcc version as well here or you assume any gcc which supports bpf should be okay here?

Quoted 3 lines

The second, because GCC versions that do not support bpf_tail_call_static are not capable of building the selftests for many other reasons, so there is little point to support them.

bpf_helpers.h is part of libbpf-provided API, and so it's going to be used way beyond just BPF selftests. So I think it's prudent to guard with version check just like we do it for clang. I assume you do know GCC version that is meant to support this?

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
tools/lib/bpf/bpf_helpers.h +0 -0
  static __always_inline void
  bpf_tail_call_static(void *ctx, const void *map, const __u32 slot)
  {