xref: /linux/tools/objtool/tests/generic/test-jump-label-new-key.sh (revision 5b6dca02b3e2254d2fd5706d76d7ab4610a67296)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# A patch may introduce a static branch where the original function had none.
5#
6# That is not the same case as patching a function which already has one.  The
7# __jump_table entry is itself new, so there is no counterpart in the original
8# to correlate it against: klp diff has to carry the entry and the key into the
9# patch from scratch, and the key has to be reached the way any other reference
10# to a vmlinux symbol is.
11#
12# Get it wrong and the entry is dropped, leaving a static branch the kernel
13# never patches -- the code takes the wrong arm forever, silently.
14#
15# Where the key lives still decides whether that is allowed, exactly as it does
16# for a key the original already had: a module-owned one cannot be reached, so
17# introducing one has to stop the build rather than emit an entry nothing will
18# resolve.
19#
20# Covers the same ground as corpus/x86_64/static-branch-vmlinux-new and
21# static-branch-module-new in Joe Lawrence's klp-build unit test corpus.
22
23. "$(dirname "$0")/../lib.sh"
24
25setup klp_test_key
26build_pair jump_label.c -DNEW_KEY
27
28# The premise: the original really has no jump table, and the patched one does.
29has_input_section orig.o __jump_table &&
30	fail "fixture put a __jump_table in the original; nothing new to add"
31has_input_section patched.o __jump_table ||
32	probe_skip "compiler produced no __jump_table on this arch"
33
34run_diff
35
36assert_patched target
37assert_section __jump_table
38assert_reloc_sym __jump_table target
39
40# The same new branch, with the key owned by a module.  Drop the vmlinux export
41# first: while it is exported the key is reachable and being new changes
42# nothing, which is what the first version of this got wrong.
43export_syms
44rm -f "$workdir/out.o"
45build_pair jump_label.c -DNEW_KEY -DMODNAME='"klp_testmod"'
46run_diff 255
47assert_diff_log 'unsupported static branch key klp_test_key'
48[ -e "$workdir/out.o" ] &&
49	fail "output object produced for a rejected input"
50
51pass "static branch introduced by the patch carried in, or rejected for a module key"
52