Home | History | Annotate | Line # | Download | only in ld
t_script.sh revision 1.1
      1  1.1  uebayasi #	$NetBSD: t_script.sh,v 1.1 2014/11/14 09:03:39 uebayasi Exp $
      2  1.1  uebayasi #
      3  1.1  uebayasi # Copyright (c) 2014 The NetBSD Foundation, Inc.
      4  1.1  uebayasi # All rights reserved.
      5  1.1  uebayasi #
      6  1.1  uebayasi # Redistribution and use in source and binary forms, with or without
      7  1.1  uebayasi # modification, are permitted provided that the following conditions
      8  1.1  uebayasi # are met:
      9  1.1  uebayasi # 1. Redistributions of source code must retain the above copyright
     10  1.1  uebayasi #    notice, this list of conditions and the following disclaimer.
     11  1.1  uebayasi # 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  uebayasi #    notice, this list of conditions and the following disclaimer in the
     13  1.1  uebayasi #    documentation and/or other materials provided with the distribution.
     14  1.1  uebayasi #
     15  1.1  uebayasi # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16  1.1  uebayasi # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17  1.1  uebayasi # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18  1.1  uebayasi # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19  1.1  uebayasi # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20  1.1  uebayasi # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21  1.1  uebayasi # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22  1.1  uebayasi # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23  1.1  uebayasi # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24  1.1  uebayasi # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  1.1  uebayasi # POSSIBILITY OF SUCH DAMAGE.
     26  1.1  uebayasi #
     27  1.1  uebayasi 
     28  1.1  uebayasi atf_test_case multisec
     29  1.1  uebayasi multisec_head() {
     30  1.1  uebayasi 	atf_set "descr" "check if multiple SECTIONS commands work"
     31  1.1  uebayasi 	atf_set "require.progs" "cc" "ld" "readelf" "nm" "sed" "grep"
     32  1.1  uebayasi }
     33  1.1  uebayasi 
     34  1.1  uebayasi multisec_body() {
     35  1.1  uebayasi 	cat > test.c << EOF
     36  1.1  uebayasi #include <sys/cdefs.h>
     37  1.1  uebayasi char a __section(".data.a") = 'a';
     38  1.1  uebayasi char b __section(".data.b") = 'b';
     39  1.1  uebayasi char c __section(".data.c") = 'c';
     40  1.1  uebayasi EOF
     41  1.1  uebayasi 	atf_check -s exit:0 -o ignore -e ignore cc -c test.c
     42  1.1  uebayasi 
     43  1.1  uebayasi 	cat > test.x << EOF
     44  1.1  uebayasi SECTIONS {
     45  1.1  uebayasi 	.data : {
     46  1.1  uebayasi 		*(.data)
     47  1.1  uebayasi 		*(.data.a)
     48  1.1  uebayasi 	}
     49  1.1  uebayasi }
     50  1.1  uebayasi SECTIONS {
     51  1.1  uebayasi 	.data : {
     52  1.1  uebayasi 		*(.data)
     53  1.1  uebayasi 		*(.data.b)
     54  1.1  uebayasi 	}
     55  1.1  uebayasi }
     56  1.1  uebayasi EOF
     57  1.1  uebayasi 	atf_check -s exit:0 -o ignore -e ignore \
     58  1.1  uebayasi 	    ld -r -T test.x -Map test.map -o test.ro test.o
     59  1.1  uebayasi 	extract_section_names test.ro >test.secs
     60  1.1  uebayasi 	extract_symbol_names test.ro >test.syms
     61  1.1  uebayasi 	atf_check -s exit:1 -o ignore -e ignore \
     62  1.1  uebayasi 	    grep '\.data\.a$' test.secs
     63  1.1  uebayasi 	atf_check -s exit:1 -o ignore -e ignore \
     64  1.1  uebayasi 	    grep '\.data\.b$' test.secs
     65  1.1  uebayasi 	atf_check -s exit:0 -o ignore -e ignore \
     66  1.1  uebayasi 	    grep '\.data\.c$' test.secs
     67  1.1  uebayasi }
     68  1.1  uebayasi 
     69  1.1  uebayasi extract_section_names() {
     70  1.1  uebayasi 	readelf -S "$1" |
     71  1.1  uebayasi 	sed -ne '/\] \./ { s/^.*\] //; s/ .*$//; p }'
     72  1.1  uebayasi }
     73  1.1  uebayasi 
     74  1.1  uebayasi extract_symbol_names() {
     75  1.1  uebayasi 	nm -n "$1" |
     76  1.1  uebayasi 	sed -e 's/^.* //'
     77  1.1  uebayasi }
     78  1.1  uebayasi 
     79  1.1  uebayasi atf_init_test_cases()
     80  1.1  uebayasi {
     81  1.1  uebayasi 
     82  1.1  uebayasi 	atf_add_test_case multisec
     83  1.1  uebayasi }
     84