xref: /linux/tools/objtool/tests/generic/test-local-vs-export.sh (revision 12d5fc96ebbb3b948861805b32a4c3a96105ccd9)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# find_export() matched on symbol name alone, so a static function or variable
5# sharing a name with an export was mistaken for a reference to that export.
6# For a vmlinux export that means no klp relocation at all: the normal
7# relocation left behind is resolved by the module loader to the vmlinux
8# symbol, and the patched code quietly reads and writes the wrong object.
9#
10# Exports are always global, so a local symbol is never one.
11
12. "$(dirname "$0")/../lib.sh"
13
14setup
15build_pair static_local.c
16
17# The static the fixture uses.  Compilers mangle statics variously -- gcc says
18# counter.0, clang says target.counter -- so find what this one produced rather
19# than assuming a shape.
20local_sym="$(in_symbols orig.o |
21	awk '$4 == "OBJECT" && $5 == "LOCAL" && $8 ~ /counter/ { print $8; exit }')"
22[ -n "$local_sym" ] ||
23	fail "fixture produced no local 'counter' symbol"
24
25# Contrive the collision: something else exports that same name.
26export_syms "$local_sym" counter
27run_diff
28
29# Still treated as the local it is, not as the export.
30assert_klp_sym "$local_sym" vmlinux
31
32pass "local symbol not mistaken for an export of the same name"
33