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