summaryrefslogtreecommitdiff
path: root/tools/objtool/tests/x86/test-special-sections.sh
blob: 8dfaa4fc9a360fc3b5b41e1e44c72d94e7cf795c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# klp diff extracts entries from eight special sections.  Between them the
# existing tests reach .kcfi_traps, __jump_table, .static_call_sites and
# .altinstructions; __bug_table, __ex_table and __mcount_loc are covered by
# nothing, though the same extraction code serves all of them.
#
# Losing an entry is quiet in every case and wrong in a different way for each:
# a WARN() in patched code that no longer reports where it came from, an
# exception fixup that is simply not there when the faulting instruction traps,
# a function ftrace can no longer see.

. "$(dirname "$0")/../lib.sh"


# section, entry size, relocations per entry
for spec in "__bug_table 12 1" "__ex_table 12 2" "__mcount_loc 8 1"; do
	set -- $spec
	sec=$1

	# A fresh workdir per section: run_diff caches its checksums.
	setup
	build_pair special_sections.c \
		-DSPECIAL_SEC="\"$1\"" -DSPECIAL_ENTSIZE="$2" -DSPECIAL_RELOCS="$3"

	assert_input_section "$sec"
	run_diff

	# Extracted, and pointing at the function that was patched.
	assert_section "$sec"
	assert_reloc_sym "$sec" target
	assert_patched target

	# Nothing belonging to the function that was not.
	assert_not_patched other
	assert_no_reloc_sym "$sec" other

	cleanup
done

pass "__bug_table, __ex_table and __mcount_loc entries extracted"