* [PATCH] scripts: fix faddr2line to work on last symbol
@ 2017-10-12 3:22 NeilBrown
2017-10-12 15:55 ` Josh Poimboeuf
0 siblings, 1 reply; 4+ messages in thread
From: NeilBrown @ 2017-10-12 3:22 UTC (permalink / raw)
To: Linus Torvalds, Ingo Molnar; +Cc: LKML, Josh Poimboeuf
[-- Attachment #1: Type: text/plain, Size: 1524 bytes --]
If faddr2line is given a function name which is the
last one listed by "nm -n", it will fail because it
never finds the next symbol.
So teach the awk script to catch that possibility,
and use 'size' to provide the end point of the last
function.
Signed-off-by: NeilBrown <neilb@suse.com>
---
scripts/faddr2line | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/scripts/faddr2line b/scripts/faddr2line
index 29df825d375c..2f6ce802397d 100755
--- a/scripts/faddr2line
+++ b/scripts/faddr2line
@@ -103,11 +103,12 @@ __faddr2line() {
# Go through each of the object's symbols which match the func name.
# In rare cases there might be duplicates.
+ file_end=$(size -Ax $objfile | awk '$1 == ".text" {print $2}')
while read symbol; do
local fields=($symbol)
local sym_base=0x${fields[0]}
local sym_type=${fields[1]}
- local sym_end=0x${fields[3]}
+ local sym_end=${fields[3]}
# calculate the size
local sym_size=$(($sym_end - $sym_base))
@@ -157,7 +158,7 @@ __faddr2line() {
addr2line -fpie $objfile $addr | sed "s; $dir_prefix\(\./\)*; ;"
DONE=1
- done < <(nm -n $objfile | awk -v fn=$func '$3 == fn { found=1; line=$0; start=$1; next } found == 1 { found=0; print line, $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; }')
}
[[ $# -lt 2 ]] && usage
--
2.14.0.rc0.dirty
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scripts: fix faddr2line to work on last symbol
2017-10-12 3:22 [PATCH] scripts: fix faddr2line to work on last symbol NeilBrown
@ 2017-10-12 15:55 ` Josh Poimboeuf
2017-10-12 19:27 ` Linus Torvalds
2017-10-12 21:40 ` NeilBrown
0 siblings, 2 replies; 4+ messages in thread
From: Josh Poimboeuf @ 2017-10-12 15:55 UTC (permalink / raw)
To: NeilBrown; +Cc: Linus Torvalds, Ingo Molnar, LKML
On Thu, Oct 12, 2017 at 02:22:04PM +1100, NeilBrown wrote:
>
> If faddr2line is given a function name which is the
> last one listed by "nm -n", it will fail because it
> never finds the next symbol.
>
> So teach the awk script to catch that possibility,
> and use 'size' to provide the end point of the last
> function.
>
> Signed-off-by: NeilBrown <neilb@suse.com>
Thanks. I'm assuming you saw this issue with a .o file, and not with
vmlinux? Because on my vmlinux, the last symbol isn't a text symbol.
This patch is mostly ok, but it will only work if the last symbol is in
the .text section (which will probably be true in most cases).
But that makes me realize that this script has even deeper problems with
.o files.
With vmlinux, the symbols have been assigned absolute addresses, so it
makes sense to sort them by address there, and the symbol sorting works
as expected.
But with .o files, they _haven't_ been assigned absolute addresses.
Instead they just have section offsets, which is what nm prints. So
symbols in different sections will be overlaid. For example:
$ nm -n kernel/fork.o |grep "0000000000000000 [tT]"
0000000000000000 t coredump_filter_setup
0000000000000000 T get_task_mm
0000000000000000 t set_ti_thread_flag
0000000000000000 t __setup_coredump_filter_setup
0000000000000000 t __setup_str_coredump_filter_setup
Here coredump_filter_setup() is at offset 0 in .init.text,
set_ti_thread_flag() is at offset 0 in .text.text.unlikely, and
get_task_mm() is at offset 0 in .text. That confuses the script:
$ scripts/faddr2line kernel/fork.o get_task_mm+0x1
bad symbol size: base: 0x0000000000000000 end: 0x0000000000000000
We need to refactor the script a bit to be more section-aware. Instead
of nm, I think it will need to use objdump or readelf, since nm doesn't
seem to have an option for dumping the section name.
After fixing that, we can then fix the issue you found with the last
symbol.
I can give it a shot, though it may be a few weeks (probably
post-Prague).
--
Josh
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scripts: fix faddr2line to work on last symbol
2017-10-12 15:55 ` Josh Poimboeuf
@ 2017-10-12 19:27 ` Linus Torvalds
2017-10-12 21:40 ` NeilBrown
1 sibling, 0 replies; 4+ messages in thread
From: Linus Torvalds @ 2017-10-12 19:27 UTC (permalink / raw)
To: Josh Poimboeuf; +Cc: NeilBrown, Ingo Molnar, LKML
On Thu, Oct 12, 2017 at 8:55 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
>
> We need to refactor the script a bit to be more section-aware. Instead
> of nm, I think it will need to use objdump or readelf, since nm doesn't
> seem to have an option for dumping the section name.
Fair enough, but I'll apply Neil's patch in the meantime as a stopgap.
Linus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scripts: fix faddr2line to work on last symbol
2017-10-12 15:55 ` Josh Poimboeuf
2017-10-12 19:27 ` Linus Torvalds
@ 2017-10-12 21:40 ` NeilBrown
1 sibling, 0 replies; 4+ messages in thread
From: NeilBrown @ 2017-10-12 21:40 UTC (permalink / raw)
To: Josh Poimboeuf; +Cc: Linus Torvalds, Ingo Molnar, LKML
[-- Attachment #1: Type: text/plain, Size: 724 bytes --]
On Thu, Oct 12 2017, Josh Poimboeuf wrote:
> On Thu, Oct 12, 2017 at 02:22:04PM +1100, NeilBrown wrote:
>>
>> If faddr2line is given a function name which is the
>> last one listed by "nm -n", it will fail because it
>> never finds the next symbol.
>>
>> So teach the awk script to catch that possibility,
>> and use 'size' to provide the end point of the last
>> function.
>>
>> Signed-off-by: NeilBrown <neilb@suse.com>
>
> Thanks. I'm assuming you saw this issue with a .o file, and not with
> vmlinux? Because on my vmlinux, the last symbol isn't a text symbol.
Yes, I was using a .o
Thanks for looking further into this - there certainly are subtleties
that I missed.
Thanks,
NeilBrown
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-10-12 21:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-12 3:22 [PATCH] scripts: fix faddr2line to work on last symbol NeilBrown
2017-10-12 15:55 ` Josh Poimboeuf
2017-10-12 19:27 ` Linus Torvalds
2017-10-12 21:40 ` NeilBrown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome