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