xref: /linux/tools/objtool/tests/generic/test-klp-funcs-content.sh (revision 12d5fc96ebbb3b948861805b32a4c3a96105ccd9)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# .init.klp_funcs is the list the kernel walks to decide what to patch, and
5# .init.klp_objects points at it.  Existing tests assert only that the sections
6# exist, which they do whether the list names the right functions, the wrong
7# ones, or none at all -- and a patch module with an empty function list loads
8# perfectly happily and patches nothing.
9#
10# Each entry pairs a name string in .rodata.klp.str1.1 with a relocation to the
11# new function, so both halves are checkable.
12
13. "$(dirname "$0")/../lib.sh"
14
15setup
16build_pair klp_funcs.c
17run_diff
18
19assert_section .init.klp_funcs
20assert_section .init.klp_objects
21
22# Two functions changed, so two entries, each contributing a name relocation
23# and a function relocation.
24assert_reloc_count .init.klp_funcs 4
25
26# The functions that changed are named ...
27assert_reloc_sym .init.klp_funcs first
28assert_reloc_sym .init.klp_funcs second
29# ... and the one that did not is absent, from the list and from the patch.
30assert_no_reloc_sym .init.klp_funcs third
31assert_not_patched third
32
33# The names the kernel matches on are real strings, not just relocations.
34# readelf prints one per line as "[ offset]  <string>", so compare the whole
35# name: a word-boundary match would also accept ".text.first", since a dot is
36# not a word character.
37for name in first second; do
38	out_strings .rodata.klp.str1.1 | awk -v n="$name" '$NF == n' | grep -q . ||
39		fail "no '$name' string in .rodata.klp.str1.1"
40done
41
42# The object list has to reach the function list, or nothing is walked.
43assert_reloc_sym .init.klp_objects .init.klp_funcs
44
45pass "klp_funcs lists exactly the changed functions, by name and relocation"
46