All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scripts/faddr2line: Only use text symbols to calculate function size
@ 2022-05-02 18:43 Josh Poimboeuf
  2022-05-06  6:04 ` Kaiwan N Billimoria
  0 siblings, 1 reply; 4+ messages in thread
From: Josh Poimboeuf @ 2022-05-02 18:43 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: linux-kernel, Kaiwan N Billimoria

With the following commit

  efdb4167e676 ("scripts/faddr2line: Fix "size mismatch" error")

it was discovered that faddr2line can't just read a function's ELF
size, because that wouldn't match the kallsyms function size which is
printed in the stack trace.  The kallsyms size includes any padding
after the function, whereas the ELF size does not.

So faddr2line has to manually calculate the size of a function similar
to how kallsyms does.  It does so by starting with a sorted list of
symbols and subtracting the function address from the subsequent
symbol's address.

That calculation is broken in the case where the function is the last
(or only) symbol in the .text section, which can occur quite commonly in
a kernel module or a .o file.  In that case, the next symbol in the
sorted list might actually be a data symbol, which breaks the function
size detection:

  $ scripts/faddr2line sound/soundcore.ko sound_devnode+0x5/0x35
  bad symbol size: base: 0x0000000000000000 end: 0x0000000000000000

Fix it by only including text symbols in the symbol list.

Fixes: efdb4167e676 ("scripts/faddr2line: Fix "size mismatch" error")
Reported-by: Kaiwan N Billimoria <kaiwan.billimoria@gmail.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 scripts/faddr2line | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/faddr2line b/scripts/faddr2line
index 6c6439f69a72..2a130134f1e6 100755
--- a/scripts/faddr2line
+++ b/scripts/faddr2line
@@ -189,7 +189,7 @@ __faddr2line() {
 
 		DONE=1
 
-	done < <(${NM} -n $objfile | awk -v fn=$func -v end=$file_end '$3 == fn { found=1; line=$0; start=$1; next } found == 1 { found=0; print line, "0x"$1 } END {if (found == 1) print line, end; }')
+	done < <(${NM} -n $objfile | awk -v fn=$func -v end=$file_end '$2 !~ /[Tt]/ {next} $3 == fn { found=1; line=$0; start=$1; next } found == 1 { found=0; print line, "0x"$1 } END {if (found == 1) print line, end; }')
 }
 
 [[ $# -lt 2 ]] && usage
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] scripts/faddr2line: Only use text symbols to calculate function size
  2022-05-02 18:43 [PATCH] scripts/faddr2line: Only use text symbols to calculate function size Josh Poimboeuf
@ 2022-05-06  6:04 ` Kaiwan N Billimoria
  2022-05-06 15:26   ` Josh Poimboeuf
  0 siblings, 1 reply; 4+ messages in thread
From: Kaiwan N Billimoria @ 2022-05-06  6:04 UTC (permalink / raw)
  To: Josh Poimboeuf; +Cc: Peter Zijlstra, Linux Kernel Mailing List

Hi Josh,

Unfortunately, it didn't work with my test case (as before):
$ <...>/linux-5.10.60/scripts/faddr2line ./oops_tryv2.ko do_the_work+0x124
bad symbol size: base: 0x0000000000000000 end: 0x0000000000000000
$

What _did_ work was the earlier (much longer) patch you'd sent (your
email dt 20 Jan 2022),
Could you pl recheck...
(As before, i have the test case module here:
https://github.com/PacktPublishing/Linux-Kernel-Debugging/tree/main/ch7/oops_tryv2
)

Regards,
Kaiwan.


On Tue, May 3, 2022 at 12:14 AM Josh Poimboeuf <jpoimboe@redhat.com> wrote:
>
> With the following commit
>
>   efdb4167e676 ("scripts/faddr2line: Fix "size mismatch" error")
>
> it was discovered that faddr2line can't just read a function's ELF
> size, because that wouldn't match the kallsyms function size which is
> printed in the stack trace.  The kallsyms size includes any padding
> after the function, whereas the ELF size does not.
>
> So faddr2line has to manually calculate the size of a function similar
> to how kallsyms does.  It does so by starting with a sorted list of
> symbols and subtracting the function address from the subsequent
> symbol's address.
>
> That calculation is broken in the case where the function is the last
> (or only) symbol in the .text section, which can occur quite commonly in
> a kernel module or a .o file.  In that case, the next symbol in the
> sorted list might actually be a data symbol, which breaks the function
> size detection:
>
>   $ scripts/faddr2line sound/soundcore.ko sound_devnode+0x5/0x35
>   bad symbol size: base: 0x0000000000000000 end: 0x0000000000000000
>
> Fix it by only including text symbols in the symbol list.
>
> Fixes: efdb4167e676 ("scripts/faddr2line: Fix "size mismatch" error")
> Reported-by: Kaiwan N Billimoria <kaiwan.billimoria@gmail.com>
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> ---
>  scripts/faddr2line | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/faddr2line b/scripts/faddr2line
> index 6c6439f69a72..2a130134f1e6 100755
> --- a/scripts/faddr2line
> +++ b/scripts/faddr2line
> @@ -189,7 +189,7 @@ __faddr2line() {
>
>                 DONE=1
>
> -       done < <(${NM} -n $objfile | awk -v fn=$func -v end=$file_end '$3 == fn { found=1; line=$0; start=$1; next } found == 1 { found=0; print line, "0x"$1 } END {if (found == 1) print line, end; }')
> +       done < <(${NM} -n $objfile | awk -v fn=$func -v end=$file_end '$2 !~ /[Tt]/ {next} $3 == fn { found=1; line=$0; start=$1; next } found == 1 { found=0; print line, "0x"$1 } END {if (found == 1) print line, end; }')
>  }
>
>  [[ $# -lt 2 ]] && usage
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] scripts/faddr2line: Only use text symbols to calculate function size
  2022-05-06  6:04 ` Kaiwan N Billimoria
@ 2022-05-06 15:26   ` Josh Poimboeuf
  2022-05-07  1:29     ` Kaiwan N Billimoria
  0 siblings, 1 reply; 4+ messages in thread
From: Josh Poimboeuf @ 2022-05-06 15:26 UTC (permalink / raw)
  To: Kaiwan N Billimoria
  Cc: Josh Poimboeuf, Peter Zijlstra, Linux Kernel Mailing List

On Fri, May 06, 2022 at 11:34:00AM +0530, Kaiwan N Billimoria wrote:
> Hi Josh,
> 
> Unfortunately, it didn't work with my test case (as before):
> $ <...>/linux-5.10.60/scripts/faddr2line ./oops_tryv2.ko do_the_work+0x124
> bad symbol size: base: 0x0000000000000000 end: 0x0000000000000000
> $
> 
> What _did_ work was the earlier (much longer) patch you'd sent (your
> email dt 20 Jan 2022),
> Could you pl recheck...
> (As before, i have the test case module here:
> https://github.com/PacktPublishing/Linux-Kernel-Debugging/tree/main/ch7/oops_tryv2

Sorry, I totally managed to forget that I rewrote the whole script:

  https://lkml.kernel.org/lkml/20220120171751.gibauc4zovoskjns@treble

IIRC, that was the one that fixed your issue.  Let me go clean that one
up...

-- 
Josh

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] scripts/faddr2line: Only use text symbols to calculate function size
  2022-05-06 15:26   ` Josh Poimboeuf
@ 2022-05-07  1:29     ` Kaiwan N Billimoria
  0 siblings, 0 replies; 4+ messages in thread
From: Kaiwan N Billimoria @ 2022-05-07  1:29 UTC (permalink / raw)
  To: Josh Poimboeuf; +Cc: Josh Poimboeuf, Peter Zijlstra, Linux Kernel Mailing List

On Fri, May 6, 2022 at 8:56 PM Josh Poimboeuf <jpoimboe@kernel.org> wrote:
>
> On Fri, May 06, 2022 at 11:34:00AM +0530, Kaiwan N Billimoria wrote:
> > Hi Josh,
> >
> > Unfortunately, it didn't work with my test case (as before):
> > $ <...>/linux-5.10.60/scripts/faddr2line ./oops_tryv2.ko do_the_work+0x124
> > bad symbol size: base: 0x0000000000000000 end: 0x0000000000000000
> > $
> >
> > What _did_ work was the earlier (much longer) patch you'd sent (your
> > email dt 20 Jan 2022),
> > Could you pl recheck...
> > (As before, i have the test case module here:
> > https://github.com/PacktPublishing/Linux-Kernel-Debugging/tree/main/ch7/oops_tryv2
>
> Sorry, I totally managed to forget that I rewrote the whole script:
>
>   https://lkml.kernel.org/lkml/20220120171751.gibauc4zovoskjns@treble
>
> IIRC, that was the one that fixed your issue.  Let me go clean that one
> up...
Yup ! that's the one

>
> --
> Josh

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-05-07  1:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-02 18:43 [PATCH] scripts/faddr2line: Only use text symbols to calculate function size Josh Poimboeuf
2022-05-06  6:04 ` Kaiwan N Billimoria
2022-05-06 15:26   ` Josh Poimboeuf
2022-05-07  1:29     ` Kaiwan N Billimoria

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.