t_section.sh revision 1.5
11.5Sskrll# $NetBSD: t_section.sh,v 1.5 2022/06/05 08:42:25 skrll Exp $ 21.1Suebayasi# 31.1Suebayasi# Copyright (c) 2014 The NetBSD Foundation, Inc. 41.1Suebayasi# All rights reserved. 51.1Suebayasi# 61.1Suebayasi# Redistribution and use in source and binary forms, with or without 71.1Suebayasi# modification, are permitted provided that the following conditions 81.1Suebayasi# are met: 91.1Suebayasi# 1. Redistributions of source code must retain the above copyright 101.1Suebayasi# notice, this list of conditions and the following disclaimer. 111.1Suebayasi# 2. Redistributions in binary form must reproduce the above copyright 121.1Suebayasi# notice, this list of conditions and the following disclaimer in the 131.1Suebayasi# documentation and/or other materials provided with the distribution. 141.1Suebayasi# 151.1Suebayasi# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 161.1Suebayasi# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 171.1Suebayasi# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 181.1Suebayasi# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 191.1Suebayasi# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 201.1Suebayasi# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 211.1Suebayasi# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 221.1Suebayasi# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 231.1Suebayasi# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 241.1Suebayasi# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 251.1Suebayasi# POSSIBILITY OF SUCH DAMAGE. 261.1Suebayasi# 271.1Suebayasi 281.3Suebayasi################################################################################ 291.3Suebayasi 301.1Suebayasiatf_test_case startstop 311.1Suebayasistartstop_head() { 321.1Suebayasi atf_set "descr" "check if __start_*/__stop_* symbols are generated" 331.1Suebayasi atf_set "require.progs" "cc" 341.1Suebayasi} 351.1Suebayasi 361.1Suebayasistartstop_body() { 371.1Suebayasi cat > test.c << EOF 381.1Suebayasi#include <sys/cdefs.h> 391.1Suebayasiint i __section("hoge"); 401.1Suebayasiextern int __start_hoge[], __stop_hoge[]; 411.2Suebayasiint main(void) { return __start_hoge[0] + __stop_hoge[0]; } 421.1SuebayasiEOF 431.1Suebayasi atf_check -s exit:0 -o ignore -e ignore cc -o test test.c 441.1Suebayasi} 451.1Suebayasi 461.3Suebayasi################################################################################ 471.3Suebayasi 481.3Suebayasiatf_test_case orphan 491.3Suebayasiorphan_head() { 501.3Suebayasi atf_set "descr" "check orphan section placement" 511.3Suebayasi atf_set "require.progs" "cc" "readelf" "grep" 521.3Suebayasi} 531.3Suebayasi 541.3Suebayasiorphan_body() { 551.3Suebayasi cat > test.c << EOF 561.3Suebayasi#include <sys/cdefs.h> 571.3Suebayasi/* read-only orphan */ 581.3Suebayasiconst char a[] __section("hoge") = "hoge"; 591.3Suebayasi/* read-write orphan */ 601.3Suebayasichar b[] __section("fuga") = { 'f', 'u', 'g', 'a', '\0' }; 611.3Suebayasi/* .data */ 621.4Smartinint c[1024] = { 123, 20, 1, 0 }; 631.3Suebayasi/* .bss */ 641.3Suebayasiint d = 0; 651.3Suebayasi/* .text */ 661.3Suebayasiint main(void) { return 0; } 671.3SuebayasiEOF 681.3Suebayasi atf_check -s exit:0 -o ignore -e ignore cc -o test test.c 691.3Suebayasi readelf -S test | 701.5Sskrll grep ' \.text \| hoge \| \.data \| fuga \| \.bss ' >test.secs 711.3Suebayasi { 721.3Suebayasi # Read-only orphan sections are placed after well-known 731.3Suebayasi # read-only sections (.text, .rodata) but before .data. 741.3Suebayasi match ".text" && 751.3Suebayasi match "hoge" && 761.3Suebayasi # Read-write orphan sections are placed after well-known 771.3Suebayasi # read-write sections (.data) but before .bss. 781.3Suebayasi match ".data" && 791.3Suebayasi match "fuga" && 801.3Suebayasi match ".bss" && 811.3Suebayasi : 821.3Suebayasi } < test.secs 831.3Suebayasi atf_check test "$?" -eq 0 841.3Suebayasi} 851.3Suebayasi 861.3Suebayasimatch() { 871.3Suebayasi read line 881.3Suebayasi case "$line" in 891.3Suebayasi *"$1"*) return 0; 901.3Suebayasi esac 911.3Suebayasi return 1 921.3Suebayasi} 931.3Suebayasi 941.3Suebayasi################################################################################ 951.3Suebayasi 961.1Suebayasiatf_init_test_cases() 971.1Suebayasi{ 981.1Suebayasi atf_add_test_case startstop 991.3Suebayasi atf_add_test_case orphan 1001.1Suebayasi} 101