1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4set -e
5set -o pipefail
6
7# To debug, uncomment the following line
8# set -x
9
10# -mprofile-kernel is only supported on 64-bit, so this should not be invoked
11# for 32-bit. We pass in -m64 explicitly, and -mbig-endian and -mlittle-endian
12# are passed in from Kconfig, which takes care of toolchains defaulting to
13# other targets.
14
15# Test whether the compile option -mprofile-kernel exists and generates
16# profiling code (ie. a call to _mcount()).
17echo "int func() { return 0; }" | \
18    $* -m64 -S -x c -O2 -p -mprofile-kernel - -o - \
19    2> /dev/null | grep -q "_mcount"
20
21# Test whether the notrace attribute correctly suppresses calls to _mcount().
22
23echo -e "#include <linux/compiler.h>\nnotrace int func() { return 0; }" | \
24    $* -m64 -S -x c -O2 -p -mprofile-kernel - -o - \
25    2> /dev/null | grep -q "_mcount" && \
26    exit 1
27
28exit 0
29