1#!/bin/ksh
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13# Copyright 2021, Richard Lowe.
14
15TESTDIR=$(dirname $0)
16
17tmpdir=/tmp/test.$$
18mkdir $tmpdir
19cd $tmpdir
20
21cleanup() {
22	cd /
23	rm -fr $tmpdir
24}
25
26trap 'cleanup' EXIT
27
28if [[ $PWD != $tmpdir ]]; then
29	print -u2 "Failed to create temporary directory: $tmpdir"
30	exit 1;
31fi
32
33make -f ${TESTDIR}/Makefile.test SRCDIR=${TESTDIR}
34if (( $? != 0 )); then
35	print -u2 "FAIL: Failed to link"
36	exit 1;
37fi
38
39elfdump -sN.symtab libtest.so | awk '$9 ~ /(bss|data)_symbol/ {
40	if ($5 != "LOCL") {
41		exit 1;
42	}
43}'
44
45if (( $? != 0 )); then
46	print -u2 "FAIL: libtest.so COMDAT symbols not reduced to local"
47	exit 1;
48fi
49
50elfdump -sN.symtab libothertest.so | awk '$9 ~ /(bss|data)_symbol/ {
51	if ($5 != "LOCL") {
52		exit 1;
53	}
54}'
55
56if (( $? != 0 )); then
57	print -u2 "FAIL: libothertest.so COMDAT symbols not reduced to local"
58	exit 1;
59fi
60
61elfdump -s libnoref.so | grep -q _symbol
62if (( $? == 0 )); then
63	print -u2 "FAIL: unreferenced symbols survive into output object"
64	exit 1;
65fi
66
67./test
68if (( $? != 0 )); then
69	print -u2 "FAIL: Failed to execute ./test"
70	exit 1;
71fi
72