xref: /linux/arch/powerpc/tools/check-fpatchable-function-entry.sh (revision 2b8e3fac9bac1f2bb67571a00bb58851826fe705)
1*73cdf24eSHari Bathini#!/bin/bash
2*73cdf24eSHari Bathini# SPDX-License-Identifier: GPL-2.0
3*73cdf24eSHari Bathini
4*73cdf24eSHari Bathiniset -e
5*73cdf24eSHari Bathini
6*73cdf24eSHari Bathini# To debug, uncomment the following line
7*73cdf24eSHari Bathini# set -x
8*73cdf24eSHari Bathini
9*73cdf24eSHari Bathini# Output from -fpatchable-function-entry can only vary on ppc64 elfv2, so this
10*73cdf24eSHari Bathini# should not be invoked for other targets. Therefore we can pass in -m64 and
11*73cdf24eSHari Bathini# -mabi explicitly, to take care of toolchains defaulting to other targets.
12*73cdf24eSHari Bathini
13*73cdf24eSHari Bathini# Test whether the compile option -fpatchable-function-entry exists and
14*73cdf24eSHari Bathini# generates appropriate code
15*73cdf24eSHari Bathiniecho "int func() { return 0; }" | \
16*73cdf24eSHari Bathini    $* -m64 -mabi=elfv2 -S -x c -O2 -fpatchable-function-entry=2 - -o - 2> /dev/null | \
17*73cdf24eSHari Bathini    grep -q "__patchable_function_entries"
18*73cdf24eSHari Bathini
19*73cdf24eSHari Bathini# Test whether nops are generated after the local entry point
20*73cdf24eSHari Bathiniecho "int x; int func() { return x; }" | \
21*73cdf24eSHari Bathini    $* -m64 -mabi=elfv2 -S -x c -O2 -fpatchable-function-entry=2 - -o - 2> /dev/null | \
22*73cdf24eSHari Bathini    awk 'BEGIN { RS = ";" } /\.localentry.*nop.*\n[[:space:]]*nop/ { print $0 }' | \
23*73cdf24eSHari Bathini    grep -q "func:"
24*73cdf24eSHari Bathini
25*73cdf24eSHari Bathiniexit 0
26