xref: /linux/tools/objtool/tests/generic/test-export-symbol-for-modules.sh (revision 12d5fc96ebbb3b948861805b32a4c3a96105ccd9)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# EXPORT_SYMBOL_FOR_MODULES() puts a vmlinux symbol in a "module:<names>"
5# namespace, and the module loader grants access by matching the importing
6# module's name against that list.  A livepatch module is never on the list, so
7# referencing such a symbol with a normal relocation fails modpost, and if that
8# is silenced, fails to load with "Unknown symbol".  It needs a klp relocation,
9# the same as an unexported symbol.
10#
11# Ordinary namespaces are not affected: copy_import_ns() propagates the patched
12# object's import tags to the patch module, so a normal relocation works.
13
14. "$(dirname "$0")/../lib.sh"
15
16setup
17build_pair cross_module.c
18
19sym=other_mod_func
20
21# Plain vmlinux export: a normal relocation is what we want.
22export_syms "$sym"
23run_diff
24assert_no_klp_sym "$sym"
25
26# Ordinary namespace: still a normal relocation.
27export_syms
28add_exports_ns vmlinux MY_NS "$sym"
29run_diff
30assert_no_klp_sym "$sym"
31
32# module: namespace: has to become a klp relocation.
33export_syms
34add_exports_ns vmlinux module:kvm "$sym"
35run_diff
36assert_klp_sym "$sym" vmlinux
37assert_section __klp_relocs.vmlinux
38
39pass "EXPORT_SYMBOL_FOR_MODULES symbol referenced with a klp relocation"
40