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 -64 --mrelax-relocations=yes -c ${TESTDIR}/rex_gotpcrel.s -o rex_gotpcrel.o 38if (( $? != 0 )); then 39 print -u2 "Couldn't assemble ${TESTDIR}/rex_gotpcrel.s with relocation relaxation" 40 exit 1; 41fi 42 43$PROTO/bin/elfdump -rN.rela.text rex_gotpcrel.o | \ 44 awk '$5 == "foo" { 45 if ($1 == "R_AMD64_REX_GOTPCRELX") { 46 exit(0) 47 } else { 48 exit(1) 49 } 50 }' 51if (( $? != 0 )); then 52 print -u2 "Assembled ${TESTDIR}/gotpcrel.s did not result in relaxed relocation" 53 exit 1; 54fi 55 56gcc -m64 rex_gotpcrel.o -o rex_gotpcrel 57if (( $? != 0 )); then 58 print -u2 "Couldn't link ${TESTDIR}/rex_gotpcrel.s" 59 exit 1; 60fi 61 62./rex_gotpcrel | grep -q '^string$' 63if (( $? != 0 )); then 64 print -u2 "${TESTDIR}/rex_gotpcrel.s ran incorrectly" 65 exit 1; 66fi 67 68exit 0 69