1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# An alternative's replacement code counts towards the checksum of the function 5# it belongs to. 6# 7# checksum_update_insn() walks insn->alts after hashing the instruction itself: 8# the alternative's type, and where the replacement forms a group, its feature 9# number and every instruction in it. So a patch which edits only the 10# replacement -- code that runs on some CPUs and not others -- still has to 11# move the function's checksum. 12# 13# If it does not, klp diff decides the function is unchanged and leaves it out. 14# The patch then ships the old replacement, and the bug is fixed only on 15# machines whose CPU takes the other arm. Which machines those are depends on 16# the feature bit, so the failure looks like a machine-specific bug rather than 17# a missing patch. 18# 19# insn->alts exists only after objtool's check pass, so the pair goes through 20# that first -- the compiler emits none of this structure itself. 21# 22# Covers the same ground as corpus/x86_64/checksum-alt-group, 23# checksum-alt-no-group and checksum-alt-recursion-guard in Joe Lawrence's 24# klp-build unit test corpus. 25 26. "$(dirname "$0")/../lib.sh" 27 28setup 29 30check() 31{ 32 build_pair checksum_alt.c "-D$1" 33 assert_input_section .altinstructions 34 run_objtool_check --mcount 35 run_checksum 36 37 assert_checksum_differs target 38} 39 40# The replacement instruction itself. 41check ALT_REPL 42# The feature number, with no instruction anywhere changed. 43check ALT_FEATURE 44 45pass "alternative replacement code counts towards the checksum" 46