xref: /linux/tools/objtool/tests/generic/test-new-export-ref.sh (revision 6549ce0dd1be2400ecdd8693e47c189c54562a4e)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# A reference the patch adds has no counterpart in the original object.  klp
5# diff used to reject any such reference needing a klp relocation, which ruled
6# out patches that call something they did not call before -- a common enough
7# thing for a fix to do.
8#
9# Module.symvers is what makes it safe: it says the symbol exists and who owns
10# it.  But that is only sufficient for a vmlinux export.  A new reference to a
11# module's export is a dependency the patch module does not declare, and the
12# relocation would resolve only if that module happened to be loaded, so it
13# stays an error.
14
15. "$(dirname "$0")/../lib.sh"
16
17setup
18build_pair new_export_ref.c
19
20# Exported by vmlinux, in a module: namespace so it needs a klp relocation
21# rather than an ordinary one.  Allowed.
22export_syms
23add_exports_ns vmlinux module:kvm newly_referenced
24run_diff
25assert_klp_sym newly_referenced vmlinux
26
27# Exported by a module the patched object does not depend on.  Rejected, and
28# for that reason rather than some other.
29export_syms
30add_exports other_mod newly_referenced
31run_diff 255
32assert_diff_log 'undeclared module dependency'
33
34# ... unless the original already referenced something that module exports.
35# The loader will not let the patched object load without other_mod, so the
36# klp relocation has something to resolve against, and klp diff allows it.
37# This is the other half of the rule, and it fails in the opposite direction:
38# refusing here would reject a patch which is safe to apply.
39rm -f "$workdir/out.o"
40build_pair new_export_ref.c -DEXISTING_DEP
41export_syms
42add_exports other_mod newly_referenced existing_dep
43run_diff
44assert_klp_sym newly_referenced other_mod
45
46pass "new reference allowed for vmlinux and for a module already depended on"
47