From d1ea490253710dc4d59e86ce5ba8ac7d3e7c537c Mon Sep 17 00:00:00 2001 From: Martin Cermak Date: Thu, 25 Jan 2024 11:46:50 +0100 Subject: [PATCH] PR26843: print_ubacktrace_fileline() fails with PIE binaries Ubuntu has it's GCC configured with --enable-default-pie. The binaries it's producing by default are DYN (Position-Independent Executable file). This isn't reflected in the producer record. For processing PIE binaries, additional relocation is needed in the stap runtime. --- runtime/sym.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runtime/sym.c b/runtime/sym.c index 595871bc6..720ba2239 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -379,6 +379,7 @@ unsigned long _stp_linenumber_lookup(unsigned long addr, struct task_struct *tas uint8_t *str_linep, *str_enddatap; int compat_task = _stp_is_compat_task(); int user = (task ? 1 : 0); + unsigned long rel_off = 0; // the portion below is encased in this conditional because some of the functions // and constants needed are encased in a similar condition @@ -394,6 +395,9 @@ unsigned long _stp_linenumber_lookup(unsigned long addr, struct task_struct *tas addr &= ((compat_ulong_t) ~0); #endif m = _stp_umod_lookup(addr, task, &modname, NULL, NULL, NULL); + // PR26843: In case the binary is PIE we need to relocate the addr + // For non-PIE binaries the addr stays unchanged. + addr = addr - _stp_umodule_relocate(m->path, rel_off, task); } else m = _stp_kmod_sec_lookup(addr, &sec); -- 2.43.5