xref: /linux/tools/objtool/tests/generic/test-module-vmlinux-reloc.sh (revision 5b6dca02b3e2254d2fd5706d76d7ab4610a67296)
1*65b0aac4SSong Liu#!/bin/bash
2*65b0aac4SSong Liu# SPDX-License-Identifier: GPL-2.0
3*65b0aac4SSong Liu#
4*65b0aac4SSong Liu# Patching a module, where the patched code references a vmlinux symbol which
5*65b0aac4SSong Liu# needs a klp relocation.
6*65b0aac4SSong Liu#
7*65b0aac4SSong Liu# The kernel does not allow a module-targeted klp relocation to reference a
8*65b0aac4SSong Liu# vmlinux symbol, and a symbol exported with EXPORT_SYMBOL_FOR_MODULES gets a
9*65b0aac4SSong Liu# klp relocation.  Put together, filing that relocation under the patched
10*65b0aac4SSong Liu# module produces a patch the kernel refuses to apply to its target.
11*65b0aac4SSong Liu#
12*65b0aac4SSong Liu# So it goes under vmlinux instead, and is applied when the patch module loads
13*65b0aac4SSong Liu# rather than when the patched module does.  That is the opposite of the rule
14*65b0aac4SSong Liu# for a reference to a module's symbol, which test-module-object covers; this
15*65b0aac4SSong Liu# is the other branch of the same decision.
16*65b0aac4SSong Liu
17*65b0aac4SSong Liu. "$(dirname "$0")/../lib.sh"
18*65b0aac4SSong Liu
19*65b0aac4SSong Liusetup
20*65b0aac4SSong Liu# The object being patched is a module ...
21*65b0aac4SSong Liubuild_module_pair cross_module.c klp_testmod
22*65b0aac4SSong Liu
23*65b0aac4SSong Liu# ... and the symbol it references belongs to vmlinux, exported in a way that
24*65b0aac4SSong Liu# still requires a klp relocation.
25*65b0aac4SSong Liuexport_syms
26*65b0aac4SSong Liuadd_exports_ns vmlinux module:kvm other_mod_func
27*65b0aac4SSong Liurun_diff
28*65b0aac4SSong Liu
29*65b0aac4SSong Liu# Filed against vmlinux, applied when the patch loads.
30*65b0aac4SSong Liuassert_section __klp_relocs.vmlinux
31*65b0aac4SSong Liuassert_klp_sym other_mod_func vmlinux
32*65b0aac4SSong Liu
33*65b0aac4SSong Liu# Not against the patched module: that is the relocation the kernel rejects.
34*65b0aac4SSong Liuassert_no_section __klp_relocs.klp_testmod
35*65b0aac4SSong Liu
36*65b0aac4SSong Liurun_post_link
37*65b0aac4SSong Liuassert_klp_rela vmlinux .text.target
38*65b0aac4SSong Liuassert_no_section ".klp.rela.klp_testmod..text.target"
39*65b0aac4SSong Liu
40*65b0aac4SSong Liupass "klp relocation to a vmlinux symbol filed under vmlinux, not the patched module"
41