xref: /titanic_51/usr/src/cmd/sgs/test/ld/assert-deflib/test-deflib.sh (revision b533f56bf95137d3de6666bd923e15ec373ea611)
1*b533f56bSRobert Mustacchi#!/bin/bash
2*b533f56bSRobert Mustacchi#
3*b533f56bSRobert Mustacchi# This file and its contents are supplied under the terms of the
4*b533f56bSRobert Mustacchi# Common Development and Distribution License ("CDDL"), version 1.0.
5*b533f56bSRobert Mustacchi# You may only use this file in accordance with the terms of version
6*b533f56bSRobert Mustacchi# 1.0 of the CDDL.
7*b533f56bSRobert Mustacchi#
8*b533f56bSRobert Mustacchi# A full copy of the text of the CDDL should have accompanied this
9*b533f56bSRobert Mustacchi# source.  A copy of the CDDL is also available via the Internet at
10*b533f56bSRobert Mustacchi# http://www.illumos.org/license/CDDL.
11*b533f56bSRobert Mustacchi#
12*b533f56bSRobert Mustacchi
13*b533f56bSRobert Mustacchi#
14*b533f56bSRobert Mustacchi# Copyright (c) 2012, Joyent, Inc.
15*b533f56bSRobert Mustacchi#
16*b533f56bSRobert Mustacchi
17*b533f56bSRobert Mustacchi#
18*b533f56bSRobert Mustacchi# This test validates that the -zassert-deflib option of ld(1) works correctly.
19*b533f56bSRobert Mustacchi# It requires that some cc is in your path and that you have passed in the path
20*b533f56bSRobert Mustacchi# to the proto area with the new version of libld.so.4. One thing that we have
21*b533f56bSRobert Mustacchi# to do is be careful with using LD_LIBRARY_PATH. Setting LD_LIBRARY_PATH does
22*b533f56bSRobert Mustacchi# not change the default search path so we want to make sure that we use a
23*b533f56bSRobert Mustacchi# different ISA (e.g. 32-bit vs 64-bit) from the binary we're generating.
24*b533f56bSRobert Mustacchi#
25*b533f56bSRobert Mustacchiunalias -a
26*b533f56bSRobert Mustacchi
27*b533f56bSRobert Mustacchish_path=
28*b533f56bSRobert Mustacchish_lib="lib"
29*b533f56bSRobert Mustacchish_lib64="$sh_lib/64"
30*b533f56bSRobert Mustacchish_soname="libld.so.4"
31*b533f56bSRobert Mustacchish_cc="cc"
32*b533f56bSRobert Mustacchish_cflags="-m32"
33*b533f56bSRobert Mustacchish_file="link.c"
34*b533f56bSRobert Mustacchish_arg0=$(basename $0)
35*b533f56bSRobert Mustacchi
36*b533f56bSRobert Mustacchifunction fatal
37*b533f56bSRobert Mustacchi{
38*b533f56bSRobert Mustacchi        local msg="$*"
39*b533f56bSRobert Mustacchi        [[ -z "$msg" ]] && msg="failed"
40*b533f56bSRobert Mustacchi        echo "$sh_arg0: $msg" >&2
41*b533f56bSRobert Mustacchi        exit 1
42*b533f56bSRobert Mustacchi}
43*b533f56bSRobert Mustacchi
44*b533f56bSRobert Mustacchi
45*b533f56bSRobert Mustacchi#
46*b533f56bSRobert Mustacchi# Validate that everything we need is in our path. That includes having cc
47*b533f56bSRobert Mustacchi# and the proto area libld.
48*b533f56bSRobert Mustacchi#
49*b533f56bSRobert Mustacchifunction validate
50*b533f56bSRobert Mustacchi{
51*b533f56bSRobert Mustacchi	[[ -f $sh_path/$sh_lib/$sh_soname ]] || fatal "missing 32-bit $sh_soname"
52*b533f56bSRobert Mustacchi	[[ -f $sh_path/$sh_lib64/$sh_soname ]] ||
53*b533f56bSRobert Mustacchi	    fatal "missing 64-bit $sh_soname"
54*b533f56bSRobert Mustacchi	which $sh_cc >/dev/null || fatal "cc not in path"
55*b533f56bSRobert Mustacchi}
56*b533f56bSRobert Mustacchi
57*b533f56bSRobert Mustacchi#
58*b533f56bSRobert Mustacchi# $1 is a series of flags to append
59*b533f56bSRobert Mustacchi# $2 is expected exit status
60*b533f56bSRobert Mustacchi# $3 is pre-test message
61*b533f56bSRobert Mustacchi# $4 is the failure message
62*b533f56bSRobert Mustacchi#
63*b533f56bSRobert Mustacchifunction run
64*b533f56bSRobert Mustacchi{
65*b533f56bSRobert Mustacchi	local ret
66*b533f56bSRobert Mustacchi
67*b533f56bSRobert Mustacchi	echo $3
68*b533f56bSRobert Mustacchi	LD_LIBRARY_PATH_64="$sh_path/$sh_lib64" $sh_cc $sh_cflags $sh_file $1
69*b533f56bSRobert Mustacchi	if [[ $? -eq $2 ]]; then
70*b533f56bSRobert Mustacchi		printf "success\n\n"
71*b533f56bSRobert Mustacchi	else
72*b533f56bSRobert Mustacchi		fatal $4
73*b533f56bSRobert Mustacchi	fi
74*b533f56bSRobert Mustacchi}
75*b533f56bSRobert Mustacchi
76*b533f56bSRobert Mustacchish_path=$1
77*b533f56bSRobert Mustacchi[[ -z "$1" ]] && fatal "<proto root>"
78*b533f56bSRobert Mustacchivalidate
79*b533f56bSRobert Mustacchi
80*b533f56bSRobert Mustacchirun "-Wl,-zassert-deflib" 0 \
81*b533f56bSRobert Mustacchi    "Testing basic compilation succeeds with warnings..." \
82*b533f56bSRobert Mustacchi    "failed to compile with warnings"
83*b533f56bSRobert Mustacchi
84*b533f56bSRobert Mustacchirun "-Wl,-zassert-deflib -Wl,-zfatal-warnings" 1 \
85*b533f56bSRobert Mustacchi    "Testing basic compilation fails if warning are fatal..." \
86*b533f56bSRobert Mustacchi    "linking succeeeded, expected failure"
87*b533f56bSRobert Mustacchi
88*b533f56bSRobert Mustacchirun "-Wl,-zassert-deflib=libc.so -Wl,-zfatal-warnings" 0 \
89*b533f56bSRobert Mustacchi    "Testing basic exception with fatal warnings..." \
90*b533f56bSRobert Mustacchi    "linking failed despite exception"
91*b533f56bSRobert Mustacchi
92*b533f56bSRobert Mustacchirun "-Wl,-zassert-deflib=libc.so -Wl,-zfatal-warnings" 0 \
93*b533f56bSRobert Mustacchi    "Testing basic exception with fatal warnings..." \
94*b533f56bSRobert Mustacchi    "linking failed despite exception"
95*b533f56bSRobert Mustacchi
96*b533f56bSRobert Mustacchi
97*b533f56bSRobert Mustacchirun "-Wl,-zassert-deflib=lib.so -Wl,-zfatal-warnings" 1 \
98*b533f56bSRobert Mustacchi    "Testing invalid library name..." \
99*b533f56bSRobert Mustacchi    "ld should not allow invalid library name"
100*b533f56bSRobert Mustacchi
101*b533f56bSRobert Mustacchirun "-Wl,-zassert-deflib=libf -Wl,-zfatal-warnings" 1 \
102*b533f56bSRobert Mustacchi    "Testing invalid library name..." \
103*b533f56bSRobert Mustacchi    "ld should not allow invalid library name"
104*b533f56bSRobert Mustacchi
105*b533f56bSRobert Mustacchirun "-Wl,-zassert-deflib=libf.s -Wl,-zfatal-warnings" 1 \
106*b533f56bSRobert Mustacchi    "Testing invalid library name..." \
107*b533f56bSRobert Mustacchi    "ld should not allow invalid library name"
108*b533f56bSRobert Mustacchi
109*b533f56bSRobert Mustacchirun "-Wl,-zassert-deflib=libc.so -Wl,-zfatal-warnings -lelf" 1 \
110*b533f56bSRobert Mustacchi    "Errors even if one library is under exception path..." \
111*b533f56bSRobert Mustacchi    "one exception shouldn't stop another"
112*b533f56bSRobert Mustacchi
113*b533f56bSRobert Mustacchiargs="-Wl,-zassert-deflib=libc.so -Wl,-zassert-deflib=libelf.so"
114*b533f56bSRobert Mustacchiargs="$args -Wl,-zfatal-warnings -lelf"
115*b533f56bSRobert Mustacchi
116*b533f56bSRobert Mustacchirun "$args" 0 \
117*b533f56bSRobert Mustacchi    "Multiple exceptions work..." \
118*b533f56bSRobert Mustacchi    "multiple exceptions don't work"
119*b533f56bSRobert Mustacchi
120*b533f56bSRobert Mustacchiargs="-Wl,-zassert-deflib=libc.so -Wl,-zassert-deflib=libelfe.so"
121*b533f56bSRobert Mustacchiargs="$args -Wl,-zfatal-warnings -lelf"
122*b533f56bSRobert Mustacchi
123*b533f56bSRobert Mustacchirun "$args" 1 \
124*b533f56bSRobert Mustacchi    "Exceptions only catch the specific library" \
125*b533f56bSRobert Mustacchi    "exceptions caught the wrong library"
126*b533f56bSRobert Mustacchi
127*b533f56bSRobert Mustacchiargs="-Wl,-zassert-deflib=libc.so -Wl,-zassert-deflib=libel.so"
128*b533f56bSRobert Mustacchiargs="$args -Wl,-zfatal-warnings -lelf"
129*b533f56bSRobert Mustacchi
130*b533f56bSRobert Mustacchirun "$args" 1 \
131*b533f56bSRobert Mustacchi    "Exceptions only catch the specific library" \
132*b533f56bSRobert Mustacchi    "exceptions caught the wrong library"
133*b533f56bSRobert Mustacchi
134*b533f56bSRobert Mustacchiecho "Tests passed."
135*b533f56bSRobert Mustacchiexit 0
136