* [PATCHv2 0/1] In report_r_debug, iterate more segments @ 2023-05-12 19:11 Luke Diamand 2023-05-12 19:11 ` [PATCHv2 1/1] report_r_debug: handle `-z separate-code' and find more modules Luke Diamand 0 siblings, 1 reply; 3+ messages in thread From: Luke Diamand @ 2023-05-12 19:11 UTC (permalink / raw) To: elfutils-devel; +Cc: Florian Weimer, Mark Wielaard, Luke Diamand Further to: https://sourceware.org/pipermail/elfutils-devel/2023q2/006149.html This is a patch to increase the number of iterations looking for segments to load. This lets eu-stack backtrace cores that would otherwise fail. Florian Weimer and Mark Wielaard suggested both the explanation and the fix. Luke Diamand (1): report_r_debug: handle `-z separate-code' and find more modules libdwfl/link_map.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) -- 2.40.1 ^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCHv2 1/1] report_r_debug: handle `-z separate-code' and find more modules 2023-05-12 19:11 [PATCHv2 0/1] In report_r_debug, iterate more segments Luke Diamand @ 2023-05-12 19:11 ` Luke Diamand 2023-05-12 20:08 ` Mark Wielaard 0 siblings, 1 reply; 3+ messages in thread From: Luke Diamand @ 2023-05-12 19:11 UTC (permalink / raw) To: elfutils-devel; +Cc: Florian Weimer, Mark Wielaard, Luke Diamand Looking at some cores in eu-stack, I found that they were not being backtraced. This was because elfutils had not found some modules (e.g. libc-2.22.so) in report_r_debug. That is because it has a limit on the number of link map entries it will look at, to avoid loops in corrupted core files. The example I found had: - 36 elements - 109 iterations See also discussion here: https://sourceware.org/pipermail/elfutils-devel/2023q2/006149.html Signed-off-by: Luke Diamand <ldiamand@roku.com> --- libdwfl/link_map.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c index 06d85eb6..76f23354 100644 --- a/libdwfl/link_map.c +++ b/libdwfl/link_map.c @@ -331,11 +331,17 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata, int result = 0; /* There can't be more elements in the link_map list than there are - segments. DWFL->lookup_elts is probably twice that number, so it - is certainly above the upper bound. If we iterate too many times, - there must be a loop in the pointers due to link_map clobberation. */ + segments. A segment is created for each PT_LOAD and there can be + up to 5 per module (-z separate-code, tends to create four LOAD + segments, gold has -z text-unlikely-segment, which might result + in creating that number of load segments) DWFL->lookup_elts is + probably twice the number of modules, so that multiplied by max + PT_LOADs is certainly above the upper bound. If we iterate too + many times, there must be a loop in the pointers due to link_map + clobberation. */ +#define MAX_PT_LOAD 5 size_t iterations = 0; - while (next != 0 && ++iterations < dwfl->lookup_elts) + while (next != 0 && ++iterations < dwfl->lookup_elts * MAX_PT_LOAD) { if (read_addrs (&memory_closure, elfclass, elfdata, &buffer, &buffer_available, next, &read_vaddr, -- 2.40.1 ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCHv2 1/1] report_r_debug: handle `-z separate-code' and find more modules 2023-05-12 19:11 ` [PATCHv2 1/1] report_r_debug: handle `-z separate-code' and find more modules Luke Diamand @ 2023-05-12 20:08 ` Mark Wielaard 0 siblings, 0 replies; 3+ messages in thread From: Mark Wielaard @ 2023-05-12 20:08 UTC (permalink / raw) To: Luke Diamand; +Cc: elfutils-devel, Florian Weimer Hi Luke, On Fri, May 12, 2023 at 08:11:45PM +0100, Luke Diamand wrote: > Looking at some cores in eu-stack, I found that they were not being > backtraced. > > This was because elfutils had not found some modules (e.g. libc-2.22.so) > in report_r_debug. > > That is because it has a limit on the number of link map entries it will > look at, to avoid loops in corrupted core files. Looks good. Pushed. Thanks, Mark ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-12 20:08 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-05-12 19:11 [PATCHv2 0/1] In report_r_debug, iterate more segments Luke Diamand 2023-05-12 19:11 ` [PATCHv2 1/1] report_r_debug: handle `-z separate-code' and find more modules Luke Diamand 2023-05-12 20:08 ` Mark Wielaard
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).