xref: /linux/tools/objtool/tests/x86/test-special-sections.sh (revision 12d5fc96ebbb3b948861805b32a4c3a96105ccd9)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# klp diff extracts entries from eight special sections.  Between them the
5# existing tests reach .kcfi_traps, __jump_table, .static_call_sites and
6# .altinstructions; __bug_table, __ex_table and __mcount_loc are covered by
7# nothing, though the same extraction code serves all of them.
8#
9# Losing an entry is quiet in every case and wrong in a different way for each:
10# a WARN() in patched code that no longer reports where it came from, an
11# exception fixup that is simply not there when the faulting instruction traps,
12# a function ftrace can no longer see.
13
14. "$(dirname "$0")/../lib.sh"
15
16
17# section, entry size, relocations per entry
18for spec in "__bug_table 12 1" "__ex_table 12 2" "__mcount_loc 8 1"; do
19	set -- $spec
20	sec=$1
21
22	# A fresh workdir per section: run_diff caches its checksums.
23	setup
24	build_pair special_sections.c \
25		-DSPECIAL_SEC="\"$1\"" -DSPECIAL_ENTSIZE="$2" -DSPECIAL_RELOCS="$3"
26
27	assert_input_section "$sec"
28	run_diff
29
30	# Extracted, and pointing at the function that was patched.
31	assert_section "$sec"
32	assert_reloc_sym "$sec" target
33	assert_patched target
34
35	# Nothing belonging to the function that was not.
36	assert_not_patched other
37	assert_no_reloc_sym "$sec" other
38
39	cleanup
40done
41
42pass "__bug_table, __ex_table and __mcount_loc entries extracted"
43