1*640235e2SEnji Cooper# $NetBSD: t_section.sh,v 1.4 2015/02/17 11:51:04 martin Exp $ 2*640235e2SEnji Cooper# 3*640235e2SEnji Cooper# Copyright (c) 2014 The NetBSD Foundation, Inc. 4*640235e2SEnji Cooper# All rights reserved. 5*640235e2SEnji Cooper# 6*640235e2SEnji Cooper# Redistribution and use in source and binary forms, with or without 7*640235e2SEnji Cooper# modification, are permitted provided that the following conditions 8*640235e2SEnji Cooper# are met: 9*640235e2SEnji Cooper# 1. Redistributions of source code must retain the above copyright 10*640235e2SEnji Cooper# notice, this list of conditions and the following disclaimer. 11*640235e2SEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright 12*640235e2SEnji Cooper# notice, this list of conditions and the following disclaimer in the 13*640235e2SEnji Cooper# documentation and/or other materials provided with the distribution. 14*640235e2SEnji Cooper# 15*640235e2SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16*640235e2SEnji Cooper# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17*640235e2SEnji Cooper# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18*640235e2SEnji Cooper# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19*640235e2SEnji Cooper# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20*640235e2SEnji Cooper# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21*640235e2SEnji Cooper# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22*640235e2SEnji Cooper# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23*640235e2SEnji Cooper# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24*640235e2SEnji Cooper# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25*640235e2SEnji Cooper# POSSIBILITY OF SUCH DAMAGE. 26*640235e2SEnji Cooper# 27*640235e2SEnji Cooper 28*640235e2SEnji Cooper################################################################################ 29*640235e2SEnji Cooper 30*640235e2SEnji Cooperatf_test_case startstop 31*640235e2SEnji Cooperstartstop_head() { 32*640235e2SEnji Cooper atf_set "descr" "check if __start_*/__stop_* symbols are generated" 33*640235e2SEnji Cooper atf_set "require.progs" "cc" 34*640235e2SEnji Cooper} 35*640235e2SEnji Cooper 36*640235e2SEnji Cooperstartstop_body() { 37*640235e2SEnji Cooper cat > test.c << EOF 38*640235e2SEnji Cooper#include <sys/cdefs.h> 39*640235e2SEnji Cooperint i __section("hoge"); 40*640235e2SEnji Cooperextern int __start_hoge[], __stop_hoge[]; 41*640235e2SEnji Cooperint main(void) { return __start_hoge[0] + __stop_hoge[0]; } 42*640235e2SEnji CooperEOF 43*640235e2SEnji Cooper atf_check -s exit:0 -o ignore -e ignore cc -o test test.c 44*640235e2SEnji Cooper} 45*640235e2SEnji Cooper 46*640235e2SEnji Cooper################################################################################ 47*640235e2SEnji Cooper 48*640235e2SEnji Cooperatf_test_case orphan 49*640235e2SEnji Cooperorphan_head() { 50*640235e2SEnji Cooper atf_set "descr" "check orphan section placement" 51*640235e2SEnji Cooper atf_set "require.progs" "cc" "readelf" "grep" 52*640235e2SEnji Cooper} 53*640235e2SEnji Cooper 54*640235e2SEnji Cooperorphan_body() { 55*640235e2SEnji Cooper cat > test.c << EOF 56*640235e2SEnji Cooper#include <sys/cdefs.h> 57*640235e2SEnji Cooper/* read-only orphan */ 58*640235e2SEnji Cooperconst char a[] __section("hoge") = "hoge"; 59*640235e2SEnji Cooper/* read-write orphan */ 60*640235e2SEnji Cooperchar b[] __section("fuga") = { 'f', 'u', 'g', 'a', '\0' }; 61*640235e2SEnji Cooper/* .data */ 62*640235e2SEnji Cooperint c[1024] = { 123, 20, 1, 0 }; 63*640235e2SEnji Cooper/* .bss */ 64*640235e2SEnji Cooperint d = 0; 65*640235e2SEnji Cooper/* .text */ 66*640235e2SEnji Cooperint main(void) { return 0; } 67*640235e2SEnji CooperEOF 68*640235e2SEnji Cooper atf_check -s exit:0 -o ignore -e ignore cc -o test test.c 69*640235e2SEnji Cooper readelf -S test | 70*640235e2SEnji Cooper grep ' \.text\| hoge\| \.data\| fuga\| \.bss' >test.secs 71*640235e2SEnji Cooper { 72*640235e2SEnji Cooper # Read-only orphan sections are placed after well-known 73*640235e2SEnji Cooper # read-only sections (.text, .rodata) but before .data. 74*640235e2SEnji Cooper match ".text" && 75*640235e2SEnji Cooper match "hoge" && 76*640235e2SEnji Cooper # Read-write orphan sections are placed after well-known 77*640235e2SEnji Cooper # read-write sections (.data) but before .bss. 78*640235e2SEnji Cooper match ".data" && 79*640235e2SEnji Cooper match "fuga" && 80*640235e2SEnji Cooper match ".bss" && 81*640235e2SEnji Cooper : 82*640235e2SEnji Cooper } < test.secs 83*640235e2SEnji Cooper atf_check test "$?" -eq 0 84*640235e2SEnji Cooper} 85*640235e2SEnji Cooper 86*640235e2SEnji Coopermatch() { 87*640235e2SEnji Cooper read line 88*640235e2SEnji Cooper case "$line" in 89*640235e2SEnji Cooper *"$1"*) return 0; 90*640235e2SEnji Cooper esac 91*640235e2SEnji Cooper return 1 92*640235e2SEnji Cooper} 93*640235e2SEnji Cooper 94*640235e2SEnji Cooper################################################################################ 95*640235e2SEnji Cooper 96*640235e2SEnji Cooperatf_init_test_cases() 97*640235e2SEnji Cooper{ 98*640235e2SEnji Cooper atf_add_test_case startstop 99*640235e2SEnji Cooper atf_add_test_case orphan 100*640235e2SEnji Cooper} 101