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