1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# What a function's checksum has to cover beyond its instruction bytes. 5# 6# checksum_update_insn() hashes the raw bytes, and then what any relocation on 7# the instruction refers to: a string section contributes the string's 8# contents, anything else the target symbol's name and the adjusted addend, 9# with a reference to a static resolved back through its section symbol first. 10# 11# None of these show up in the bytes. A rel32 operand is zero in the object 12# and supplied by the relocation, so every change below leaves the encoded 13# instruction byte-identical. A checksum stopping at the bytes reports the 14# function unchanged, klp diff omits it, and the patch silently does not 15# contain the fix. 16# 17# test-checksum-position is the other half of this: it covers what must *not* 18# change the checksum when a function merely moves. 19# 20# Covers the same ground as corpus/x86_64/checksum-reloc-sym, 21# checksum-pc-relative-addend, checksum-string-reloc and 22# checksum-sec-sym-resolve in Joe Lawrence's klp-build unit test corpus. 23 24. "$(dirname "$0")/../lib.sh" 25 26setup 27 28# check <flag> <what it changes> 29check() 30{ 31 build_pair checksum_insn.c "-D$1" 32 run_checksum 33 34 # The premise for all of them: the operand is a relocation, not bytes. 35 assert_checksum_differs target 36} 37 38check WHICH_CALL # relocation target name 39check STR_CONTENT # contents of a string the code passes 40check WHICH_SLOT # addend, same target symbol 41check WHICH_PRIV # addend via a static's section symbol 42 43# The converse: rebuilding identical source leaves it alone, so the above is 44# not just "any rebuild moves the checksum". 45build_pair checksum_insn.c 46run_checksum 47assert_checksum_matches target 48 49pass "instruction checksums cover reloc targets, addends and string contents" 50