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