xref: /linux/tools/objtool/tests/generic/test-static-call-new.sh (revision 5b6dca02b3e2254d2fd5706d76d7ab4610a67296)
1*938816b7SSong Liu#!/bin/bash
2*938816b7SSong Liu# SPDX-License-Identifier: GPL-2.0
3*938816b7SSong Liu#
4*938816b7SSong Liu# A patch may introduce a static call where the original function had none.
5*938816b7SSong Liu#
6*938816b7SSong Liu# The .static_call_sites entry is then new, with nothing in the original to
7*938816b7SSong Liu# correlate it against, so klp diff has to carry it into the patch from
8*938816b7SSong Liu# scratch.  Where the key lives still decides whether that is allowed: a
9*938816b7SSong Liu# vmlinux key is reachable, and a module-owned one is not, for the same reason
10*938816b7SSong Liu# an existing module key is not -- late module patching lets the livepatch load
11*938816b7SSong Liu# first, and the unresolved entry is dereferenced when the module arrives.
12*938816b7SSong Liu#
13*938816b7SSong Liu# Both halves are here because they fail in opposite directions.  Dropping the
14*938816b7SSong Liu# new entry leaves a static call the kernel never patches; accepting a new
15*938816b7SSong Liu# module-owned one is the corruption the check exists to prevent.
16*938816b7SSong Liu#
17*938816b7SSong Liu# Covers the same ground as corpus/x86_64/static-call-vmlinux-new and
18*938816b7SSong Liu# static-call-module-new in Joe Lawrence's klp-build unit test corpus.
19*938816b7SSong Liu
20*938816b7SSong Liu. "$(dirname "$0")/../lib.sh"
21*938816b7SSong Liu
22*938816b7SSong Liusetup
23*938816b7SSong Liubuild_pair static_call.c -DNEW_CALL
24*938816b7SSong Liu
25*938816b7SSong Liu# The premise: the original really has no static call, the patched one does.
26*938816b7SSong Liuhas_input_section orig.o .static_call_sites &&
27*938816b7SSong Liu	fail "fixture put a .static_call_sites in the original; nothing new to add"
28*938816b7SSong Liuhas_input_section patched.o .static_call_sites ||
29*938816b7SSong Liu	probe_skip "compiler produced no .static_call_sites on this arch"
30*938816b7SSong Liu
31*938816b7SSong Liurun_diff
32*938816b7SSong Liuassert_patched target
33*938816b7SSong Liuassert_section .static_call_sites
34*938816b7SSong Liuassert_reloc_sym .static_call_sites target
35*938816b7SSong Liu
36*938816b7SSong Liu# The same new call, with the key owned by a module: not reachable, so the
37*938816b7SSong Liu# build has to stop rather than emit a relocation nothing will resolve.
38*938816b7SSong Liurm -f "$workdir/out.o"
39*938816b7SSong Liubuild_pair static_call.c -DNEW_CALL -DMODNAME='"klp_testmod"'
40*938816b7SSong Liurun_diff 255
41*938816b7SSong Liuassert_diff_log 'unsupported static call key __SCK__klp_test_call'
42*938816b7SSong Liu[ -e "$workdir/out.o" ] &&
43*938816b7SSong Liu	fail "output object produced for a rejected input"
44*938816b7SSong Liu
45*938816b7SSong Liupass "static call introduced by the patch carried in, or rejected for a module key"
46