Message ID | 20220524094447.332186-1-douglas.raillard@arm.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 8a140f1b12f71cb885b7af1dd5e5a8b58d9adb14 |
Delegated to: | BPF |
Headers | show |
Series | [v3] libbpf: Fix determine_ptr_size() guessing | expand |
Context | Check | Description |
---|---|---|
bpf/vmtest-bpf-next-PR | success | PR summary |
bpf/vmtest-bpf-next-VM_Test-2 | success | Logs for Kernel LATEST on ubuntu-latest with llvm-15 |
bpf/vmtest-bpf-next-VM_Test-1 | success | Logs for Kernel LATEST on ubuntu-latest with gcc |
bpf/vmtest-bpf-next-VM_Test-3 | success | Logs for Kernel LATEST on z15 with gcc |
bpf/vmtest-bpf-PR | pending | PR summary |
bpf/vmtest-bpf-VM_Test-1 | pending | Logs for Kernel LATEST on ubuntu-latest with gcc |
bpf/vmtest-bpf-VM_Test-2 | pending | Logs for Kernel LATEST on ubuntu-latest with llvm-15 |
bpf/vmtest-bpf-VM_Test-3 | pending | Logs for Kernel LATEST on z15 with gcc |
netdev/tree_selection | success | Not a local patch |
Hello: This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <andrii@kernel.org>: On Tue, 24 May 2022 10:44:47 +0100 you wrote: > From: Douglas Raillard <douglas.raillard@arm.com> > > One strategy employed by libbpf to guess the pointer size is by finding > the size of "unsigned long" type. This is achieved by looking for a type > of with the expected name and checking its size. > > Unfortunately, the C syntax is friendlier to humans than to computers > as there is some variety in how such a type can be named. Specifically, > gcc and clang do not use the same names for integer types in debug info: > > [...] Here is the summary with links: - [v3] libbpf: Fix determine_ptr_size() guessing https://git.kernel.org/bpf/bpf-next/c/8a140f1b12f7 You are awesome, thank you!
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 1383e26c5d1f..65c492a6807f 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -470,12 +470,25 @@ const struct btf_type *btf__type_by_id(const struct btf *btf, __u32 type_id) return btf_type_by_id((struct btf *)btf, type_id); } +static const char * const long_aliases[] = { + "long", + "long int", + "int long", + "unsigned long", + "long unsigned", + "unsigned long int", + "unsigned int long", + "long unsigned int", + "long int unsigned", + "int unsigned long", + "int long unsigned", +}; + static int determine_ptr_size(const struct btf *btf) { const struct btf_type *t; const char *name; - int i, n; - + int i, j, n; if (btf->base_btf && btf->base_btf->ptr_sz > 0) return btf->base_btf->ptr_sz; @@ -489,12 +502,12 @@ static int determine_ptr_size(const struct btf *btf) if (!name) continue; - if (strcmp(name, "long int") == 0 || - strcmp(name, "long unsigned int") == 0) { - if (t->size != 4 && t->size != 8) - continue; - return t->size; - } + if (t->size != 4 && t->size != 8) + continue; + + for (j = 0; j < ARRAY_SIZE(long_aliases); j++) + if (!strcmp(name, long_aliases[j])) + return t->size; } return -1;