162306a36Sopenharmony_ci#!/bin/bash
262306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
362306a36Sopenharmony_ci
462306a36Sopenharmony_ciset -e
562306a36Sopenharmony_ciset -o pipefail
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci# To debug, uncomment the following line
862306a36Sopenharmony_ci# set -x
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci# -mprofile-kernel is only supported on 64-bit, so this should not be invoked
1162306a36Sopenharmony_ci# for 32-bit. We pass in -m64 explicitly, and -mbig-endian and -mlittle-endian
1262306a36Sopenharmony_ci# are passed in from Kconfig, which takes care of toolchains defaulting to
1362306a36Sopenharmony_ci# other targets.
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci# Test whether the compile option -mprofile-kernel exists and generates
1662306a36Sopenharmony_ci# profiling code (ie. a call to _mcount()).
1762306a36Sopenharmony_ciecho "int func() { return 0; }" | \
1862306a36Sopenharmony_ci    $* -m64 -S -x c -O2 -p -mprofile-kernel - -o - \
1962306a36Sopenharmony_ci    2> /dev/null | grep -q "_mcount"
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci# Test whether the notrace attribute correctly suppresses calls to _mcount().
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ciecho -e "#include <linux/compiler.h>\nnotrace int func() { return 0; }" | \
2462306a36Sopenharmony_ci    $* -m64 -S -x c -O2 -p -mprofile-kernel - -o - \
2562306a36Sopenharmony_ci    2> /dev/null | grep -q "_mcount" && \
2662306a36Sopenharmony_ci    exit 1
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ciexit 0
29