diff --git a/0001-dwarves-Zero-initialize-struct-cu-in-cu__new-to-prev.patch b/0001-dwarves-Zero-initialize-struct-cu-in-cu__new-to-prev.patch deleted file mode 100644 index 5d90d12ab134b13eb5a64dd13071e0eed84dbab4..0000000000000000000000000000000000000000 --- a/0001-dwarves-Zero-initialize-struct-cu-in-cu__new-to-prev.patch +++ /dev/null @@ -1,93 +0,0 @@ -From b72f5188856df0abf45e1a707856bb4e4e86153c Mon Sep 17 00:00:00 2001 -From: Alan Maguire -Date: Fri, 21 Oct 2022 16:02:03 +0100 -Subject: [PATCH] dwarves: Zero-initialize struct cu in cu__new() to prevent - incorrect BTF types - -BTF deduplication was throwing some strange results, where core kernel -data types were failing to deduplicate due to the return values -of function type members being void (0) instead of the actual type -(unsigned int). An example of this can be seen below, where -"struct dst_ops" was failing to deduplicate between kernel and -module: - -struct dst_ops { - short unsigned int family; - unsigned int gc_thresh; - int (*gc)(struct dst_ops *); - struct dst_entry * (*check)(struct dst_entry *, __u32); - unsigned int (*default_advmss)(const struct dst_entry *); - unsigned int (*mtu)(const struct dst_entry *); -... - -struct dst_ops___2 { - short unsigned int family; - unsigned int gc_thresh; - int (*gc)(struct dst_ops___2 *); - struct dst_entry___2 * (*check)(struct dst_entry___2 *, __u32); - void (*default_advmss)(const struct dst_entry___2 *); - void (*mtu)(const struct dst_entry___2 *); -... - -This was seen with - -bcc648a10cbc ("btf_encoder: Encode DW_TAG_unspecified_type returning routines as void") - -...which rewrites the return value as 0 (void) when it is marked -as matching DW_TAG_unspecified_type: - -static int32_t btf_encoder__tag_type(struct btf_encoder *encoder, uint32_t type_id_off, uint32_t tag_type) -{ - if (tag_type == 0) - return 0; - - if (encoder->cu->unspecified_type.tag && tag_type == encoder->cu->unspecified_type.type) { - // No provision for encoding this, turn it into void. - return 0; - } - - return type_id_off + tag_type; -} - -However the odd thing was that on further examination, the unspecified type -was not being set, so why was this logic being tripped? Futher debugging -showed that the encoder->cu->unspecified_type.tag value was garbage, and -the type id happened to collide with "unsigned int"; as a result we -were replacing unsigned ints with void return values, and since this -was being done to function type members in structs, it triggered a -type mismatch which failed deduplication between kernel and module. - -The fix is simply to calloc() the cu in cu__new() instead. - -Committer notes: - -We have zalloc(size) as an alias to calloc(1, size), use it instead. - -Fixes: bcc648a10cbcd0b9 ("btf_encoder: Encode DW_TAG_unspecified_type returning routines as void") -Signed-off-by: Alan Maguire -Acked-by: Andrii Nakryiko -Acked-by: Jiri Olsa -Cc: bpf@vger.kernel.org -Cc: dwarves@vger.kernel.org -Link: https://lore.kernel.org/r/1666364523-9648-1-git-send-email-alan.maguire@oracle.com -Signed-off-by: Arnaldo Carvalho de Melo ---- - dwarves.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/dwarves.c b/dwarves.c -index fbebc1d..95a3bac 100644 ---- a/dwarves.c -+++ b/dwarves.c -@@ -626,7 +626,7 @@ struct cu *cu__new(const char *name, uint8_t addr_size, - const unsigned char *build_id, int build_id_len, - const char *filename, bool use_obstack) - { -- struct cu *cu = malloc(sizeof(*cu) + build_id_len); -+ struct cu *cu = zalloc(sizeof(*cu) + build_id_len); - - if (cu != NULL) { - uint32_t void_id; --- -2.38.1 - diff --git a/6a2b27c0f512619b0e7a769a18a0fb05bb3789a5.patch b/6a2b27c0f512619b0e7a769a18a0fb05bb3789a5.patch new file mode 100644 index 0000000000000000000000000000000000000000..ab740729ac6b688ecb5e31220ae0e76b73076219 --- /dev/null +++ b/6a2b27c0f512619b0e7a769a18a0fb05bb3789a5.patch @@ -0,0 +1,83 @@ +From 6a2b27c0f512619b0e7a769a18a0fb05bb3789a5 Mon Sep 17 00:00:00 2001 +From: Arnaldo Carvalho de Melo +Date: Tue, 18 Jun 2024 10:37:30 -0300 +Subject: [PATCH] core: Initialize cu->node with INIT_LIST_HEAD() +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +In cu__new() zalloc() is used defensively, and that helped catch this +problem where we assume that a cu us in the cus list of cu instances, +but that is not the case when we use cus__merge_and_process_cu(), for +instance when loading files created by clang with LTO, as reported by +Peter Jung and narrowed down by Nathan Chancellor. + +If we use INIT_LIST_HEAD() in cu__new() to initialize cu->node, which is +what we do with other lists and nodes there, then the unconditional +removal using list_del_init() will be a no-op and removing something not +on the cus list of cu instances will not cause problems, just keep an +unconsistent cus->nr_entries field. + +So lets just have this fix in first, keeping Nathan's Tested-by and then +do the a bit more involved fix of either adding that cu to the cus list +or checking at removal time if it is there. + + Program received signal SIGSEGV, Segmentation fault. + 0x00007ffff7f1e13e in __list_del (prev=0x0, next=0x0) at /home/acme/git/pahole/list.h:106 + 106 next->prev = prev; + (gdb) bt + #0 0x00007ffff7f1e13e in __list_del (prev=0x0, next=0x0) at /home/acme/git/pahole/list.h:106 + #1 0x00007ffff7f1e176 in list_del_init (entry=0x417980) at /home/acme/git/pahole/list.h:165 + #2 0x00007ffff7f1f8f9 in __cus__remove (cus=0x4142a0, cu=0x417980) at /home/acme/git/pahole/dwarves.c:527 + #3 0x00007ffff7f1f92b in cus__remove (cus=0x4142a0, cu=0x417980) at /home/acme/git/pahole/dwarves.c:533 + #4 0x00007ffff7f3d01c in cus__finalize (cus=0x4142a0, cu=0x417980, conf=0x4133c0 , thr_data=0x0) + at /home/acme/git/pahole/dwarf_loader.c:3040 + #5 0x00007ffff7f3e05c in cus__merge_and_process_cu (cus=0x4142a0, conf=0x4133c0 , mod=0x415cf0, dw=0x416110, elf=0x414380, + filename=0x7fffffffe3f7 "cast_common.ko", build_id=0x416680 "\265D\371U\213\373u|\037\250\242\032\271\365⒜]y\023", build_id_len=20, + type_dcu=0x0) at /home/acme/git/pahole/dwarf_loader.c:3482 + #6 0x00007ffff7f3e218 in cus__load_module (cus=0x4142a0, conf=0x4133c0 , mod=0x415cf0, dw=0x416110, elf=0x414380, + filename=0x7fffffffe3f7 "cast_common.ko") at /home/acme/git/pahole/dwarf_loader.c:3521 + #7 0x00007ffff7f3e396 in cus__process_dwflmod (dwflmod=0x415cf0, userdata=0x415d00, name=0x415ea0 "cast_common.ko", base=65536, + arg=0x7fffffffde40) at /home/acme/git/pahole/dwarf_loader.c:3581 + #8 0x00007ffff7eb4609 in dwfl_getmodules (dwfl=0x414300, callback=0x7ffff7f3e2ec , arg=0x7fffffffde40, offset=0) + at ../libdwfl/dwfl_getmodules.c:86 + #9 0x00007ffff7f3e4c5 in cus__process_file (cus=0x4142a0, conf=0x4133c0 , fd=3, filename=0x7fffffffe3f7 "cast_common.ko") + at /home/acme/git/pahole/dwarf_loader.c:3647 + #10 0x00007ffff7f3e5cd in dwarf__load_file (cus=0x4142a0, conf=0x4133c0 , filename=0x7fffffffe3f7 "cast_common.ko") + at /home/acme/git/pahole/dwarf_loader.c:3684 + #11 0x00007ffff7f232df in cus__load_file (cus=0x4142a0, conf=0x4133c0 , filename=0x7fffffffe3f7 "cast_common.ko") + at /home/acme/git/pahole/dwarves.c:2134 + #12 0x00007ffff7f23e8b in cus__load_files (cus=0x4142a0, conf=0x4133c0 , filenames=0x7fffffffe0f0) + at /home/acme/git/pahole/dwarves.c:2637 + #13 0x000000000040aec0 in main (argc=2, argv=0x7fffffffe0e8) at /home/acme/git/pahole/pahole.c:3805 + (gdb) fr 1 + #1 0x00007ffff7f1e176 in list_del_init (entry=0x417980) at /home/acme/git/pahole/list.h:165 + 165 __list_del(entry->prev, entry->next); + (gdb) p entry + $1 = (struct list_head *) 0x417980 + (gdb) p entry->next + $2 = (struct list_head *) 0x0 + (gdb) p entry->prev + $3 = (struct list_head *) 0x0 + +Closes: https://github.com/acmel/dwarves/issues/53 +Closes: https://gitlab.archlinux.org/archlinux/packaging/packages/pahole/-/issues/1 +Tested-by: Nathan Chancellor +Link: https://lore.kernel.org/all/20240617210810.GA1877676@thelio-3990X +Signed-off-by: Arnaldo Carvalho de Melo +--- + dwarves.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/dwarves.c b/dwarves.c +index 1ec259f5..823a0152 100644 +--- a/dwarves.c ++++ b/dwarves.c +@@ -739,6 +739,7 @@ struct cu *cu__new(const char *name, uint8_t addr_size, + cu->dfops = NULL; + INIT_LIST_HEAD(&cu->tags); + INIT_LIST_HEAD(&cu->tool_list); ++ INIT_LIST_HEAD(&cu->node); + + cu->addr_size = addr_size; + cu->extra_dbg_info = 0; diff --git a/94a01bde592c555b3eb526aeb4c2ad695c5660d8.patch b/94a01bde592c555b3eb526aeb4c2ad695c5660d8.patch new file mode 100644 index 0000000000000000000000000000000000000000..83bb54428229c020507a590956d1f6aba3c91d88 --- /dev/null +++ b/94a01bde592c555b3eb526aeb4c2ad695c5660d8.patch @@ -0,0 +1,46 @@ +From 94a01bde592c555b3eb526aeb4c2ad695c5660d8 Mon Sep 17 00:00:00 2001 +From: Arnaldo Carvalho de Melo +Date: Tue, 18 Jun 2024 11:14:09 -0300 +Subject: [PATCH] dwarf_loader: Add missing cus__add(cus, cu) to + cus__merge_and_process_cu() + +In cus__finalize() if cu__finalize() returns LSK__DELETE, i.e. if the +tool processing the cu is done with it, we will assume that it is in the +cus list of cu instances, remove it and then delete it. + +This was not being done by cus__merge_and_process_cu(), used when +merging all DWARF CUs into a single 'struct cu', such as when processing +binaries generated by clang using LTO. + +Add the missing cus__add() to keep cus->nr_entries consistent. + +Cc: Alan Maguire +Cc: Daniel Xu +Cc: Domenico Andreoli +Cc: Dominique Leuenberger +Cc: Eduard Zingerman +Cc: Jan Alexander Steffens +Cc: Jan Engelhardt +Cc: Jiri Olsa +Cc: Matthias Schwarzott +Cc: Nathan Chancellor +Cc: Viktor Malik +Cc: Yonghong Song +Link: https://lore.kernel.org/all/ZnGZ71a4E29kPrvS@x1 +Signed-off-by: Arnaldo Carvalho de Melo +--- + dwarf_loader.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/dwarf_loader.c b/dwarf_loader.c +index b832c93c..3caf3245 100644 +--- a/dwarf_loader.c ++++ b/dwarf_loader.c +@@ -3452,6 +3452,7 @@ static int cus__merge_and_process_cu(struct cus *cus, struct conf_load *conf, + cu->priv = dcu; + cu->dfops = &dwarf__ops; + cu->language = attr_numeric(cu_die, DW_AT_language); ++ cus__add(cus, cu); + } + + Dwarf_Die child; diff --git a/dist b/dist new file mode 100644 index 0000000000000000000000000000000000000000..89c1faffc18349bb12eee2371e9dc43bf419b95c --- /dev/null +++ b/dist @@ -0,0 +1 @@ +an9 diff --git a/download b/download index 021fb9604896829e3fe7b0f9891dbbc2f0d34cd2..3b7a7304f8fd0341bbbf2cadc3a87e4eb4430957 100644 --- a/download +++ b/download @@ -1 +1 @@ -c2a2e771a50df28911310a071e410581 dwarves-1.24.tar.xz +bea096b0fcd7144675873bf12f46b2aa dwarves-1.27.tar.xz diff --git a/dwarves.spec b/dwarves.spec index b14bf847642c84b4c79784d4a2b83cefe0d79488..c0732869e51a81c47d09dc198b64647468e977a5 100644 --- a/dwarves.spec +++ b/dwarves.spec @@ -3,18 +3,22 @@ %define libver 1 Name: dwarves -Version: 1.24 +Version: 1.27 Release: 2%{anolis_release}%{?dist} License: GPLv2 Summary: Debugging Information Manipulation Tools (pahole & friends) URL: http://acmel.wordpress.com Source: http://fedorapeople.org/~acme/dwarves/%{name}-%{version}.tar.xz +# core: Initialize cu->node with INIT_LIST_HEAD() +Patch1: https://github.com/acmel/dwarves/commit/6a2b27c0f512619b0e7a769a18a0fb05bb3789a5.patch +# dwarf_loader: Add missing cus__add(cus, cu) to cus__merge_and_process_cu() +Patch2: https://github.com/acmel/dwarves/commit/94a01bde592c555b3eb526aeb4c2ad695c5660d8.patch Requires: %{libname}%{libver} = %{version}-%{release} -Patch1: 0001-dwarves-Zero-initialize-struct-cu-in-cu__new-to-prev.patch BuildRequires: gcc BuildRequires: cmake >= 2.8.12 BuildRequires: zlib-devel BuildRequires: elfutils-devel >= 0.130 +BuildRequires: libbpf-devel BuildRequires: python3 %description @@ -67,8 +71,7 @@ Requires: %{libname}%{libver} = %{version}-%{release} Debugging information processing library development files. %prep -%setup -q -%patch1 -p1 +%autosetup -p1 %build %cmake -DCMAKE_BUILD_TYPE=Release . @@ -83,8 +86,8 @@ rm -Rf %{buildroot} %files %doc README.ctracer %doc README.btf -%doc changes-v1.23 -%doc changes-v1.24 +%doc changes-v1.26 +%doc changes-v1.27 %doc NEWS %{_bindir}/btfdiff %{_bindir}/codiff @@ -136,8 +139,47 @@ rm -Rf %{buildroot} %{_libdir}/%{libname}_reorganize.so %changelog -* Fri Dec 23 2022 Chang Gao - 1.24-2.0.1 -- Add Buildrequires python3 +* Wed Dec 04 2024 Zhao Hang - 1.27-2.0.1 +- Add patch number and remove LIBBPF_EMBEDDED +- Add Buildrequires python3 (gc-taifu@linux.alibaba.com) + +* Mon Aug 12 2024 Davide Cavalca - 1.27-2 +- Backport upstream bugfixes for clang builds + Resolves: RHEL-54022 + +* Thu Jun 20 2024 Viktor Malik - 1.27-1 +- Resolves: RHEL-30780 +- New release: v1.26 +- When expanding types using 'pahole -E' do it for union and struct typedefs and for enums too. +- Print number of holes, bit holes and bit paddings in class member types. +- Introduce --contains_enumerator=ENUMERATOR_NAME: +- Fix pretty printing using DWARF, waiting for a CU with both class (-C) and a specified "type_enum". +- Add support for DW_TAG_constant in the DWARF loader, first seen in Go DWARF. +- Fix loading DW_TAG_subroutine_type generated by the Go compiler. +- Fix loading of 32-bit signed enums from BTF. +- Add 'pahole --btf_features' to allow consumers to specify an opt-in set of features they want to use in BTF encoding. +- Parallelize loading BTF and DWARF, speeding up a bit btfdiff. +- Do type expansion to cover "private" types and enumerations in btfdiff. +- New release: v1.27 +- Reproducible parallel builds: multiple runs with different number of loading/encoding threads produce the same result. +- Inject kfunc decl tags into BTF from the BTF IDs ELF section in the Linux kernel vmlinux file. +- Sanitize unsupported DWARF int type with greater-than-16 byte, as BTF doesn't support it. +- Initial support for BTF_KIND_DECL_TAG in the BTF loader, adding support in pfunct output. +- Fix hole discovery with inheritance in C++. + +* Wed Jun 14 2023 Viktor Malik - 1.25-1 +- Resolves: rhbz#2190484 +- Build with system libbpf +- New release: v1.25 +- Support for DW_TAG_unspecified_type more generally. +- Make sure struct member offsets are in ascending order. Rust BTF needs this. +- Support C atomic types (DW_TAG_atomic_type). +- Initial support for DW_TAG_LLVM_annotation, used for BTF type tags, for __rcu, __user, etc +- Exclude functions with the same name (static functions in different CUs), inconsistent prototypes or not following calling convention. +- Allow generation of BTF for optimized functions, those that end with a .isra*, .constprop*. +- Support 'pahole --lang=/--lang_exclude=asm' +- Support --compile from DWARF in addition to from BTF. +- Exclude RUST CUs in 'btfdiff', as those are not yet being BTF encoded. * Wed Nov 16 2022 Viktor Malik - 1.24-2 - Backport BTF fix needed for kernel kfuncs