Skip to contentSkip to conversation

Fix 'libbpf: failed to find BTF info for global/extern symbol' since uninitialized global variables

PATCH In review LiuLingze 2 participants 6 messages Oct 13, 2023 – Oct 17, 2023 BPF

lore
Share & tools
lore

LiuLingze

author
#0 lore raw

PATCH 1/1 Fix 'libbpf: failed to find BTF info for global/extern symbol' since uninitialized global variables

---
 examples/c/usdt.bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/c/usdt.bpf.c +1 -1
index 49ba506..2612ec1 100644
@@ -5,7 +5,7 @@
 #include <bpf/bpf_tracing.h>
 #include <bpf/usdt.bpf.h>
 
-pid_t my_pid;
+pid_t my_pid = 0;
 
 SEC("usdt/libc.so.6:libc:setjmp")
 int BPF_USDT(usdt_auto_attach, void *arg1, int arg2, void *arg3)
Signature · 1 line
2.37.2
#1 lore raw
Quoted 10 lines · LiuLingze
---
 examples/c/usdt.bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/c/usdt.bpf.c +0 -0
index 49ba506..2612ec1 100644

examples/c/usdt.bpf.c line 8

Quoted 5 lines
examples/c/usdt.bpf.c +1 -1
@@ -5,7 +5,7 @@
 #include <bpf/bpf_tracing.h>
 #include <bpf/usdt.bpf.h>
 
-pid_t my_pid;
+pid_t my_pid = 0;

This is effectively the same, my_pid will be initialized to zero anyways. The difference might be due to you using too old Clang version that might still be putting my_pid into a special COM section.

Also "failed to find BTF info for global/extern symbol" is usually due to too old Clang that doesn't emit BTF information for global variables.

So either way, can you try upgrading your Clang and see if the problem persists?

Quoted 7 lines
examples/c/usdt.bpf.c +0 -1
 SEC("usdt/libc.so.6:libc:setjmp")
 int BPF_USDT(usdt_auto_attach, void *arg1, int arg2, void *arg3)
--

2.37.2

author
#2 lore raw

Hi Andrii Nakryiko,

Quoted 22 lines
Quoted 10 lines · On Fri, Oct 13, 2023 at 6:45=E2=80=AFAM LiuLingze <[email protected]> =…
---
 examples/c/usdt.bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/c/usdt.bpf.c +0 -0
index 49ba506..2612ec1 100644

examples/c/usdt.bpf.c line 8

Quoted 5 lines
examples/c/usdt.bpf.c +1 -1
@@ -5,7 +5,7 @@
 #include <bpf/bpf_tracing.h>
 #include <bpf/usdt.bpf.h>
 
-pid_t my_pid;
+pid_t my_pid =3D 0;

This is effectively the same, my_pid will be initialized to zero anyways. The difference might be due to you using too old Clang version that might still be putting my_pid into a special COM section.

Quoted 15 lines

Also "failed to find BTF info for global/extern symbol" is usually due to too old Clang that doesn't emit BTF information for global variables.

So either way, can you try upgrading your Clang and see if the problem pers= ists?

Quoted 7 lines
examples/c/usdt.bpf.c +0 -1
 SEC("usdt/libc.so.6:libc:setjmp")
 int BPF_USDT(usdt_auto_attach, void *arg1, int arg2, void *arg3)
--

2.37.2

Thank you for your reply.

Yes, I was able to compile on a newer ubuntu with a higher version of clang.

However, on a development module (nVidia Orin AGX) running an older version of ubuntu, it is not possible to use apt to update clang to a new version. Downloading the source code of a higher version of clang for compilation is cumbersome and affects compatibility. So I hope that with the above changes, the project code can be easily compiled and used in earlier versions.

Thanks,
LiuLingze

#3 lore raw
Quoted 41 lines · LiuLingze

Hi Andrii Nakryiko,

Quoted 22 lines
Quoted 10 lines · On Fri, Oct 13, 2023 at 6:45=E2=80=AFAM LiuLingze <[email protected]> =…
---
 examples/c/usdt.bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/c/usdt.bpf.c +0 -0
index 49ba506..2612ec1 100644

examples/c/usdt.bpf.c line 8

Quoted 5 lines
examples/c/usdt.bpf.c +1 -1
@@ -5,7 +5,7 @@
 #include <bpf/bpf_tracing.h>
 #include <bpf/usdt.bpf.h>
 
-pid_t my_pid;
+pid_t my_pid =3D 0;

This is effectively the same, my_pid will be initialized to zero anyways. The difference might be due to you using too old Clang version that might still be putting my_pid into a special COM section.

Quoted 15 lines

Also "failed to find BTF info for global/extern symbol" is usually due to too old Clang that doesn't emit BTF information for global variables.

So either way, can you try upgrading your Clang and see if the problem pers= ists?

Quoted 7 lines
examples/c/usdt.bpf.c +0 -1
 SEC("usdt/libc.so.6:libc:setjmp")
 int BPF_USDT(usdt_auto_attach, void *arg1, int arg2, void *arg3)
--

2.37.2

Quoted 5 lines

Thank you for your reply.

Yes, I was able to compile on a newer ubuntu with a higher version of clang.

However, on a development module (nVidia Orin AGX) running an older version of ubuntu, it is not possible to use apt to update clang to a new version. Downloading the source code of a higher version of clang for compilation is cumbersome and affects compatibility. So I hope that with the above changes, the project code can be easily compiled and used in earlier versions.

Did you verify that specifically adding explicit = 0 makes it more compatible with old compiler or it's just a theory?

Quoted 4 lines

Thanks,
LiuLingze

author
#4 lore raw
Quoted 41 lines · Andrii Nakryiko
Quoted 40 lines · LiuLingze

Hi Andrii Nakryiko,

Quoted 36 lines · LiuLingze
Quoted 10 lines
---
 examples/c/usdt.bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/c/usdt.bpf.c +0 -0
index 49ba506..2612ec1 100644

examples/c/usdt.bpf.c line 8

Quoted 5 lines
examples/c/usdt.bpf.c +1 -1
@@ -5,7 +5,7 @@
 #include <bpf/bpf_tracing.h>
 #include <bpf/usdt.bpf.h>
 
-pid_t my_pid;
+pid_t my_pid =3D 0;

This is effectively the same, my_pid will be initialized to zero anyways. The difference might be due to you using too old Clang version that might still be putting my_pid into a special COM section.

Also "failed to find BTF info for global/extern symbol" is usually due to too old Clang that doesn't emit BTF information for global variables.

So either way, can you try upgrading your Clang and see if the problem pers= ists?

Quoted 7 lines
examples/c/usdt.bpf.c +0 -1
 SEC("usdt/libc.so.6:libc:setjmp")
 int BPF_USDT(usdt_auto_attach, void *arg1, int arg2, void *arg3)
--

2.37.2

Quoted 8 lines
Quoted 5 lines

Thank you for your reply.

Yes, I was able to compile on a newer ubuntu with a higher version of clang.

However, on a development module (nVidia Orin AGX) running an older version of ubuntu, it is not possible to use apt to update clang to a new version. Downloading the source code of a higher version of clang for compilation is cumbersome and affects compatibility. So I hope that with the above changes, the project code can be easily compiled and used in earlier versions.

Did you verify that specifically adding explicit = 0 makes it more compatible with old compiler or it's just a theory?

Yes, I have compiled usdt successfully on Ubuntu 20.04.6 LTS with clang version 10.0.0-4ubuntu1 by specifically adding explicit = 0.

#5 lore raw
Quoted 46 lines · LiuLingze
Quoted 43 lines · Andrii Nakryiko
Quoted 42 lines · LiuLingze

Hi Andrii Nakryiko,

Quoted 21 lines · LiuLingze
Quoted 10 lines
---
 examples/c/usdt.bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
examples/c/usdt.bpf.c +0 -0
index 49ba506..2612ec1 100644

examples/c/usdt.bpf.c line 8

Quoted 5 lines
examples/c/usdt.bpf.c +1 -1
@@ -5,7 +5,7 @@
 #include <bpf/bpf_tracing.h>
 #include <bpf/usdt.bpf.h>
 
-pid_t my_pid;
+pid_t my_pid =3D 0;

This is effectively the same, my_pid will be initialized to zero anyways. The difference might be due to you using too old Clang version that might still be putting my_pid into a special COM section.

Quoted 15 lines

Also "failed to find BTF info for global/extern symbol" is usually due to too old Clang that doesn't emit BTF information for global variables.

So either way, can you try upgrading your Clang and see if the problem pers= ists?

Quoted 7 lines
examples/c/usdt.bpf.c +0 -1
 SEC("usdt/libc.so.6:libc:setjmp")
 int BPF_USDT(usdt_auto_attach, void *arg1, int arg2, void *arg3)
--

2.37.2

Thank you for your reply.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

Yes, I was able to compile on a newer ubuntu with a higher version of clang.

However, on a development module (nVidia Orin AGX) running an older version of ubuntu, it is not possible to use apt to update clang to a new version. Downloading the source code of a higher version of clang for compilation is cumbersome and affects compatibility. So I hope that with the above changes, the project code can be easily compiled and used in earlier versions.

Did you verify that specifically adding explicit = 0 makes it more compatible with old compiler or it's just a theory?

Yes, I have compiled usdt successfully on Ubuntu 20.04.6 LTS with clang version 10.0.0-4ubuntu1 by specifically adding explicit = 0.

Ok, please send a PR against libbpf-bootstrap repo ([0]) then, which is what you seem to be targeting here.

[0] https://github.com/libbpf/libbpf-bootstrap