xref: /illumos-gate/usr/src/test/elf-tests/tests/relocs/i386/got32x/got32x.sh (revision dd72704bd9e794056c558153663c739e2012d721)
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
33if [[ -n $PROTO ]]; then
34	export LD_ALTEXEC=$PROTO/bin/ld
35fi
36
37gas -32 --mrelax-relocations=yes -c ${TESTDIR}/got32x.s -o got32x.o
38if (( $? != 0 )); then
39	print -u2 "Couldn't assemble ${TESTDIR}/got32x.s with relocation relaxation"
40	exit 1;
41fi
42
43$PROTO/bin/elfdump -rN.rel.text got32x.o | \
44	awk '$4 == "foo" {
45		if ($1 == "R_386_GOT32X") {
46			exit(0)
47		} else {
48			exit(1)
49		}
50	     }'
51if (( $? != 0 )); then
52	print -u2 "Assembled ${TESTDIR}/got32x.s did not result in relaxed relocation"
53	exit 1;
54fi
55
56gcc -m32 got32x.o -o got32x
57if (( $? != 0 )); then
58	print -u2 "Couldn't link ${TESTDIR}/got32x.s"
59	exit 1;
60fi
61
62./got32x | grep -q '^string$'
63if (( $? != 0 )); then
64	print -u2 "${TESTDIR}/got32x.s ran incorrectly"
65	exit 1;
66fi
67
68exit 0
69