xref: /linux/arch/powerpc/tools/gcc-check-mprofile-kernel.sh (revision d30c1683aaecb93d2ab95685dc4300a33d3cea7a)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4set -e
5
6# To debug, uncomment the following line
7# set -x
8
9# -mprofile-kernel is only supported on 64-bit with ELFv2, so this should not
10# be invoked for other targets. Therefore we can pass in -m64 and -mabi
11# explicitly, to take care of toolchains defaulting to other targets.
12
13# Test whether the compile option -mprofile-kernel exists and generates
14# profiling code (ie. a call to _mcount()).
15echo "int func() { return 0; }" | \
16    $* -m64 -mabi=elfv2 -S -x c -O2 -p -mprofile-kernel - -o - \
17    2> /dev/null | grep -q "_mcount"
18
19# Test whether the notrace attribute correctly suppresses calls to _mcount().
20
21echo -e "#include <linux/compiler.h>\nnotrace int func() { return 0; }" | \
22    $* -m64 -mabi=elfv2 -S -x c -O2 -p -mprofile-kernel - -o - \
23    2> /dev/null | grep -q "_mcount" && \
24    exit 1
25
26exit 0
27