xref: /illumos-gate/usr/src/test/util-tests/tests/ctf/ctftest-merge-no-ctf.ksh (revision 2aeafac3612e19716bf8164f89c3c9196342979c)
1#!/usr/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# Copyright (c) 2019, Joyent, Inc.
13#
14
15set -e
16
17result=0
18
19progname=$(basename $0)
20
21fail()
22{
23	echo "Failed: $*" 2>&1
24	result=1
25}
26
27fail_no_ctf()
28{
29	cmd="$@"
30	set +e
31	out=$($cmd 2>&1)
32
33	if [[ $? -eq 0 ]]; then
34		fail "$cmd succeeded but should have failed"
35		set -e
36		return;
37	fi
38
39	set -e
40
41	if ! echo "$out" | \
42	    grep "File does not contain CTF data" >/dev/null; then
43		fail "$cmd: incorrect output $out"
44		return;
45	fi
46}
47
48has_ctf()
49{
50	for f in "$@"; do
51		if ! elfdump -c -N .SUNW_ctf "$f" |
52		    grep '.SUNW_ctf' >/dev/null; then
53			fail "$f lacks CTF section"
54			return
55		fi
56	done
57}
58
59cat <<EOF >file1.c
60#include <stdio.h>
61struct foo { int a; };
62struct foo foos[400];
63int main(void) { struct foo foo = { 4 }; printf("%d\n", foo.a); }
64EOF
65
66cat <<EOF >file2.c
67#include <stdio.h>
68struct foo { char b; float c; };
69struct foo stuff[90];
70char myfunc(int a) { printf("%d\n", a); }
71EOF
72
73cat <<EOF >file3.cc
74struct bar { char *tar; };
75void mycxxfunc(char *c) { c[0] = '9'; };
76EOF
77
78cat <<EOF >file4.s
79.globl caller
80.type caller,@function
81caller:
82	movl 4(%ebp), %eax
83	ret
84EOF
85
86echo "$progname: ctfmerge should fail if one C-source lacks CTF"
87
88$ctf_cc $ctf_debugflags -c -o file1.o file1.c
89$ctf_convert file1.o
90$ctf_cc -c -o file2.o file2.c
91ld -r -o files.o file2.o file1.o
92fail_no_ctf $ctf_merge -o files.o file2.o file1.o
93ld -r -o files.o file2.o file1.o
94$ctf_merge -m -o files.o file2.o file1.o
95has_ctf files.o
96$ctf_cc -o mybin file2.o file1.o
97fail_no_ctf $ctf_merge -o mybin file2.o file1.o
98$ctf_cc -o mybin file2.o file1.o
99$ctf_merge -m -o mybin file2.o file1.o
100
101
102echo "$progname: ctfmerge should allow a .cc file to lack CTF"
103$ctf_cxx -c -o file3.o file3.cc
104ld -r -o files.o file1.o file3.o
105$ctf_merge -o files.o file1.o file3.o
106ld -r -o files.o file1.o file3.o
107$ctf_merge -m -o files.o file1.o file3.o
108
109echo "$progname: ctfmerge should allow an .s file to lack CTF"
110$ctf_as -o file4.o file4.s
111ld -r -o files.o file4.o file1.o
112$ctf_merge -o files.o file4.o file1.o
113ld -r -o files.o file4.o file1.o
114$ctf_merge -m -o files.o file4.o file1.o
115
116echo "result is $result"
117exit $result
118