xref: /linux/tools/objtool/tests/generic/test-checksum-debug.sh (revision ade23d75deb3c679760c3f0f33d9b8d8ffa9f963)
1*ade23d75SSong Liu#!/bin/bash
2*ade23d75SSong Liu# SPDX-License-Identifier: GPL-2.0
3*ade23d75SSong Liu#
4*ade23d75SSong Liu# "klp checksum --debug-checksum" prints a per-instruction checksum stream,
5*ade23d75SSong Liu# and klp-build -f (--show-first-changed) parses it to report where a function
6*ade23d75SSong Liu# first differs between the original and patched builds.
7*ade23d75SSong Liu#
8*ade23d75SSong Liu# It is a debugging aid, so nothing fails when it breaks: klp-build greps the
9*ade23d75SSong Liu# stream, and an unmatched grep just yields no output, which reads as "no
10*ade23d75SSong Liu# instruction changed".  That is exactly how the format drifted out from under
11*ade23d75SSong Liu# it once already.  Pin the shape klp-build depends on:
12*ade23d75SSong Liu#
13*ade23d75SSong Liu#   DEBUG: <object>: checksum: <func>(): <sym>+0x<offset> <16 hex digits>
14*ade23d75SSong Liu#
15*ade23d75SSong Liu# and that --dry-run leaves the object alone, since klp-build runs this against
16*ade23d75SSong Liu# objects it is going to checksum again for real.
17*ade23d75SSong Liu
18*ade23d75SSong Liu. "$(dirname "$0")/../lib.sh"
19*ade23d75SSong Liu
20*ade23d75SSong Liusetup
21*ade23d75SSong Liubuild_pair basic.c
22*ade23d75SSong Liu
23*ade23d75SSong Liubefore="$(md5sum < "$workdir/orig.o")"
24*ade23d75SSong Liu
25*ade23d75SSong Liu"$OBJTOOL" klp checksum --dry-run --debug-checksum=changed \
26*ade23d75SSong Liu	"$workdir/orig.o" > "$workdir/debug.log" 2>&1 ||
27*ade23d75SSong Liu	fail "klp checksum --debug-checksum failed"
28*ade23d75SSong Liu
29*ade23d75SSong Liu# --dry-run has to mean it: klp-build checksums these objects again afterwards,
30*ade23d75SSong Liu# and "already has .discard.sym_checksum, skipping" would lose the real run.
31*ade23d75SSong Liu[ "$(md5sum < "$workdir/orig.o")" = "$before" ] ||
32*ade23d75SSong Liu	fail "--dry-run modified the object"
33*ade23d75SSong Liuhas_input_section orig.o .discard.sym_checksum &&
34*ade23d75SSong Liu	fail "--dry-run created .discard.sym_checksum"
35*ade23d75SSong Liu
36*ade23d75SSong Liugrep -qE '^DEBUG: .*: checksum: changed\(\): [^ ]+\+0x[0-9a-f]+ [0-9a-f]{16}$' \
37*ade23d75SSong Liu	"$workdir/debug.log" ||
38*ade23d75SSong Liu	fail "unexpected --debug-checksum format: $(head -1 "$workdir/debug.log")"
39*ade23d75SSong Liu
40*ade23d75SSong Liu# This is the pattern klp-build greps with.  Keep it working verbatim.
41*ade23d75SSong Liugrep -qE "^DEBUG: .*checksum: changed\(\): " "$workdir/debug.log" ||
42*ade23d75SSong Liu	fail "klp-build's --show-first-changed pattern no longer matches"
43*ade23d75SSong Liu
44*ade23d75SSong Liu# Only the requested function, or klp-build attributes instructions to the
45*ade23d75SSong Liu# wrong one.
46*ade23d75SSong Liugrep -qE 'checksum: untouched\(\)' "$workdir/debug.log" &&
47*ade23d75SSong Liu	fail "--debug-checksum=changed also dumped untouched()"
48*ade23d75SSong Liu
49*ade23d75SSong Liupass "--debug-checksum format is the one klp-build -f parses"
50