1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# Some static locals must not be correlated with their counterparts in the 5# running kernel; the patched code has to use a fresh copy instead. 6# 7# .data..once holds the "have we warned yet" flags behind WARN_ONCE. Correlate 8# one and the patched function inherits the flag from before the patch, so the 9# warning the patch was written to produce never fires. The same goes for the 10# names the kernel generates for per-instance state -- __warned, __key, 11# __func__ and friends. 12# 13# Both directions matter, so an ordinary static local is here too: a rule that 14# refuses to correlate anything would pass a test that only checks the 15# refusals. 16 17. "$(dirname "$0")/../lib.sh" 18 19setup 20build_pair static_local_uncorrelated.c 21run_diff 22 23# Compilers mangle static locals differently -- gcc gives __key.1, Clang 24# target.__key -- so match on the base name. 25 26# Correlated: referenced through a klp symbol, pointing at the kernel's copy. 27out_symbols | grep -q '\.klp\.sym\..*ordinary' || 28 fail "ordinary static local was not correlated" 29 30# Not correlated: no klp symbol, and a copy cloned into the patch instead. 31out_symbols | grep -q '\.klp\.sym\..*__key' && 32 fail "__key was correlated; it must use a fresh copy" 33# .sbss/.sdata on the architectures with a small-data area. 34out_sections | grep -qE '\.s?(bss|data)[^ ]*__key' || 35 fail "__key was neither correlated nor cloned" 36 37out_symbols | grep -q '\.klp\.sym\..*once_flag' && 38 fail ".data..once variable was correlated; it must use a fresh copy" 39assert_section '.data..once' 40 41pass "per-instance static locals cloned, ordinary ones correlated" 42