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