Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 2c80918

Browse files
bjohannesmeyerjpoimboe
authored andcommitted
scripts/faddr2line: Check vmlinux only once
Rather than checking whether the object file is vmlinux for each invocation of __faddr2line, check it only once beforehand. Signed-off-by: Brian Johannesmeyer <bjohannesmeyer@gmail.com> Link: https://lore.kernel.org/r/20240415145538.1938745-4-bjohannesmeyer@gmail.com Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
1 parent b8d9d94 commit 2c80918

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

scripts/faddr2line

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ run_readelf() {
115115
ELF_SYMS=$(echo "${out}" | sed -n '/Symbol table .* contains [0-9]* entries:/,$p')
116116
}
117117

118+
check_vmlinux() {
119+
# vmlinux uses absolute addresses in the section table rather than
120+
# section offsets.
121+
IS_VMLINUX=0
122+
local file_type=$(echo "${ELF_FILEHEADER}" |
123+
${AWK} '$1 == "Type:" { print $2; exit }')
124+
if [[ $file_type = "EXEC" ]] || [[ $file_type == "DYN" ]]; then
125+
IS_VMLINUX=1
126+
fi
127+
}
128+
118129
__faddr2line() {
119130
local objfile=$1
120131
local func_addr=$2
@@ -125,8 +136,6 @@ __faddr2line() {
125136
local func_offset=${func_addr#*+}
126137
func_offset=${func_offset%/*}
127138
local user_size=
128-
local file_type
129-
local is_vmlinux=0
130139
[[ $func_addr =~ "/" ]] && user_size=${func_addr#*/}
131140

132141
if [[ -z $sym_name ]] || [[ -z $func_offset ]] || [[ $sym_name = $func_addr ]]; then
@@ -135,14 +144,6 @@ __faddr2line() {
135144
return
136145
fi
137146

138-
# vmlinux uses absolute addresses in the section table rather than
139-
# section offsets.
140-
local file_type=$(echo "${ELF_FILEHEADER}" |
141-
${AWK} '$1 == "Type:" { print $2; exit }')
142-
if [[ $file_type = "EXEC" ]] || [[ $file_type == "DYN" ]]; then
143-
is_vmlinux=1
144-
fi
145-
146147
# Go through each of the object's symbols which match the func name.
147148
# In rare cases there might be duplicates, in which case we print all
148149
# matches.
@@ -260,7 +261,7 @@ __faddr2line() {
260261
# Pass section address to addr2line and strip absolute paths
261262
# from the output:
262263
local args="--functions --pretty-print --inlines --exe=$objfile"
263-
[[ $is_vmlinux = 0 ]] && args="$args --section=$sec_name"
264+
[[ $IS_VMLINUX = 0 ]] && args="$args --section=$sec_name"
264265
local output=$(${ADDR2LINE} $args $addr | sed "s; $dir_prefix\(\./\)*; ;")
265266
[[ -z $output ]] && continue
266267

@@ -305,6 +306,8 @@ run_readelf $objfile
305306

306307
echo "${ELF_SECHEADERS}" | ${GREP} -q '\.debug_info' || die "CONFIG_DEBUG_INFO not enabled"
307308

309+
check_vmlinux
310+
308311
DIR_PREFIX=supercalifragilisticexpialidocious
309312
find_dir_prefix $objfile
310313

0 commit comments

Comments
 (0)