mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-09 18:19:06 +08:00
libbpf: Fix determine_ptr_size() guessing
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:
- clang uses "unsigned long"
- gcc uses "long unsigned int"
Lookup all the names for such a type so that libbpf can hope to find the
information it wants.
Signed-off-by: Douglas Raillard <douglas.raillard@arm.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20220524094447.332186-1-douglas.raillard@arm.com
This commit is contained in:
committed by
Andrii Nakryiko
parent
37218f49fa
commit
a5d75daa8c
26
src/btf.c
26
src/btf.c
@@ -472,9 +472,22 @@ const struct btf_type *btf__type_by_id(const struct btf *btf, __u32 type_id)
|
|||||||
|
|
||||||
static int determine_ptr_size(const struct btf *btf)
|
static int determine_ptr_size(const struct btf *btf)
|
||||||
{
|
{
|
||||||
|
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",
|
||||||
|
};
|
||||||
const struct btf_type *t;
|
const struct btf_type *t;
|
||||||
const char *name;
|
const char *name;
|
||||||
int i, n;
|
int i, j, n;
|
||||||
|
|
||||||
if (btf->base_btf && btf->base_btf->ptr_sz > 0)
|
if (btf->base_btf && btf->base_btf->ptr_sz > 0)
|
||||||
return btf->base_btf->ptr_sz;
|
return btf->base_btf->ptr_sz;
|
||||||
@@ -485,15 +498,16 @@ static int determine_ptr_size(const struct btf *btf)
|
|||||||
if (!btf_is_int(t))
|
if (!btf_is_int(t))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (t->size != 4 && t->size != 8)
|
||||||
|
continue;
|
||||||
|
|
||||||
name = btf__name_by_offset(btf, t->name_off);
|
name = btf__name_by_offset(btf, t->name_off);
|
||||||
if (!name)
|
if (!name)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (strcmp(name, "long int") == 0 ||
|
for (j = 0; j < ARRAY_SIZE(long_aliases); j++) {
|
||||||
strcmp(name, "long unsigned int") == 0) {
|
if (strcmp(name, long_aliases[j]) == 0)
|
||||||
if (t->size != 4 && t->size != 8)
|
return t->size;
|
||||||
continue;
|
|
||||||
return t->size;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user