Skip to content

Commit 95a8798

Browse files
LiucInteltorvalds
authored andcommittedNov 30, 2017
scripts/faddr2line: extend usage on generic arch
When cross-compiling, fadd2line should use the binary tool used for the target system, rather than that of the host. Link: http://lkml.kernel.org/r/20171121092911.GA150711@sofia Signed-off-by: Liu Changcheng <[email protected]> Cc: Kate Stewart <[email protected]> Cc: NeilBrown <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 5c9d2d5 commit 95a8798

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed
 

‎scripts/faddr2line

+14-7
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,16 @@
4444
set -o errexit
4545
set -o nounset
4646

47+
READELF="${CROSS_COMPILE}readelf"
48+
ADDR2LINE="${CROSS_COMPILE}addr2line"
49+
SIZE="${CROSS_COMPILE}size"
50+
NM="${CROSS_COMPILE}nm"
51+
4752
command -v awk >/dev/null 2>&1 || die "awk isn't installed"
48-
command -v readelf >/dev/null 2>&1 || die "readelf isn't installed"
49-
command -v addr2line >/dev/null 2>&1 || die "addr2line isn't installed"
53+
command -v ${READELF} >/dev/null 2>&1 || die "readelf isn't installed"
54+
command -v ${ADDR2LINE} >/dev/null 2>&1 || die "addr2line isn't installed"
55+
command -v ${SIZE} >/dev/null 2>&1 || die "size isn't installed"
56+
command -v ${NM} >/dev/null 2>&1 || die "nm isn't installed"
5057

5158
usage() {
5259
echo "usage: faddr2line <object file> <func+offset> <func+offset>..." >&2
@@ -69,10 +76,10 @@ die() {
6976
find_dir_prefix() {
7077
local objfile=$1
7178

72-
local start_kernel_addr=$(readelf -sW $objfile | awk '$8 == "start_kernel" {printf "0x%s", $2}')
79+
local start_kernel_addr=$(${READELF} -sW $objfile | awk '$8 == "start_kernel" {printf "0x%s", $2}')
7380
[[ -z $start_kernel_addr ]] && return
7481

75-
local file_line=$(addr2line -e $objfile $start_kernel_addr)
82+
local file_line=$(${ADDR2LINE} -e $objfile $start_kernel_addr)
7683
[[ -z $file_line ]] && return
7784

7885
local prefix=${file_line%init/main.c:*}
@@ -104,7 +111,7 @@ __faddr2line() {
104111

105112
# Go through each of the object's symbols which match the func name.
106113
# In rare cases there might be duplicates.
107-
file_end=$(size -Ax $objfile | awk '$1 == ".text" {print $2}')
114+
file_end=$(${SIZE} -Ax $objfile | awk '$1 == ".text" {print $2}')
108115
while read symbol; do
109116
local fields=($symbol)
110117
local sym_base=0x${fields[0]}
@@ -156,10 +163,10 @@ __faddr2line() {
156163

157164
# pass real address to addr2line
158165
echo "$func+$offset/$sym_size:"
159-
addr2line -fpie $objfile $addr | sed "s; $dir_prefix\(\./\)*; ;"
166+
${ADDR2LINE} -fpie $objfile $addr | sed "s; $dir_prefix\(\./\)*; ;"
160167
DONE=1
161168

162-
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; }')
169+
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; }')
163170
}
164171

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

0 commit comments

Comments
 (0)
Please sign in to comment.