Home | History | Annotate | Line # | Download | only in ld.elf_so
      1 #	$NetBSD: t_r_rel.sh,v 1.2 2025/05/02 23:03:16 riastradh Exp $
      2 #
      3 # Copyright (c) 2025 The NetBSD Foundation, Inc.
      4 # All rights reserved.
      5 #
      6 # Redistribution and use in source and binary forms, with or without
      7 # modification, are permitted provided that the following conditions
      8 # are met:
      9 # 1. Redistributions of source code must retain the above copyright
     10 #    notice, this list of conditions and the following disclaimer.
     11 # 2. Redistributions in binary form must reproduce the above copyright
     12 #    notice, this list of conditions and the following disclaimer in the
     13 #    documentation and/or other materials provided with the distribution.
     14 #
     15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25 # POSSIBILITY OF SUCH DAMAGE.
     26 #
     27 
     28 cleanup_core()
     29 {
     30 	local prog
     31 
     32 	prog=$1
     33 	test -f "${prog}.core" || return
     34 	readelf -rs "$(atf_get_srcdir)/${prog}"
     35 	gdb -batch -ex bt -ex 'info registers' -ex disas \
     36 	    "$(atf_get_srcdir)/${prog}" "${prog}.core"
     37 }
     38 
     39 atf_test_case readelf_relative_nopack
     40 readelf_relative_nopack_head()
     41 {
     42 	atf_set "descr" "readelf R_*_RELATIVE with -z nopack-relative-relocs"
     43 	atf_set "require.progs" "readelf"
     44 }
     45 readelf_relative_nopack_body()
     46 {
     47 	atf_check -o match:'R_.*_REL' \
     48 	    readelf -r "$(atf_get_srcdir)"/h_r_rel_nopack
     49 }
     50 
     51 atf_test_case readelf_relative_pack
     52 readelf_relative_pack_head()
     53 {
     54 	atf_set "descr" "readelf R_*_RELATIVE with -z pack-relative-relocs"
     55 	atf_set "require.progs" "readelf"
     56 }
     57 readelf_relative_pack_body()
     58 {
     59 	case `uname -p` in
     60 	i386|powerpc64*|x86_64)
     61 		;;
     62 	*)	# Actually missing GNU binutils ld(1) support.
     63 		atf_expect_fail "PR bin/59360: ld.elf_so(8):" \
     64 		    " missing RELR support"
     65 		;;
     66 	esac
     67 	atf_check -o not-match:'R_.*_REL' \
     68 	    readelf -r "$(atf_get_srcdir)"/h_r_rel_pack
     69 }
     70 
     71 atf_test_case run_relative_nopack cleanup
     72 run_relative_nopack_head()
     73 {
     74 	atf_set "descr" "run R_*_RELATIVE with -z nopack-relative-relocs"
     75 }
     76 run_relative_nopack_body()
     77 {
     78 	atf_check "$(atf_get_srcdir)"/h_r_rel_nopack
     79 }
     80 run_relative_nopack_cleanup()
     81 {
     82 	cleanup_core h_r_rel_nopack
     83 }
     84 
     85 atf_test_case run_relative_pack cleanup
     86 run_relative_pack_head()
     87 {
     88 	atf_set "descr" "run R_*_RELATIVE with -z pack-relative-relocs"
     89 }
     90 run_relative_pack_body()
     91 {
     92 	case `uname -p` in
     93 	i386|powerpc64*|x86_64)
     94 		;;
     95 	*)	# Missing GNU binutils ld(1) support to generate RELR
     96 		# sections, so the program should run just fine because
     97 		# it just uses traditional REL/RELA instead.
     98 		;;
     99 	esac
    100 	atf_check "$(atf_get_srcdir)"/h_r_rel_pack
    101 }
    102 run_relative_pack_cleanup()
    103 {
    104 	cleanup_core h_r_rel_pack
    105 }
    106 
    107 atf_init_test_cases()
    108 {
    109 	atf_add_test_case readelf_relative_nopack
    110 	atf_add_test_case readelf_relative_pack
    111 	atf_add_test_case run_relative_nopack
    112 	atf_add_test_case run_relative_pack
    113 }
    114