xref: /linux/tools/objtool/tests/x86/test-alt-annotation.sh (revision 5b6dca02b3e2254d2fd5706d76d7ab4610a67296)
1*c4717a16SSong Liu#!/bin/bash
2*c4717a16SSong Liu# SPDX-License-Identifier: GPL-2.0
3*c4717a16SSong Liu#
4*c4717a16SSong Liu# A text annotation on an instruction inside an alternative's replacement must
5*c4717a16SSong Liu# be carried into the patch.
6*c4717a16SSong Liu#
7*c4717a16SSong Liu# The kernel annotates replacement code wherever objtool has to be told
8*c4717a16SSong Liu# something about it -- a retpoline-safe indirect branch, a deliberately absent
9*c4717a16SSong Liu# ENDBR.  Two things made klp diff drop those annotations:
10*c4717a16SSong Liu#
11*c4717a16SSong Liu#   - replacement code has no real symbol, so objtool invents a NOTYPE fake
12*c4717a16SSong Liu#     one, and the extraction only kept references to FUNC symbols;
13*c4717a16SSong Liu#   - .discard.annotate_insn was processed before .altinstructions, so the
14*c4717a16SSong Liu#     replacement it referenced had no clone to point at yet.
15*c4717a16SSong Liu#
16*c4717a16SSong Liu# Nothing fails at build time when the annotation goes missing.  It surfaces
17*c4717a16SSong Liu# later as objtool warning about, or rejecting, the patched code it was there
18*c4717a16SSong Liu# to explain.
19*c4717a16SSong Liu#
20*c4717a16SSong Liu# Fixed by 62a7a01fde87 ("objtool/klp: Fix extraction of text annotations for
21*c4717a16SSong Liu# alternatives").
22*c4717a16SSong Liu
23*c4717a16SSong Liu. "$(dirname "$0")/../lib.sh"
24*c4717a16SSong Liu
25*c4717a16SSong Liusetup
26*c4717a16SSong Liubuild_pair alt_annotate.c
27*c4717a16SSong Liu
28*c4717a16SSong Liuassert_input_section .altinstructions
29*c4717a16SSong Liuassert_input_section .discard.annotate_insn
30*c4717a16SSong Liu
31*c4717a16SSong Liurun_diff
32*c4717a16SSong Liu
33*c4717a16SSong Liu# The annotation has to survive, and to still name the replacement.  Checking
34*c4717a16SSong Liu# only the section would pass on an entry whose relocation was dropped.
35*c4717a16SSong Liuassert_section .discard.annotate_insn
36*c4717a16SSong Liuassert_reloc_sym .discard.annotate_insn target_repl
37*c4717a16SSong Liu
38*c4717a16SSong Liupass "text annotation on an alternative replacement carried into the patch"
39