1*638df22cSSong Liu#!/bin/bash 2*638df22cSSong Liu# SPDX-License-Identifier: GPL-2.0 3*638df22cSSong Liu# 4*638df22cSSong Liu# sympos is what livepatch uses to tell duplicate symbol names apart in the 5*638df22cSSong Liu# patched object: which "dup_counter" of several the relocation means. Get it 6*638df22cSSong Liu# wrong and the patch resolves to the wrong object at load time, silently. 7*638df22cSSong Liu# 8*638df22cSSong Liu# klp_find_sympos() reports 0 when a name is unique and a 1-based position when 9*638df22cSSong Liu# it is not, so both need checking -- always reporting a position, or never, 10*638df22cSSong Liu# each looks right in one of the two cases. 11*638df22cSSong Liu# 12*638df22cSSong Liu# This is the module path, counting symbol table order. vmlinux is reordered 13*638df22cSSong Liu# by the final link and goes through .klp.symid instead; that needs a linked 14*638df22cSSong Liu# vmlinux next to vmlinux.o and is not covered here. 15*638df22cSSong Liu 16*638df22cSSong Liu. "$(dirname "$0")/../lib.sh" 17*638df22cSSong Liu 18*638df22cSSong Liusetup 19*638df22cSSong Liu 20*638df22cSSong Liu# One copy: the name is unique, so there is nothing to disambiguate. 21*638df22cSSong Liubuild_one sympos_dup.c orig.o -DFUNC_NAME=use_a 22*638df22cSSong Liubuild_one sympos_dup.c patched.o -DFUNC_NAME=use_a -DPATCHED 23*638df22cSSong Liurun_diff 24*638df22cSSong Liu 25*638df22cSSong Liuassert_klp_sympos dup_counter 0 26*638df22cSSong Liu 27*638df22cSSong Liu# Two copies: positions, in symbol table order. 28*638df22cSSong Liufor p in "" "-DPATCHED"; do 29*638df22cSSong Liu # shellcheck disable=SC2086 30*638df22cSSong Liu build_one sympos_dup.c "a$p.o" -DFUNC_NAME=use_a $p 31*638df22cSSong Liu # shellcheck disable=SC2086 32*638df22cSSong Liu build_one sympos_dup.c "b$p.o" -DFUNC_NAME=use_b -DNO_MODINFO $p 33*638df22cSSong Liudone 34*638df22cSSong Liupartial_link "$workdir/orig.o" "$workdir/a.o" "$workdir/b.o" || 35*638df22cSSong Liu probe_skip "partial link unavailable" 36*638df22cSSong Liupartial_link "$workdir/patched.o" "$workdir/a-DPATCHED.o" "$workdir/b-DPATCHED.o" || 37*638df22cSSong Liu probe_skip "partial link unavailable" 38*638df22cSSong Liu 39*638df22cSSong Liu# Without duplicates in the input there is nothing for sympos to number. 40*638df22cSSong Liu[ "$(count_input_symbols orig.o dup_counter)" = 2 ] || 41*638df22cSSong Liu fail "fixture did not produce two dup_counter symbols" 42*638df22cSSong Liu 43*638df22cSSong Liurun_diff 44*638df22cSSong Liu 45*638df22cSSong Liuassert_klp_sympos dup_counter 1 46*638df22cSSong Liuassert_klp_sympos dup_counter 2 47*638df22cSSong Liu# ... and nothing still claiming the name is unique 48*638df22cSSong Liuout_symbols | grep -qE '\.klp\.sym\.[^.]+\.dup_counter,0([[:space:]]|$)' && 49*638df22cSSong Liu fail "sympos 0 emitted for a duplicated symbol" 50*638df22cSSong Liu 51*638df22cSSong Liupass "sympos numbers duplicate symbols and stays 0 for unique ones" 52