xref: /linux/tools/objtool/tests/generic/test-cold-function.sh (revision 5b6dca02b3e2254d2fd5706d76d7ab4610a67296)
1*76e7630dSPuranjay Mohan#!/bin/bash
2*76e7630dSPuranjay Mohan# SPDX-License-Identifier: GPL-2.0
3*76e7630dSPuranjay Mohan#
4*76e7630dSPuranjay Mohan# Both halves of a split function belong to the patch; carrying only the hot
5*76e7630dSPuranjay Mohan# part leaves the cold path branching into unpatched code.
6*76e7630dSPuranjay Mohan
7*76e7630dSPuranjay Mohan. "$(dirname "$0")/../lib.sh"
8*76e7630dSPuranjay Mohan
9*76e7630dSPuranjay Mohan# Clang does not split functions into a cold part at all, so there is nothing
10*76e7630dSPuranjay Mohan# for this test to look at there.  A given gcc may or may not split, which is a
11*76e7630dSPuranjay Mohan# version property rather than a compiler choice -- that stays a probe below.
12*76e7630dSPuranjay Mohangcc_only "clang does not split functions into a cold part"
13*76e7630dSPuranjay Mohan
14*76e7630dSPuranjay Mohansetup
15*76e7630dSPuranjay Mohan
16*76e7630dSPuranjay Mohansplit_flag=-freorder-blocks-and-partition
17*76e7630dSPuranjay Mohancc_supports "$split_flag" || split_flag=
18*76e7630dSPuranjay Mohan
19*76e7630dSPuranjay Mohanbuild_pair cold_function.c $split_flag
20*76e7630dSPuranjay Mohan
21*76e7630dSPuranjay Mohan# Find what the compiler called the cold half -- target.cold, target.cold.0,
22*76e7630dSPuranjay Mohan# depending on version -- and name it exactly from here on.
23*76e7630dSPuranjay Mohancold_sym="$(in_symbols orig.o | awk '$NF ~ /^target\.cold/ { print $NF; exit }')"
24*76e7630dSPuranjay Mohan[ -n "$cold_sym" ] ||
25*76e7630dSPuranjay Mohan	probe_skip "compiler did not split the function into a cold part"
26*76e7630dSPuranjay Mohan
27*76e7630dSPuranjay Mohanrun_diff
28*76e7630dSPuranjay Mohan
29*76e7630dSPuranjay Mohanassert_patched target
30*76e7630dSPuranjay Mohan# Match the name field exactly, and require it to be defined.  Had the cold
31*76e7630dSPuranjay Mohan# half been left behind, the branch to it would appear as an undefined
32*76e7630dSPuranjay Mohan# .klp.sym.vmlinux.target.cold,0 -- a different name, which happens to contain
33*76e7630dSPuranjay Mohan# this one.  Asking about a column instead of the name would not tell them
34*76e7630dSPuranjay Mohan# apart: readelf prints SHN_LIVEPATCH as "OS [0xff20]" and llvm-readelf as
35*76e7630dSPuranjay Mohan# "OS[0xff20]", so the fields either side of the name shift between the two.
36*76e7630dSPuranjay Mohanout_symbols | awk -v n="$cold_sym" '$NF == n && $(NF - 1) != "UND"' | grep -q . ||
37*76e7630dSPuranjay Mohan	fail "cold half ($cold_sym) was not carried into the patch"
38*76e7630dSPuranjay Mohan
39*76e7630dSPuranjay Mohanpass "cold half carried into the patch with its parent"
40