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

Commit b8d9d94

Browse files
bjohannesmeyerjpoimboe
authored andcommitted
scripts/faddr2line: Combine three readelf calls into one
Rather than calling readelf three separate times to collect three different types of info, call it only once, and parse out the different types of info from its output. Signed-off-by: Brian Johannesmeyer <bjohannesmeyer@gmail.com> Link: https://lore.kernel.org/r/20240415145538.1938745-3-bjohannesmeyer@gmail.com Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
1 parent 39cf650 commit b8d9d94

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

scripts/faddr2line

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,14 @@ find_dir_prefix() {
105105

106106
run_readelf() {
107107
local objfile=$1
108-
109-
ELF_FILEHEADER=$(${READELF} --file-header $objfile)
110-
ELF_SECHEADERS=$(${READELF} --section-headers --wide $objfile)
111-
ELF_SYMS=$(${READELF} --symbols --wide $objfile)
108+
local out=$(${READELF} --file-header --section-headers --symbols --wide $objfile)
109+
110+
# This assumes that readelf first prints the file header, then the section headers, then the symbols.
111+
# Note: It seems that GNU readelf does not prefix section headers with the "There are X section headers"
112+
# line when multiple options are given, so let's also match with the "Section Headers:" line.
113+
ELF_FILEHEADER=$(echo "${out}" | sed -n '/There are [0-9]* section headers, starting at offset\|Section Headers:/q;p')
114+
ELF_SECHEADERS=$(echo "${out}" | sed -n '/There are [0-9]* section headers, starting at offset\|Section Headers:/,$p' | sed -n '/Symbol table .* contains [0-9]* entries:/q;p')
115+
ELF_SYMS=$(echo "${out}" | sed -n '/Symbol table .* contains [0-9]* entries:/,$p')
112116
}
113117

114118
__faddr2line() {

0 commit comments

Comments
 (0)