xref: /linux/tools/objtool/tests/generic/test-init-reference.sh (revision d6f2548ec3508fac9ad0f2a7d6f4783f9f9cd119)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# Init code and data are freed after boot, so a klp relocation against them can
5# never resolve.  Such a patch must be rejected.
6
7. "$(dirname "$0")/../lib.sh"
8
9setup
10build_pair init_reference.c
11
12# The rejection can only happen if the patched build really does reference the
13# init symbol.  The fixture makes init_only volatile so the read cannot be
14# folded away, and this checks that it worked: without a relocation klp diff
15# would succeed, and the failure below would read as a missing check rather
16# than as a fixture which stopped posing the question.
17# Either spelling will do.  A file-local variable is reached through its
18# section symbol -- .init.data -- and a global one by name; which of the two
19# the compiler picks is its business, and the reference is what matters.
20in_relocs "$patched_obj" |
21	awk '$5 == ".init.data" || $5 == "init_only"' | grep -q . ||
22	fail "patched object has no reference into .init.data; the fixture tests nothing"
23
24run_diff 255
25
26diff_log | grep -q "can't patch or reference init code/data" ||
27	fail "expected rejection, got: $(diff_log | tail -1)"
28
29pass "reference to init data rejected"
30