summaryrefslogtreecommitdiff
path: root/tools/objtool/tests/generic/test-checksum-insn.sh
blob: e1c04a1f518a4b6011456bffa71a21ef9946574b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# What a function's checksum has to cover beyond its instruction bytes.
#
# checksum_update_insn() hashes the raw bytes, and then what any relocation on
# the instruction refers to: a string section contributes the string's
# contents, anything else the target symbol's name and the adjusted addend,
# with a reference to a static resolved back through its section symbol first.
#
# None of these show up in the bytes.  A rel32 operand is zero in the object
# and supplied by the relocation, so every change below leaves the encoded
# instruction byte-identical.  A checksum stopping at the bytes reports the
# function unchanged, klp diff omits it, and the patch silently does not
# contain the fix.
#
# test-checksum-position is the other half of this: it covers what must *not*
# change the checksum when a function merely moves.
#
# Covers the same ground as corpus/x86_64/checksum-reloc-sym,
# checksum-pc-relative-addend, checksum-string-reloc and
# checksum-sec-sym-resolve in Joe Lawrence's klp-build unit test corpus.

. "$(dirname "$0")/../lib.sh"

setup

# check <flag> <what it changes>
check()
{
	build_pair checksum_insn.c "-D$1"
	run_checksum

	# The premise for all of them: the operand is a relocation, not bytes.
	assert_checksum_differs target
}

check WHICH_CALL    # relocation target name
check STR_CONTENT   # contents of a string the code passes
check WHICH_SLOT    # addend, same target symbol
check WHICH_PRIV    # addend via a static's section symbol

# The converse: rebuilding identical source leaves it alone, so the above is
# not just "any rebuild moves the checksum".
build_pair checksum_insn.c
run_checksum
assert_checksum_matches target

pass "instruction checksums cover reloc targets, addends and string contents"