1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# A patch can change a symbol's linkage without renaming it: dropping "static" 5# from a helper so something else can call it, or adding it to one that is no 6# longer shared. Correlation keys off more than the name, so a symbol whose 7# binding moved can fail to pair with itself. 8# 9# Failing to correlate is not a build failure. The symbol looks new, and a 10# "new" data symbol is either rejected or cloned as a second copy -- at which 11# point the patched code updates its own private variable and the rest of the 12# kernel keeps reading the original. 13 14. "$(dirname "$0")/../lib.sh" 15 16setup 17build_pair local_to_global.c 18 19# Confirm the fixture really moved the bindings, in both directions. 20# 21# Match the binding and the name as fields, not as substrings of the line. 22# -ffunction-sections and -fdata-sections give these symbols sections of their 23# own, and the section symbols -- .text.flipped_up, .data.flipped_down -- are 24# always LOCAL, so "does a LOCAL line mention flipped_up" is answered by the 25# wrong symbol. GNU readelf 2.35 happens to leave section symbol names blank, 26# but llvm-readelf prints them, and a premise that holds on one readelf and 27# not the other is no premise at all. 28has_binding() # $1 object, $2 binding, $3 symbol 29{ 30 in_symbols "$1" | awk -v b="$2" -v n="$3" '$5 == b && $NF == n' | grep -q . 31} 32 33has_binding orig.o LOCAL flipped_up || 34 fail "flipped_up is not local in the original" 35has_binding patched.o GLOBAL flipped_up || 36 fail "flipped_up is not global in the patched object" 37has_binding orig.o GLOBAL flipped_down || 38 fail "flipped_down is not global in the original" 39has_binding patched.o LOCAL flipped_down || 40 fail "flipped_down is not local in the patched object" 41 42run_diff 43 44assert_diff_log 'changed function: caller' 45 46# Correlated means each pairs with its own counterpart in the original, so the 47# patch refers back to the kernel's copy ... 48assert_klp_sym flipped_up vmlinux 49assert_klp_sym flipped_down vmlinux 50 51# ... rather than carrying its own. A second copy of flipped_down is the bad 52# outcome: patched code would update its private one while the rest of the 53# kernel keeps reading the original. 54assert_not_patched flipped_up 55assert_no_section .data.flipped_down 56assert_no_section .bss.flipped_down 57 58diff_log | grep -q 'no correlation' && 59 fail "linkage change reported as an uncorrelated symbol" 60diff_log | grep -q 'changed data' && 61 fail "linkage change reported as changed data" 62 63pass "symbols correlated across a change of linkage" 64