Commit 39cf650d authored by Brian Johannesmeyer's avatar Brian Johannesmeyer Committed by Josh Poimboeuf

scripts/faddr2line: Reduce number of readelf calls to three

Rather than calling readelf several times for each invocation of
__faddr2line, call readelf only three times at the beginning, and save its
result for future use.
Signed-off-by: default avatarBrian Johannesmeyer <bjohannesmeyer@gmail.com>
Link: https://lore.kernel.org/r/20240415145538.1938745-2-bjohannesmeyer@gmail.comSigned-off-by: default avatarJosh Poimboeuf <jpoimboe@kernel.org>
parent 22a40d14
...@@ -87,7 +87,7 @@ command -v ${ADDR2LINE} >/dev/null 2>&1 || die "${ADDR2LINE} isn't installed" ...@@ -87,7 +87,7 @@ command -v ${ADDR2LINE} >/dev/null 2>&1 || die "${ADDR2LINE} isn't installed"
find_dir_prefix() { find_dir_prefix() {
local objfile=$1 local objfile=$1
local start_kernel_addr=$(${READELF} --symbols --wide $objfile | sed 's/\[.*\]//' | local start_kernel_addr=$(echo "${ELF_SYMS}" | sed 's/\[.*\]//' |
${AWK} '$8 == "start_kernel" {printf "0x%s", $2}') ${AWK} '$8 == "start_kernel" {printf "0x%s", $2}')
[[ -z $start_kernel_addr ]] && return [[ -z $start_kernel_addr ]] && return
...@@ -103,6 +103,14 @@ find_dir_prefix() { ...@@ -103,6 +103,14 @@ find_dir_prefix() {
return 0 return 0
} }
run_readelf() {
local objfile=$1
ELF_FILEHEADER=$(${READELF} --file-header $objfile)
ELF_SECHEADERS=$(${READELF} --section-headers --wide $objfile)
ELF_SYMS=$(${READELF} --symbols --wide $objfile)
}
__faddr2line() { __faddr2line() {
local objfile=$1 local objfile=$1
local func_addr=$2 local func_addr=$2
...@@ -125,7 +133,7 @@ __faddr2line() { ...@@ -125,7 +133,7 @@ __faddr2line() {
# vmlinux uses absolute addresses in the section table rather than # vmlinux uses absolute addresses in the section table rather than
# section offsets. # section offsets.
local file_type=$(${READELF} --file-header $objfile | local file_type=$(echo "${ELF_FILEHEADER}" |
${AWK} '$1 == "Type:" { print $2; exit }') ${AWK} '$1 == "Type:" { print $2; exit }')
if [[ $file_type = "EXEC" ]] || [[ $file_type == "DYN" ]]; then if [[ $file_type = "EXEC" ]] || [[ $file_type == "DYN" ]]; then
is_vmlinux=1 is_vmlinux=1
...@@ -143,8 +151,7 @@ __faddr2line() { ...@@ -143,8 +151,7 @@ __faddr2line() {
local sec_name local sec_name
# Get the section size: # Get the section size:
sec_size=$(${READELF} --section-headers --wide $objfile | sec_size=$(echo "${ELF_SECHEADERS}" | sed 's/\[ /\[/' |
sed 's/\[ /\[/' |
${AWK} -v sec=$sym_sec '$1 == "[" sec "]" { print "0x" $6; exit }') ${AWK} -v sec=$sym_sec '$1 == "[" sec "]" { print "0x" $6; exit }')
if [[ -z $sec_size ]]; then if [[ -z $sec_size ]]; then
...@@ -154,8 +161,7 @@ __faddr2line() { ...@@ -154,8 +161,7 @@ __faddr2line() {
fi fi
# Get the section name: # Get the section name:
sec_name=$(${READELF} --section-headers --wide $objfile | sec_name=$(echo "${ELF_SECHEADERS}" | sed 's/\[ /\[/' |
sed 's/\[ /\[/' |
${AWK} -v sec=$sym_sec '$1 == "[" sec "]" { print $2; exit }') ${AWK} -v sec=$sym_sec '$1 == "[" sec "]" { print $2; exit }')
if [[ -z $sec_name ]]; then if [[ -z $sec_name ]]; then
...@@ -197,7 +203,7 @@ __faddr2line() { ...@@ -197,7 +203,7 @@ __faddr2line() {
found=2 found=2
break break
fi fi
done < <(${READELF} --symbols --wide $objfile | sed 's/\[.*\]//' | ${AWK} -v sec=$sym_sec '$7 == sec' | sort --key=2) done < <(echo "${ELF_SYMS}" | sed 's/\[.*\]//' | ${AWK} -v sec=$sym_sec '$7 == sec' | sort --key=2)
if [[ $found = 0 ]]; then if [[ $found = 0 ]]; then
warn "can't find symbol: sym_name: $sym_name sym_sec: $sym_sec sym_addr: $sym_addr sym_elf_size: $sym_elf_size" warn "can't find symbol: sym_name: $sym_name sym_sec: $sym_sec sym_addr: $sym_addr sym_elf_size: $sym_elf_size"
...@@ -278,7 +284,7 @@ __faddr2line() { ...@@ -278,7 +284,7 @@ __faddr2line() {
DONE=1 DONE=1
done < <(${READELF} --symbols --wide $objfile | sed 's/\[.*\]//' | ${AWK} -v fn=$sym_name '$8 == fn') done < <(echo "${ELF_SYMS}" | sed 's/\[.*\]//' | ${AWK} -v fn=$sym_name '$8 == fn')
} }
[[ $# -lt 2 ]] && usage [[ $# -lt 2 ]] && usage
...@@ -291,7 +297,9 @@ LIST=0 ...@@ -291,7 +297,9 @@ LIST=0
[[ ! -f $objfile ]] && die "can't find objfile $objfile" [[ ! -f $objfile ]] && die "can't find objfile $objfile"
shift shift
${READELF} --section-headers --wide $objfile | ${GREP} -q '\.debug_info' || die "CONFIG_DEBUG_INFO not enabled" run_readelf $objfile
echo "${ELF_SECHEADERS}" | ${GREP} -q '\.debug_info' || die "CONFIG_DEBUG_INFO not enabled"
DIR_PREFIX=supercalifragilisticexpialidocious DIR_PREFIX=supercalifragilisticexpialidocious
find_dir_prefix $objfile find_dir_prefix $objfile
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment