xref: /linux/tools/objtool/tests/generic/test-jump-label-key.sh (revision 5b6dca02b3e2254d2fd5706d76d7ab4610a67296)
1*729bf531SPuranjay Mohan#!/bin/bash
2*729bf531SPuranjay Mohan# SPDX-License-Identifier: GPL-2.0
3*729bf531SPuranjay Mohan#
4*729bf531SPuranjay Mohan# A cloned __jump_table entry must keep a relocation in its key slot, whether
5*729bf531SPuranjay Mohan# the key needs a klp relocation or not.
6*729bf531SPuranjay Mohan
7*729bf531SPuranjay Mohan. "$(dirname "$0")/../lib.sh"
8*729bf531SPuranjay Mohan
9*729bf531SPuranjay Mohankey=klp_test_key
10*729bf531SPuranjay Mohan
11*729bf531SPuranjay Mohansetup
12*729bf531SPuranjay Mohanbuild_pair jump_label.c
13*729bf531SPuranjay Mohan
14*729bf531SPuranjay Mohanhas_input_section orig.o __jump_table ||
15*729bf531SPuranjay Mohan	probe_skip "fixture produced no __jump_table on this arch"
16*729bf531SPuranjay Mohan
17*729bf531SPuranjay Mohankey_slot_relocs()
18*729bf531SPuranjay Mohan{
19*729bf531SPuranjay Mohan	out_relocs | awk '/rela__jump_table/,/^$/' | grep -c "^0*8[[:space:]]"
20*729bf531SPuranjay Mohan}
21*729bf531SPuranjay Mohan
22*729bf531SPuranjay Mohan# Unexported: klp relocation, key slot holds a tombstone.
23*729bf531SPuranjay Mohanexport_syms
24*729bf531SPuranjay Mohanrun_diff
25*729bf531SPuranjay Mohan
26*729bf531SPuranjay Mohan[ "$(key_slot_relocs)" = 1 ] ||
27*729bf531SPuranjay Mohan	fail "unexported key: key slot has no relocation"
28*729bf531SPuranjay Mohanout_relocs | awk '/rela__jump_table/,/^$/' | grep -q "\.klp\.tombstone\.$key" ||
29*729bf531SPuranjay Mohan	fail "unexported key: expected a .klp.tombstone.$key relocation"
30*729bf531SPuranjay Mohanout_symbols | grep -q "\.klp\.sym\..*\.$key," ||
31*729bf531SPuranjay Mohan	fail "unexported key: no .klp.sym reference for the real relocation"
32*729bf531SPuranjay Mohan
33*729bf531SPuranjay Mohan# Exported: ordinary relocation, no klp machinery.
34*729bf531SPuranjay Mohanexport_syms "$key"
35*729bf531SPuranjay Mohanrun_diff
36*729bf531SPuranjay Mohan
37*729bf531SPuranjay Mohan[ "$(key_slot_relocs)" = 1 ] ||
38*729bf531SPuranjay Mohan	fail "exported key: key slot has no relocation"
39*729bf531SPuranjay Mohanout_relocs | awk '/rela__jump_table/,/^$/' | grep -q "[[:space:]]$key[[:space:]]*+" ||
40*729bf531SPuranjay Mohan	fail "exported key: expected a direct relocation to $key"
41*729bf531SPuranjay Mohanout_symbols | grep -q '\.klp\.tombstone\.' &&
42*729bf531SPuranjay Mohan	fail "exported key: tombstone emitted for an exported symbol"
43*729bf531SPuranjay Mohan
44*729bf531SPuranjay Mohanpass "key slot populated for exported and unexported vmlinux keys"
45