From 131dd6de582e92508c2e41a835b5781c9e55a8d9 Mon Sep 17 00:00:00 2001 From: zhang-mingyi66 Date: Thu, 19 Jan 2023 15:33:21 +0800 Subject: [PATCH] backporting --- ...bbpf-Fix-determine_ptr_size-guessing.patch | 79 +++++++++++++++++++ libbpf.spec | 6 +- 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 backport-libbpf-Fix-determine_ptr_size-guessing.patch diff --git a/backport-libbpf-Fix-determine_ptr_size-guessing.patch b/backport-libbpf-Fix-determine_ptr_size-guessing.patch new file mode 100644 index 0000000..5a638d7 --- /dev/null +++ b/backport-libbpf-Fix-determine_ptr_size-guessing.patch @@ -0,0 +1,79 @@ +From a5d75daa8c467a863ecf297982b70ed284adc0e9 Mon Sep 17 00:00:00 2001 +From: Douglas Raillard +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 +Signed-off-by: Andrii Nakryiko +Acked-by: Yonghong Song +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 7dfca70..dbe0ce0 100644 +--- a/src/btf.c ++++ b/src/btf.c +@@ -224,24 +224,38 @@ 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; ++ int i, j; + + for (i = 1; i <= btf->nr_types; i++) { + t = btf__type_by_id(btf, i); + 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; + } + } + +-- +2.33.0 + diff --git a/libbpf.spec b/libbpf.spec index e62fc7c..5ae0069 100644 --- a/libbpf.spec +++ b/libbpf.spec @@ -4,7 +4,7 @@ Name: %{githubname} Version: %{githubver} -Release: 2 +Release: 3 Summary: Libbpf library License: LGPLv2 or BSD @@ -16,6 +16,7 @@ BuildRequires: gcc elfutils-libelf-devel elfutils-devel Patch0000: backport-libbpf-Ensure-functions-with-always_inline-attribute-are-inline.patch Patch0001: backport-libbpf-Fix-the-name-of-a-reused-map.patch Patch0002: backport-libbpf-preserve-errno-across-pr_warn-pr_info-pr_debug.patch +Patch0003: backport-libbpf-Fix-determine_ptr_size-guessing.patch # This package supersedes libbpf from kernel-tools, # which has default Epoch: 0. By having Epoch: 1 @@ -67,6 +68,9 @@ developing applications that use %{name} %{_libdir}/libbpf.a %changelog +* Thu Jan 19 2023 zhangmingyi - 2:0.1.1-3 +- backporting: backport-libbpf-Fix-determine_ptr_size-guessing.patch + * Thu Dec 8 2022 zhangmingyi - 2:0.1.1-2 - backporting: backport-libbpf-Ensure-functions-with-always_inline-attribute-are-inline.patch backport-libbpf-Fix-the-name-of-a-reused-map.patch -- Gitee