Skip to content

Commit efdb416

Browse files
jpoimboeingomolnar
authored andcommitted
scripts/faddr2line: Fix "size mismatch" error
I'm not sure how we missed this problem before. When I take a function address and size from an oops and give it to faddr2line, it usually complains about a size mismatch: $ scripts/faddr2line ~/k/vmlinux write_sysrq_trigger+0x51/0x60 skipping write_sysrq_trigger address at 0xffffffff815731a1 due to size mismatch (0x60 != 83) no match for write_sysrq_trigger+0x51/0x60 The problem is caused by differences in how kallsyms and faddr2line determine a function's size. kallsyms calculates a function's size by parsing the output of 'nm -n' and subtracting the next function's address from the current function's address. This means that nop instructions after the end of the function are included in the size. In contrast, faddr2line reads the size from the symbol table, which does *not* include the ending nops in the function's size. Change faddr2line to calculate the size from the output of 'nm -n' to be consistent with kallsyms and oops outputs. Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/bd313ed7c4003f6b1fda63e825325c44a9d837de.1477405374.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 5e25d5b commit efdb416

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

‎scripts/faddr2line‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,18 @@ __faddr2line() {
105105
# In rare cases there might be duplicates.
106106
while read symbol; do
107107
local fields=($symbol)
108-
local sym_base=0x${fields[1]}
109-
local sym_size=${fields[2]}
110-
local sym_type=${fields[3]}
108+
local sym_base=0x${fields[0]}
109+
local sym_type=${fields[1]}
110+
local sym_end=0x${fields[3]}
111+
112+
# calculate the size
113+
local sym_size=$(($sym_end - $sym_base))
114+
if [[ -z $sym_size ]] || [[ $sym_size -le 0 ]]; then
115+
warn "bad symbol size: base: $sym_base end: $sym_end"
116+
DONE=1
117+
return
118+
fi
119+
sym_size=0x$(printf %x $sym_size)
111120

112121
# calculate the address
113122
local addr=$(($sym_base + $offset))
@@ -116,39 +125,39 @@ __faddr2line() {
116125
DONE=1
117126
return
118127
fi
119-
local hexaddr=0x$(printf %x $addr)
128+
addr=0x$(printf %x $addr)
120129

121130
# weed out non-function symbols
122-
if [[ $sym_type != "FUNC" ]]; then
131+
if [[ $sym_type != t ]] && [[ $sym_type != T ]]; then
123132
[[ $print_warnings = 1 ]] &&
124-
echo "skipping $func address at $hexaddr due to non-function symbol"
133+
echo "skipping $func address at $addr due to non-function symbol of type '$sym_type'"
125134
continue
126135
fi
127136

128137
# if the user provided a size, make sure it matches the symbol's size
129138
if [[ -n $size ]] && [[ $size -ne $sym_size ]]; then
130139
[[ $print_warnings = 1 ]] &&
131-
echo "skipping $func address at $hexaddr due to size mismatch ($size != $sym_size)"
140+
echo "skipping $func address at $addr due to size mismatch ($size != $sym_size)"
132141
continue;
133142
fi
134143

135144
# make sure the provided offset is within the symbol's range
136145
if [[ $offset -gt $sym_size ]]; then
137146
[[ $print_warnings = 1 ]] &&
138-
echo "skipping $func address at $hexaddr due to size mismatch ($offset > $sym_size)"
147+
echo "skipping $func address at $addr due to size mismatch ($offset > $sym_size)"
139148
continue
140149
fi
141150

142151
# separate multiple entries with a blank line
143152
[[ $FIRST = 0 ]] && echo
144153
FIRST=0
145154

146-
local hexsize=0x$(printf %x $sym_size)
147-
echo "$func+$offset/$hexsize:"
148-
addr2line -fpie $objfile $hexaddr | sed "s; $dir_prefix\(\./\)*; ;"
155+
# pass real address to addr2line
156+
echo "$func+$offset/$sym_size:"
157+
addr2line -fpie $objfile $addr | sed "s; $dir_prefix\(\./\)*; ;"
149158
DONE=1
150159

151-
done < <(readelf -sW $objfile | awk -v f=$func '$8 == f {print}')
160+
done < <(nm -n $objfile | awk -v fn=$func '$3 == fn { found=1; line=$0; start=$1; next } found == 1 { found=0; print line, $1 }')
152161
}
153162

154163
[[ $# -lt 2 ]] && usage

0 commit comments

Comments
 (0)