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