xref: /illumos-gate/usr/src/test/elf-tests/tests/groups/common.sh (revision 7a6d80f1660abd4755c68cbd094d4a914681d26e)
1#! /usr/bin/sh
2#
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14# Copyright 2023 Richard Lowe
15
16# find_in_group <group> <section> <file>
17# errors if not present, else returns the group index
18find_in_group() {
19	elfdump -g $3 | awk -v group="${1}\$" -v section=$2 '
20		BEGIN { slurp = 0 };
21		$0 ~ group { slurp = 1 };
22		slurp && $0 ~ section {
23			gsub(/[\[\]]/, "", $3);
24			print $3;
25			exit;
26		}' | read index
27	if [[ -z $index ]] || (( index <= 0 )); then
28		print -u2 "Couldn't find $2 in $1"
29		exit 1
30	fi
31	print $index;
32}
33