xref: /illumos-gate/usr/src/test/elf-tests/tests/groups/strip-groups/strip-two-sections.sh (revision d48be21240dfd051b689384ce2b23479d757f2d8)
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 2023, 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}/strip-two-sections.s -o strip-two-obj1.o
40if (( $? != 0 )); then
41	print -u2 "Couldn't assemble ${TESTDIR}/strip-two-sections.s (obj1)"
42	exit 1;
43fi
44
45/bin/ld -s strip-two-obj1.o -o strip-two
46if (( $? != 0 )); then
47	print -u2 "Couldn't link ${TESTDIR}/strip-two"
48	exit 1;
49fi
50
51if [[ $(elfdump -cN.debug_stuff strip-two) != "" ]]; then
52	print -u2 ".debug_stuff section not stripped"
53	exit 1
54fi
55
56if [[ $(elfdump -cN.test_code strip-two) == "" ||
57      $(elfdump -cN.test_data strip-two) == "" ]]; then
58	print -u2 ".test section remains"
59	exit 1
60fi
61
62# Test that the group, which is now smaller, makes it through ld -r
63# correctly and that we don't crash
64/bin/ld -r -s strip-two-obj1.o -o strip-two.o
65if (( $? != 0 )); then
66	print -u2 "Couldn't link ${TESTDIR}/strip-two.o"
67	exit 1;
68fi
69
70
71if [[ $(elfdump -cN.group strip-two.o) == "" ]]; then
72	print -u2 "No group section made it to the output object"
73	exit 1
74fi
75
76find_in_group .group1 .test_data strip-two.o
77find_in_group .group1 .test_code strip-two.o
78