1b71c9ffbSNicholas Piggin#!/bin/bash
2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
3b71c9ffbSNicholas Piggin
4b71c9ffbSNicholas Pigginset -e
5b71c9ffbSNicholas Pigginset -o pipefail
6b71c9ffbSNicholas Piggin
7b71c9ffbSNicholas Piggin# To debug, uncomment the following line
8b71c9ffbSNicholas Piggin# set -x
9b71c9ffbSNicholas Piggin
101421dc6dSNicholas Piggin# -mprofile-kernel is only supported on 64le, so this should not be invoked
111421dc6dSNicholas Piggin# for other targets. Therefore we can pass in -m64 and -mlittle-endian
121421dc6dSNicholas Piggin# explicitly, to take care of toolchains defaulting to other targets.
131421dc6dSNicholas Piggin
14b71c9ffbSNicholas Piggin# Test whether the compile option -mprofile-kernel exists and generates
15b71c9ffbSNicholas Piggin# profiling code (ie. a call to _mcount()).
16b71c9ffbSNicholas Pigginecho "int func() { return 0; }" | \
171421dc6dSNicholas Piggin    $* -m64 -mlittle-endian -S -x c -O2 -p -mprofile-kernel - -o - \
181421dc6dSNicholas Piggin    2> /dev/null | grep -q "_mcount"
19b71c9ffbSNicholas Piggin
20b71c9ffbSNicholas Piggin# Test whether the notrace attribute correctly suppresses calls to _mcount().
21b71c9ffbSNicholas Piggin
22b71c9ffbSNicholas Pigginecho -e "#include <linux/compiler.h>\nnotrace int func() { return 0; }" | \
231421dc6dSNicholas Piggin    $* -m64 -mlittle-endian -S -x c -O2 -p -mprofile-kernel - -o - \
241421dc6dSNicholas Piggin    2> /dev/null | grep -q "_mcount" && \
25b71c9ffbSNicholas Piggin    exit 1
26b71c9ffbSNicholas Piggin
27b71c9ffbSNicholas Pigginecho "OK"
28b71c9ffbSNicholas Pigginexit 0
29