1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# klp post-link converts the intermediate __klp_relocs.* sections into the 5# .klp.rela.* form the kernel applies at patch load. Getting this wrong is 6# invisible at build time: the module links and loads, and the relocations are 7# simply never applied. 8 9. "$(dirname "$0")/../lib.sh" 10 11setup 12build_pair static_local.c 13 14# An unexported symbol is what produces a klp relocation in the first place. 15# The static local is renamed by the compiler -- counter.0 with gcc -- so the 16# fixture's premise is that some local of that shape exists, not that a symbol 17# called "counter" does. Find it first; everything below names it. 18local_sym="$(in_symbols orig.o | 19 awk '$4 == "OBJECT" && $5 == "LOCAL" && $8 ~ /counter/ { print $8; exit }')" 20[ -n "$local_sym" ] || fail "fixture produced no local 'counter' symbol" 21 22run_diff 23assert_section __klp_relocs.vmlinux 24 25# Nothing has converted them yet. 26assert_no_section ".klp.rela.vmlinux..text.target" 27 28# The original relocation is neutralised by pointing it at a tombstone, which 29# is what stops the module loader resolving it behind livepatch's back. 30# 31# Compilers mangle a static local differently -- gcc says counter.0, clang 32# target.counter -- so find what this one produced rather than assuming. 33assert_tombstone "$local_sym" 34 35run_post_link 36 37# One .klp.rela section per base section, carrying SHF_RELA_LIVEPATCH, against 38# a symbol in SHN_LIVEPATCH for the kernel to resolve. 39assert_klp_rela vmlinux .text.target 40assert_livepatch_sym "$local_sym" 41 42pass "klp relocations converted to .klp.rela with SHN_LIVEPATCH symbols" 43