Fix determine_ptr_size() guessing
(cherry picked from commit f6ebdd7a5d94f81748c3bf3b59a6644cca9f1588)
This commit is contained in:
parent
546b8c0304
commit
ca85c57bc5
77
backport-libbpf-Fix-determine_ptr_size-guessing.patch
Normal file
77
backport-libbpf-Fix-determine_ptr_size-guessing.patch
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
From a5d75daa8c467a863ecf297982b70ed284adc0e9 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Douglas Raillard <douglas.raillard@arm.com>
|
||||||
|
Date: Tue, 24 May 2022 10:44:47 +0100
|
||||||
|
Subject: [PATCH] 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
|
||||||
|
---
|
||||||
|
src/btf.c | 26 ++++++++++++++++++++------
|
||||||
|
1 file changed, 20 insertions(+), 6 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/btf.c b/src/btf.c
|
||||||
|
index bb1e06eb1..3d6c30d9a 100644
|
||||||
|
--- a/src/btf.c
|
||||||
|
+++ b/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 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 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;
|
||||||
|
@@ -485,15 +498,16 @@ static int determine_ptr_size(const struct btf *btf)
|
||||||
|
if (!btf_is_int(t))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
+ if (t->size != 4 && t->size != 8)
|
||||||
|
+ continue;
|
||||||
|
+
|
||||||
|
name = btf__name_by_offset(btf, t->name_off);
|
||||||
|
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;
|
||||||
|
+ for (j = 0; j < ARRAY_SIZE(long_aliases); j++) {
|
||||||
|
+ if (strcmp(name, long_aliases[j]) == 0)
|
||||||
|
+ return t->size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
10
libbpf.spec
10
libbpf.spec
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
Name: %{githubname}
|
Name: %{githubname}
|
||||||
Version: %{githubver}
|
Version: %{githubver}
|
||||||
Release: 2
|
Release: 3
|
||||||
Summary: Libbpf library
|
Summary: Libbpf library
|
||||||
|
|
||||||
License: LGPLv2 or BSD
|
License: LGPLv2 or BSD
|
||||||
@ -12,6 +12,9 @@ URL: https://github.com/%{githubname}/%{githubname}
|
|||||||
Source: https://github.com/%{githubname}/%{githubname}/archive/%{githubname}-%{githubver}.tar.gz
|
Source: https://github.com/%{githubname}/%{githubname}/archive/%{githubname}-%{githubver}.tar.gz
|
||||||
BuildRequires: gcc elfutils-libelf-devel elfutils-devel
|
BuildRequires: gcc elfutils-libelf-devel elfutils-devel
|
||||||
|
|
||||||
|
#patches
|
||||||
|
Patch0000: backport-libbpf-Fix-determine_ptr_size-guessing.patch
|
||||||
|
|
||||||
# This package supersedes libbpf from kernel-tools,
|
# This package supersedes libbpf from kernel-tools,
|
||||||
# which has default Epoch: 0. By having Epoch: 1
|
# which has default Epoch: 0. By having Epoch: 1
|
||||||
# this libbpf will take over smoothly
|
# this libbpf will take over smoothly
|
||||||
@ -42,7 +45,7 @@ developing applications that use %{name}
|
|||||||
%global make_flags DESTDIR=%{buildroot} OBJDIR=%{_builddir} CFLAGS="%{build_cflags} -fPIC" LDFLAGS="%{build_ldflags} -Wl,--no-as-needed" LIBDIR=/%{_libdir} NO_PKG_CONFIG=1
|
%global make_flags DESTDIR=%{buildroot} OBJDIR=%{_builddir} CFLAGS="%{build_cflags} -fPIC" LDFLAGS="%{build_ldflags} -Wl,--no-as-needed" LIBDIR=/%{_libdir} NO_PKG_CONFIG=1
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
%autosetup -n %{githubfull}
|
%autosetup -n %{githubfull} -p1
|
||||||
|
|
||||||
%build
|
%build
|
||||||
%make_build -C ./src %{make_flags}
|
%make_build -C ./src %{make_flags}
|
||||||
@ -63,6 +66,9 @@ developing applications that use %{name}
|
|||||||
%{_libdir}/libbpf.a
|
%{_libdir}/libbpf.a
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Wed Oct 26 2022 zhangmingyi <zhangmingyi5@huawei.com> - 2:0.3-3
|
||||||
|
- Fix determine_ptr_size() guessing
|
||||||
|
|
||||||
* Mon Aug 22 2022 hujiawang <hujiawang1@huawei.com> - 2:0.3-2
|
* Mon Aug 22 2022 hujiawang <hujiawang1@huawei.com> - 2:0.3-2
|
||||||
- change the package name
|
- change the package name
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user