Print this page
10367 ld(1) tests should be a real test suite
10368 want an ld(1) regression test for i386 LD tls transition (10267)


   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 #
  14 # Copyright (c) 2012, Joyent, Inc.
  15 #
  16 
  17 #
  18 # This test validates that the -zassert-deflib option of ld(1) works correctly.
  19 # It requires that some cc is in your path and that you have passed in the path
  20 # to the proto area with the new version of libld.so.4. One thing that we have
  21 # to do is be careful with using LD_LIBRARY_PATH. Setting LD_LIBRARY_PATH does
  22 # not change the default search path so we want to make sure that we use a
  23 # different ISA (e.g. 32-bit vs 64-bit) from the binary we're generating.
  24 #
  25 unalias -a
  26 


  27 sh_path=
  28 sh_lib="lib"
  29 sh_lib64="$sh_lib/64"
  30 sh_soname="libld.so.4"
  31 sh_cc="cc"
  32 sh_cflags="-m32"
  33 sh_file="link.c"
  34 sh_arg0=$(basename $0)
  35 
  36 function fatal
  37 {
  38         local msg="$*"
  39         [[ -z "$msg" ]] && msg="failed"
  40         echo "$sh_arg0: $msg" >&2
  41         exit 1
  42 }
  43 
  44 
  45 #
  46 # Validate that everything we need is in our path. That includes having cc
  47 # and the proto area libld.
  48 #
  49 function validate
  50 {
  51         [[ -f $sh_path/$sh_lib/$sh_soname ]] || fatal "missing 32-bit $sh_soname"
  52         [[ -f $sh_path/$sh_lib64/$sh_soname ]] ||
  53             fatal "missing 64-bit $sh_soname"


  56 
  57 #
  58 # $1 is a series of flags to append
  59 # $2 is expected exit status
  60 # $3 is pre-test message
  61 # $4 is the failure message
  62 #
  63 function run
  64 {
  65         local ret
  66 
  67         echo $3
  68         LD_LIBRARY_PATH_64="$sh_path/$sh_lib64" $sh_cc $sh_cflags $sh_file $1
  69         if [[ $? -eq $2 ]]; then
  70                 printf "success\n\n"
  71         else
  72                 fatal $4
  73         fi
  74 }
  75 
  76 sh_path=$1
  77 [[ -z "$1" ]] && fatal "<proto root>"
  78 validate
  79 
  80 run "-Wl,-zassert-deflib" 0 \
  81     "Testing basic compilation succeeds with warnings..." \
  82     "failed to compile with warnings"
  83 
  84 run "-Wl,-zassert-deflib -Wl,-zfatal-warnings" 1 \
  85     "Testing basic compilation fails if warning are fatal..." \
  86     "linking succeeeded, expected failure"
  87 
  88 run "-Wl,-zassert-deflib=libc.so -Wl,-zfatal-warnings" 0 \
  89     "Testing basic exception with fatal warnings..." \
  90     "linking failed despite exception"
  91 
  92 run "-Wl,-zassert-deflib=libc.so -Wl,-zfatal-warnings" 0 \
  93     "Testing basic exception with fatal warnings..." \
  94     "linking failed despite exception"
  95 
  96 
  97 run "-Wl,-zassert-deflib=lib.so -Wl,-zfatal-warnings" 1 \




   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 #
  14 # Copyright (c) 2012, Joyent, Inc.
  15 #
  16 
  17 #
  18 # This test validates that the -zassert-deflib option of ld(1) works correctly.
  19 # It requires that some cc is in your path and that you have passed in the path
  20 # to the proto area with the new version of libld.so.4. One thing that we have
  21 # to do is be careful with using LD_LIBRARY_PATH. Setting LD_LIBRARY_PATH does
  22 # not change the default search path so we want to make sure that we use a
  23 # different ISA (e.g. 32-bit vs 64-bit) from the binary we're generating.
  24 #
  25 unalias -a
  26 
  27 TESTDIR=$(dirname $0)
  28 
  29 sh_path=
  30 sh_lib="lib"
  31 sh_lib64="$sh_lib/64"
  32 sh_soname="libld.so.4"
  33 sh_cc="gcc"
  34 sh_cflags="-m32"
  35 sh_file="${TESTDIR}/link.c"
  36 sh_arg0=$(basename $0)
  37 
  38 function fatal
  39 {
  40         local msg="$*"
  41         [[ -z "$msg" ]] && msg="failed"
  42         echo "$sh_arg0: $msg" >&2
  43         exit 1
  44 }
  45 
  46 
  47 #
  48 # Validate that everything we need is in our path. That includes having cc
  49 # and the proto area libld.
  50 #
  51 function validate
  52 {
  53         [[ -f $sh_path/$sh_lib/$sh_soname ]] || fatal "missing 32-bit $sh_soname"
  54         [[ -f $sh_path/$sh_lib64/$sh_soname ]] ||
  55             fatal "missing 64-bit $sh_soname"


  58 
  59 #
  60 # $1 is a series of flags to append
  61 # $2 is expected exit status
  62 # $3 is pre-test message
  63 # $4 is the failure message
  64 #
  65 function run
  66 {
  67         local ret
  68 
  69         echo $3
  70         LD_LIBRARY_PATH_64="$sh_path/$sh_lib64" $sh_cc $sh_cflags $sh_file $1
  71         if [[ $? -eq $2 ]]; then
  72                 printf "success\n\n"
  73         else
  74                 fatal $4
  75         fi
  76 }
  77 
  78 sh_path=${1:-/}

  79 validate
  80 
  81 run "-Wl,-zassert-deflib" 0 \
  82     "Testing basic compilation succeeds with warnings..." \
  83     "failed to compile with warnings"
  84 
  85 run "-Wl,-zassert-deflib -Wl,-zfatal-warnings" 1 \
  86     "Testing basic compilation fails if warning are fatal..." \
  87     "linking succeeeded, expected failure"
  88 
  89 run "-Wl,-zassert-deflib=libc.so -Wl,-zfatal-warnings" 0 \
  90     "Testing basic exception with fatal warnings..." \
  91     "linking failed despite exception"
  92 
  93 run "-Wl,-zassert-deflib=libc.so -Wl,-zfatal-warnings" 0 \
  94     "Testing basic exception with fatal warnings..." \
  95     "linking failed despite exception"
  96 
  97 
  98 run "-Wl,-zassert-deflib=lib.so -Wl,-zfatal-warnings" 1 \