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