xref: /illumos-gate/usr/src/test/elf-tests/tests/string-merge/simple.sh (revision 3cac7b0d73edf3f2674ad0f64d1fff3d2e59ae8c)
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
33assemble() {
34	gcc -c -o $2 $1
35	if (( $? != 0 )); then
36		print -u2 "assembly of ${1} failed";
37		exit 1;
38	fi
39}
40
41# We expect any alternate linker to be in LD_ALTEXEC for us already
42assemble ${TESTDIR}/str1.s str1.o
43assemble ${TESTDIR}/str2.s str2.o
44
45gcc -shared -o strmerge.so str1.o str2.o
46if (( $? != 0 )); then
47	print -u2 "link of ${TESTDIR}/str[12].o failed";
48	exit 1;
49fi
50
51elfdump -N.test -w /dev/stdout strmerge.so | tr '\0' ' ' | grep -q '^ buffalo bills $'
52if (( $? != 0 )); then
53	print -u2 "Merged section contains unexpected data";
54	elfdump -N.test -w /dev/stdout strmerge.so | tr '\0' ' ' >&2
55	exit 1;
56fi
57