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 2022, Richard Lowe. 14 15TESTDIR=$(dirname $0) 16 17source ${TESTDIR}/../common.sh 18 19tmpdir=/tmp/test.$$ 20mkdir $tmpdir 21cd $tmpdir 22 23cleanup() { 24 cd / 25 rm -fr $tmpdir 26} 27 28trap 'cleanup' EXIT 29 30if [[ $PWD != $tmpdir ]]; then 31 print -u2 "Failed to create temporary directory: $tmpdir" 32 exit 1; 33fi 34 35if [[ -n $PROTO ]]; then 36 export LD_ALTEXEC=$PROTO/bin/ld 37fi 38 39gas -c ${TESTDIR}/sections.s -o obj1.o 40if (( $? != 0 )); then 41 print -u2 "Couldn't assemble ${TESTDIR}/sections.s (obj1)" 42 exit 1; 43fi 44 45gas -c ${TESTDIR}/sections.s -o obj2.o 46if (( $? != 0 )); then 47 print -u2 "Couldn't assemble ${TESTDIR}/sections.s (obj2)" 48 exit 1; 49fi 50 51/bin/ld -r obj1.o obj2.o -o test-obj.o 52if (( $? != 0 )); then 53 print -u2 "Couldn't link ${TESTDIR}/test-obj.o" 54 exit 1; 55fi 56 57# section_content <index> <file> 58section_content() { 59 elfdump -I$1 -w /dev/stdout $2 | tr '\0' '\n' 60} 61 62# The first test_data_conflict, a member of group1 unmerged with only one 63# copy kept. 64GROUP1_INDEX=$(find_in_group group1 test_data_conflict test-obj.o) 65 66# The first test_data_conflict, a member of group2 unmerged with only one 67# copy kept. 68GROUP2_INDEX=$(find_in_group group2 test_data_conflict test-obj.o) 69 70# The un-grouped test_data_conflict, with both copies kept 71elfdump -cN.test_data_conflict test-obj.o | \ 72 awk -v group1=$GROUP1_INDEX -v group2=$GROUP2_INDEX ' 73 /^Section Header/ { 74 gsub(/[^0-9]/, "", $2); 75 if (($2 != group1) && ($2 != group2)) { 76 print $2 77 } 78 }' | read UNGROUP_INDEX 79if [[ -z $UNGROUP_INDEX ]] || (( UNGROUP_INDEX <= 0 )); then 80 print -u2 "Couldn't find ungrouped .test_data_conflict" 81 exit 1 82fi 83 84if (( GROUP1_INDEX == GROUP2_INDEX )); then 85 print -u2 "FAIL: group1 and group2 contain the same section"; 86 exit 1 87fi 88 89cmp -s <(section_content $GROUP1_INDEX test-obj.o) /dev/stdin <<EOF 902: test_data_conflict (group 1) 91EOF 92if (( $? != 0 )); then 93 print -u2 "FAIL: the .test_data_conflict section in group1 has the wrong content" 94 exit 1; 95fi 96 97cmp -s <(section_content $GROUP2_INDEX test-obj.o) /dev/stdin <<EOF 983: test_data_conflict (group 2) 99EOF 100if (( $? != 0 )); then 101 print -u2 "FAIL: the .test_data_conflict section in group2 has the wrong content" 102 exit 1; 103fi 104 105cmp -s <(section_content $UNGROUP_INDEX test-obj.o) /dev/stdin <<EOF 1064: test_data_conflict (two copies not in group) 1074: test_data_conflict (two copies not in group) 108EOF 109if (( $? != 0 )); then 110 print -u2 "FAIL: the ungrouped .test_data_conflict has the wrong content" 111 exit 1; 112fi 113