1303980Sngie# $NetBSD: t_section.sh,v 1.4 2015/02/17 11:51:04 martin Exp $ 2303980Sngie# 3303980Sngie# Copyright (c) 2014 The NetBSD Foundation, Inc. 4303980Sngie# All rights reserved. 5303980Sngie# 6303980Sngie# Redistribution and use in source and binary forms, with or without 7303980Sngie# modification, are permitted provided that the following conditions 8303980Sngie# are met: 9303980Sngie# 1. Redistributions of source code must retain the above copyright 10303980Sngie# notice, this list of conditions and the following disclaimer. 11303980Sngie# 2. Redistributions in binary form must reproduce the above copyright 12303980Sngie# notice, this list of conditions and the following disclaimer in the 13303980Sngie# documentation and/or other materials provided with the distribution. 14303980Sngie# 15303980Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16303980Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17303980Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18303980Sngie# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19303980Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20303980Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21303980Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22303980Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23303980Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24303980Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25303980Sngie# POSSIBILITY OF SUCH DAMAGE. 26303980Sngie# 27303980Sngie 28303980Sngie################################################################################ 29303980Sngie 30303980Sngieatf_test_case startstop 31303980Sngiestartstop_head() { 32303980Sngie atf_set "descr" "check if __start_*/__stop_* symbols are generated" 33303980Sngie atf_set "require.progs" "cc" 34303980Sngie} 35303980Sngie 36303980Sngiestartstop_body() { 37303980Sngie cat > test.c << EOF 38303980Sngie#include <sys/cdefs.h> 39303980Sngieint i __section("hoge"); 40303980Sngieextern int __start_hoge[], __stop_hoge[]; 41303980Sngieint main(void) { return __start_hoge[0] + __stop_hoge[0]; } 42303980SngieEOF 43303980Sngie atf_check -s exit:0 -o ignore -e ignore cc -o test test.c 44303980Sngie} 45303980Sngie 46303980Sngie################################################################################ 47303980Sngie 48303980Sngieatf_test_case orphan 49303980Sngieorphan_head() { 50303980Sngie atf_set "descr" "check orphan section placement" 51303980Sngie atf_set "require.progs" "cc" "readelf" "grep" 52303980Sngie} 53303980Sngie 54303980Sngieorphan_body() { 55303980Sngie cat > test.c << EOF 56303980Sngie#include <sys/cdefs.h> 57303980Sngie/* read-only orphan */ 58303980Sngieconst char a[] __section("hoge") = "hoge"; 59303980Sngie/* read-write orphan */ 60303980Sngiechar b[] __section("fuga") = { 'f', 'u', 'g', 'a', '\0' }; 61303980Sngie/* .data */ 62303980Sngieint c[1024] = { 123, 20, 1, 0 }; 63303980Sngie/* .bss */ 64303980Sngieint d = 0; 65303980Sngie/* .text */ 66303980Sngieint main(void) { return 0; } 67303980SngieEOF 68303980Sngie atf_check -s exit:0 -o ignore -e ignore cc -o test test.c 69303980Sngie readelf -S test | 70303980Sngie grep ' \.text\| hoge\| \.data\| fuga\| \.bss' >test.secs 71303980Sngie { 72303980Sngie # Read-only orphan sections are placed after well-known 73303980Sngie # read-only sections (.text, .rodata) but before .data. 74303980Sngie match ".text" && 75303980Sngie match "hoge" && 76303980Sngie # Read-write orphan sections are placed after well-known 77303980Sngie # read-write sections (.data) but before .bss. 78303980Sngie match ".data" && 79303980Sngie match "fuga" && 80303980Sngie match ".bss" && 81303980Sngie : 82303980Sngie } < test.secs 83303980Sngie atf_check test "$?" -eq 0 84303980Sngie} 85303980Sngie 86303980Sngiematch() { 87303980Sngie read line 88303980Sngie case "$line" in 89303980Sngie *"$1"*) return 0; 90303980Sngie esac 91303980Sngie return 1 92303980Sngie} 93303980Sngie 94303980Sngie################################################################################ 95303980Sngie 96303980Sngieatf_init_test_cases() 97303980Sngie{ 98303980Sngie atf_add_test_case startstop 99303980Sngie atf_add_test_case orphan 100303980Sngie} 101