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