Skip to contentSkip to conversation

bpf: handle implicit declaration of function gettid in bpf_iter.c

PATCH Superseded Jason Xing 2 participants 3 messages Oct 28, 2024 – Oct 29, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jason Xing

author
#0 lore raw

PATCH 1/1 bpf: handle implicit declaration of function gettid in bpf_iter.c

From: Jason Xing <[email protected]>

As we can see from the title, when I compiled the selftests/bpf, I
saw the error:
implicit declaration of function ‘gettid’ ; did you mean ‘getgid’? [-Werror=implicit-function-declaration]

  skel->bss->tid = gettid();
                   ^~~~~~
                   getgid

Adding a define to fix it (referring to tools/perf/tests/shell/coresight/thread_loop/thread_loop.c file.

---
 tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +2 -0
index f0a3a9c18e9e..a105759f3dcf 100644
@@ -34,6 +34,8 @@
 #include "bpf_iter_ksym.skel.h"
 #include "bpf_iter_sockmap.skel.h"
 
+#define gettid() syscall(SYS_gettid)
+
 static void test_btf_id_or_null(void)
 {
 	struct bpf_iter_test_kern3 *skel;
Signature · 1 line
2.37.3
#1 lore raw
Quoted 23 lines · Jason Xing

From: Jason Xing <[email protected]>

As we can see from the title, when I compiled the selftests/bpf, I
saw the error:
implicit declaration of function ‘gettid’ ; did you mean ‘getgid’? [-Werror=implicit-function-declaration]

  skel->bss->tid = gettid();
                   ^~~~~~
                   getgid

Adding a define to fix it (referring to tools/perf/tests/shell/coresight/thread_loop/thread_loop.c file.

---
 tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +0 -0
index f0a3a9c18e9e..a105759f3dcf 100644

tools/testing/selftests/bpf/prog_tests/bpf_iter.c line 38

Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +2 -0
@@ -34,6 +34,8 @@
 #include "bpf_iter_ksym.skel.h"
 #include "bpf_iter_sockmap.skel.h"
 
+#define gettid() syscall(SYS_gettid)
+

We just call syscall(SYS_gettid) directly in all other tests, so let's do just that?

pw-bot: cr

Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +0 -1
 static void test_btf_id_or_null(void)
 {
        struct bpf_iter_test_kern3 *skel;
--

2.37.3

author
#2 lore raw
Quoted 28 lines · Andrii Nakryiko
Quoted 26 lines · Jason Xing

From: Jason Xing <[email protected]>

As we can see from the title, when I compiled the selftests/bpf, I
saw the error:
implicit declaration of function ‘gettid’ ; did you mean ‘getgid’? [-Werror=implicit-function-declaration]

  skel->bss->tid = gettid();
                   ^~~~~~
                   getgid

Adding a define to fix it (referring to tools/perf/tests/shell/coresight/thread_loop/thread_loop.c file.

---
 tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +0 -0
index f0a3a9c18e9e..a105759f3dcf 100644
@@ -34,6 +34,8 @@
 #include "bpf_iter_ksym.skel.h"
 #include "bpf_iter_sockmap.skel.h"
 
Quoted 5 lines

tools/testing/selftests/bpf/prog_tests/bpf_iter.c line 38

Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/bpf_iter.c +2 -0
+#define gettid() syscall(SYS_gettid)
+

We just call syscall(SYS_gettid) directly in all other tests, so let's do just that?

I got it and will adjust the bpf_iter.c in the next version.

Thanks,
Jason