1*782f46cbSNaveen N Rao#!/bin/bash 2*782f46cbSNaveen N Rao# SPDX-License-Identifier: GPL-2.0-or-later 3*782f46cbSNaveen N Rao# 4*782f46cbSNaveen N Rao# This script checks vmlinux to ensure that all functions can call ftrace_caller() either directly, 5*782f46cbSNaveen N Rao# or through the stub, ftrace_tramp_text, at the end of kernel text. 6*782f46cbSNaveen N Rao 7*782f46cbSNaveen N Rao# Error out if any command fails 8*782f46cbSNaveen N Raoset -e 9*782f46cbSNaveen N Rao 10*782f46cbSNaveen N Rao# Allow for verbose output 11*782f46cbSNaveen N Raoif [ "$V" = "1" ]; then 12*782f46cbSNaveen N Rao set -x 13*782f46cbSNaveen N Raofi 14*782f46cbSNaveen N Rao 15*782f46cbSNaveen N Raoif [ $# -lt 2 ]; then 16*782f46cbSNaveen N Rao echo "$0 [path to nm] [path to vmlinux]" 1>&2 17*782f46cbSNaveen N Rao exit 1 18*782f46cbSNaveen N Raofi 19*782f46cbSNaveen N Rao 20*782f46cbSNaveen N Rao# Have Kbuild supply the path to nm so we handle cross compilation. 21*782f46cbSNaveen N Raonm="$1" 22*782f46cbSNaveen N Raovmlinux="$2" 23*782f46cbSNaveen N Rao 24*782f46cbSNaveen N Raostext_addr=$($nm "$vmlinux" | grep -e " [TA] _stext$" | \ 25*782f46cbSNaveen N Rao cut -d' ' -f1 | tr '[:lower:]' '[:upper:]') 26*782f46cbSNaveen N Raoftrace_caller_addr=$($nm "$vmlinux" | grep -e " T ftrace_caller$" | \ 27*782f46cbSNaveen N Rao cut -d' ' -f1 | tr '[:lower:]' '[:upper:]') 28*782f46cbSNaveen N Raoftrace_tramp_addr=$($nm "$vmlinux" | grep -e " T ftrace_tramp_text$" | \ 29*782f46cbSNaveen N Rao cut -d' ' -f1 | tr '[:lower:]' '[:upper:]') 30*782f46cbSNaveen N Rao 31*782f46cbSNaveen N Raoftrace_caller_offset=$(echo "ibase=16;$ftrace_caller_addr - $stext_addr" | bc) 32*782f46cbSNaveen N Raoftrace_tramp_offset=$(echo "ibase=16;$ftrace_tramp_addr - $ftrace_caller_addr" | bc) 33*782f46cbSNaveen N Raosz_32m=$(printf "%d" 0x2000000) 34*782f46cbSNaveen N Raosz_64m=$(printf "%d" 0x4000000) 35*782f46cbSNaveen N Rao 36*782f46cbSNaveen N Rao# ftrace_caller - _stext < 32M 37*782f46cbSNaveen N Raoif [ "$ftrace_caller_offset" -ge "$sz_32m" ]; then 38*782f46cbSNaveen N Rao echo "ERROR: ftrace_caller (0x$ftrace_caller_addr) is beyond 32MiB of _stext" 1>&2 39*782f46cbSNaveen N Rao echo "ERROR: consider disabling CONFIG_FUNCTION_TRACER, or reducing the size \ 40*782f46cbSNaveen N Rao of kernel text" 1>&2 41*782f46cbSNaveen N Rao exit 1 42*782f46cbSNaveen N Raofi 43*782f46cbSNaveen N Rao 44*782f46cbSNaveen N Rao# ftrace_tramp_text - ftrace_caller < 64M 45*782f46cbSNaveen N Raoif [ "$ftrace_tramp_offset" -ge "$sz_64m" ]; then 46*782f46cbSNaveen N Rao echo "ERROR: kernel text extends beyond 64MiB from ftrace_caller" 1>&2 47*782f46cbSNaveen N Rao echo "ERROR: consider disabling CONFIG_FUNCTION_TRACER, or reducing the size \ 48*782f46cbSNaveen N Rao of kernel text" 1>&2 49*782f46cbSNaveen N Rao exit 1 50*782f46cbSNaveen N Raofi 51