1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# .klp.symid must not reference symbols in sections the vmlinux link discards. 5# Each such section has been its own bug, found only when someone built a 6# config where a duplicate happened to land there, so cover the whole list 7# rather than whichever one was reported last. 8 9. "$(dirname "$0")/../lib.sh" 10 11setup 12 13# Allocated sections which vmlinux.lds.h discards unconditionally. A symid 14# referencing one of these fails the vmlinux link outright: 15# 16# `__exitcall_hid_exit' referenced in section `.klp.symid' of vmlinux.o: 17# defined in discarded section `.exitcall.exit' of vmlinux.o 18for sec in .exitcall.exit .no_trim_symbol; do 19 build_one symid_discarded.c a.o \ 20 -DFUNC_NAME=use_a -DDISCARDED_SEC="\"$sec\"" 21 build_one symid_discarded.c b.o \ 22 -DFUNC_NAME=use_b -DDISCARDED_SEC="\"$sec\"" 23 24 # --klp-symids only runs on a file named vmlinux.o 25 rm -f "$workdir/vmlinux.o" 26 partial_link "$workdir/vmlinux.o" "$workdir/a.o" "$workdir/b.o" || 27 probe_skip "partial link unavailable" 28 29 "$OBJTOOL" --klp-symids --link "$workdir/vmlinux.o" || 30 fail "objtool --klp-symids failed" 31 32 symids="$(in_relocs vmlinux.o | 33 awk '/rela.klp.symid/,/^$/')" 34 35 # Without this the test would also pass if symid generation stopped 36 # entirely. 37 echo "$symids" | grep -q 'dup_normal' || 38 fail "$sec: no symid for the duplicate in a live section" 39 40 echo "$symids" | grep -q 'dup_discarded' && 41 fail "symid emitted for a symbol in discarded section $sec" 42done 43 44pass "no symids for symbols in discarded sections" 45