xref: /linux/tools/objtool/tests/x86/test-manual-klp-static-call.sh (revision 5b6dca02b3e2254d2fd5706d76d7ab4610a67296)
1*841c8c57SSong Liu#!/bin/bash
2*841c8c57SSong Liu# SPDX-License-Identifier: GPL-2.0
3*841c8c57SSong Liu#
4*841c8c57SSong Liu# objtool's static call handling must accept a livepatch module which cannot
5*841c8c57SSong Liu# see a static call's key symbol.
6*841c8c57SSong Liu#
7*841c8c57SSong Liu# __SCK__* keys are not exported; modules get read-only access at load time
8*841c8c57SSong Liu# instead.  Livepatch modules built by klp-build do have full access to their
9*841c8c57SSong Liu# keys, and a check was added on the strength of that -- but a livepatch module
10*841c8c57SSong Liu# can also be written by hand, and samples/livepatch is full of them.  One of
11*841c8c57SSong Liu# those needs a key it cannot see as soon as it does anything that expands to a
12*841c8c57SSong Liu# static call, which with CONFIG_MEM_ALLOC_PROFILING_DEBUG includes allocating
13*841c8c57SSong Liu# memory:
14*841c8c57SSong Liu#
15*841c8c57SSong Liu#   samples/livepatch/livepatch-shadow-fix1.o: error: objtool: static_call:
16*841c8c57SSong Liu#     can't find static_call_key symbol: __SCK__WARN_trap
17*841c8c57SSong Liu#
18*841c8c57SSong Liu# The module built without the livepatch tag is the control: it takes the same
19*841c8c57SSong Liu# path and has always been accepted, so a test which only built the livepatch
20*841c8c57SSong Liu# one could not tell this fix from the check being removed altogether.
21*841c8c57SSong Liu#
22*841c8c57SSong Liu# Fixed by f495054bd12e ("objtool/klp: Fix unexported static call key access
23*841c8c57SSong Liu# for manually built livepatch modules").
24*841c8c57SSong Liu
25*841c8c57SSong Liu. "$(dirname "$0")/../lib.sh"
26*841c8c57SSong Liu
27*841c8c57SSong Liusetup
28*841c8c57SSong Liu
29*841c8c57SSong Liu# Not a klp subcommand: this is objtool's ordinary check pass, which is what
30*841c8c57SSong Liu# runs over a hand-built livepatch module during a normal kernel build.
31*841c8c57SSong Liufor tag in "" -DLIVEPATCH; do
32*841c8c57SSong Liu	build_one static_call_no_key.c mod.o $tag
33*841c8c57SSong Liu
34*841c8c57SSong Liu	"$OBJTOOL" --module --static-call "$workdir/mod.o" \
35*841c8c57SSong Liu		> "$workdir/objtool.log" 2>&1 ||
36*841c8c57SSong Liu		fail "objtool rejected a ${tag:+livepatch }module which cannot" \
37*841c8c57SSong Liu		     "see its static call key: $(tail -1 "$workdir/objtool.log")"
38*841c8c57SSong Liudone
39*841c8c57SSong Liu
40*841c8c57SSong Liupass "livepatch module accepted without access to its static call key"
41