xref: /linux/tools/objtool/tests/x86/test-empty-alternative.sh (revision 5b6dca02b3e2254d2fd5706d76d7ab4610a67296)
1*dff07c58SSong Liu#!/bin/bash
2*dff07c58SSong Liu# SPDX-License-Identifier: GPL-2.0
3*dff07c58SSong Liu#
4*dff07c58SSong Liu# An x86 alternative with an empty replacement still gets a relocation for its
5*dff07c58SSong Liu# replacement offset, but the label it points at is the end of the previous
6*dff07c58SSong Liu# replacement -- which is also the start of the next one.  The value is
7*dff07c58SSong Liu# meaningless, and get_alt_entry() already ignores it.
8*dff07c58SSong Liu#
9*dff07c58SSong Liu# Cloning it drags in an unrelated neighboring replacement and everything that
10*dff07c58SSong Liu# replacement references.  In the reported case an empty alternative in
11*dff07c58SSong Liu# meminfo_proc_show() pulled in one from proc_kcore_init(), emitting a klp
12*dff07c58SSong Liu# relocation against init text which is long freed by the time the patch is
13*dff07c58SSong Liu# applied.
14*dff07c58SSong Liu
15*dff07c58SSong Liu. "$(dirname "$0")/../lib.sh"
16*dff07c58SSong Liu
17*dff07c58SSong Liusetup
18*dff07c58SSong Liubuild_pair empty_alternative.c
19*dff07c58SSong Liu
20*dff07c58SSong Liuassert_input_section .altinstructions
21*dff07c58SSong Liuassert_input_section .altinstr_replacement
22*dff07c58SSong Liu
23*dff07c58SSong Liurun_diff
24*dff07c58SSong Liu
25*dff07c58SSong Liu# target's own replacement comes along ...
26*dff07c58SSong Liuassert_symbol target_repl
27*dff07c58SSong Liu# ... neighbor's does not, nor what it references.
28*dff07c58SSong Liuassert_no_symbol neighbor_repl
29*dff07c58SSong Liuassert_no_symbol neighbor_only
30*dff07c58SSong Liu
31*dff07c58SSong Liupass "empty alternative's replacement offset ignored when cloning"
32