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