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