#!/bin/bash
set -e
if [ "$V" = "1" ]; then
set -x
fi
if [ $# -lt 2 ]; then
echo "$0 [path to nm] [path to vmlinux]" 1>&2
exit 1
fi
nm="$1"
vmlinux="$2"
stext_addr=$($nm "$vmlinux" | grep -e " [TA] _stext$" | \
cut -d' ' -f1 | tr '[:lower:]' '[:upper:]')
ftrace_caller_addr=$($nm "$vmlinux" | grep -e " T ftrace_caller$" | \
cut -d' ' -f1 | tr '[:lower:]' '[:upper:]')
ftrace_tramp_addr=$($nm "$vmlinux" | grep -e " T ftrace_tramp_text$" | \
cut -d' ' -f1 | tr '[:lower:]' '[:upper:]')
ftrace_caller_offset=$(echo "ibase=16;$ftrace_caller_addr - $stext_addr" | bc)
ftrace_tramp_offset=$(echo "ibase=16;$ftrace_tramp_addr - $ftrace_caller_addr" | bc)
sz_32m=$(printf "%d" 0x2000000)
sz_64m=$(printf "%d" 0x4000000)
if [ "$ftrace_caller_offset" -ge "$sz_32m" ]; then
echo "ERROR: ftrace_caller (0x$ftrace_caller_addr) is beyond 32MiB of _stext" 1>&2
echo "ERROR: consider disabling CONFIG_FUNCTION_TRACER, or reducing the size \
of kernel text" 1>&2
exit 1
fi
if [ "$ftrace_tramp_offset" -ge "$sz_64m" ]; then
echo "ERROR: kernel text extends beyond 64MiB from ftrace_caller" 1>&2
echo "ERROR: consider disabling CONFIG_FUNCTION_TRACER, or reducing the size \
of kernel text" 1>&2
exit 1
fi