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