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