1 1.7 riastrad # $NetBSD: t_static_destructor.sh,v 1.7 2025/04/16 01:52:42 riastradh Exp $ 2 1.1 kamil # 3 1.1 kamil # Copyright (c) 2017 The NetBSD Foundation, Inc. 4 1.1 kamil # All rights reserved. 5 1.1 kamil # 6 1.1 kamil # This code is derived from software contributed to The NetBSD Foundation 7 1.1 kamil # by Kamil Rytarowski. 8 1.1 kamil # 9 1.1 kamil # Redistribution and use in source and binary forms, with or without 10 1.1 kamil # modification, are permitted provided that the following conditions 11 1.1 kamil # are met: 12 1.1 kamil # 1. Redistributions of source code must retain the above copyright 13 1.1 kamil # notice, this list of conditions and the following disclaimer. 14 1.1 kamil # 2. Redistributions in binary form must reproduce the above copyright 15 1.1 kamil # notice, this list of conditions and the following disclaimer in the 16 1.1 kamil # documentation and/or other materials provided with the distribution. 17 1.1 kamil # 18 1.1 kamil # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 1.1 kamil # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 1.1 kamil # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 1.1 kamil # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 1.1 kamil # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 1.1 kamil # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 1.1 kamil # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 1.1 kamil # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 1.1 kamil # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 1.1 kamil # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 1.1 kamil # POSSIBILITY OF SUCH DAMAGE. 29 1.1 kamil # 30 1.1 kamil 31 1.1 kamil atf_test_case static_destructor 32 1.1 kamil static_destructor_head() { 33 1.1 kamil atf_set "descr" "compile and run \"hello world\"" 34 1.1 kamil atf_set "require.progs" "c++" 35 1.1 kamil } 36 1.1 kamil 37 1.2 kamil atf_test_case static_destructor_profile 38 1.2 kamil static_destructor_profile_head() { 39 1.2 kamil atf_set "descr" "compile and run \"hello world\" with profiling option" 40 1.2 kamil atf_set "require.progs" "c++" 41 1.2 kamil } 42 1.2 kamil 43 1.2 kamil atf_test_case static_destructor_static 44 1.2 kamil static_destructor_static_head() { 45 1.2 kamil atf_set "descr" "compile and run \"hello world\" with static option" 46 1.2 kamil atf_set "require.progs" "c++" 47 1.2 kamil } 48 1.2 kamil 49 1.1 kamil atf_test_case static_destructor_pic 50 1.1 kamil static_destructor_pic_head() { 51 1.1 kamil atf_set "descr" "compile and run PIC \"hello world\"" 52 1.1 kamil atf_set "require.progs" "c++" 53 1.1 kamil } 54 1.1 kamil 55 1.2 kamil atf_test_case static_destructor_pic_32 56 1.2 kamil static_destructor_pic_32_head() { 57 1.2 kamil atf_set "descr" "compile and run 32-bit PIC \"hello world\"" 58 1.2 kamil atf_set "require.progs" "c++" 59 1.2 kamil } 60 1.2 kamil 61 1.2 kamil atf_test_case static_destructor_pic_profile 62 1.2 kamil static_destructor_pic_profile_head() { 63 1.2 kamil atf_set "descr" "compile and run PIC \"hello world\" with profiling option" 64 1.2 kamil atf_set "require.progs" "c++" 65 1.2 kamil } 66 1.2 kamil 67 1.2 kamil atf_test_case static_destructor_pic_profile_32 68 1.2 kamil static_destructor_pic_profile_32_head() { 69 1.2 kamil atf_set "descr" "compile and run 32-bit PIC \"hello world\" with profiling option" 70 1.2 kamil atf_set "require.progs" "c++" 71 1.2 kamil } 72 1.2 kamil 73 1.2 kamil atf_test_case static_destructor_profile_32 74 1.2 kamil static_destructor_profile_32_head() { 75 1.2 kamil atf_set "descr" "compile and run 32-bit \"hello world\" with profiling option" 76 1.2 kamil atf_set "require.progs" "c++" 77 1.2 kamil } 78 1.2 kamil 79 1.1 kamil atf_test_case static_destructor_pie 80 1.1 kamil static_destructor_pie_head() { 81 1.1 kamil atf_set "descr" "compile and run position independent (PIE) \"hello world\"" 82 1.1 kamil atf_set "require.progs" "c++" 83 1.1 kamil } 84 1.1 kamil 85 1.1 kamil atf_test_case static_destructor32 86 1.1 kamil static_destructor32_head() { 87 1.1 kamil atf_set "descr" "compile and run \"hello world\" for/in netbsd32 emulation" 88 1.1 kamil atf_set "require.progs" "c++ file diff cat" 89 1.1 kamil } 90 1.1 kamil 91 1.1 kamil static_destructor_body() { 92 1.1 kamil cat > test.cpp << EOF 93 1.1 kamil #include <iostream> 94 1.1 kamil struct A { 95 1.1 kamil int i; 96 1.1 kamil A(int i):i(i){std::cout << "CTOR A" << std::endl;} 97 1.1 kamil ~A() {std::cout << "DTOR A:" << i << std::endl;} 98 1.1 kamil }; 99 1.1 kamil struct B { 100 1.1 kamil A *m_a; 101 1.1 kamil B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;} 102 1.1 kamil ~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;} 103 1.1 kamil }; 104 1.1 kamil int main(void) {struct B b;return 0;} 105 1.1 kamil EOF 106 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello test.cpp 107 1.1 kamil atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello 108 1.1 kamil } 109 1.1 kamil 110 1.2 kamil static_destructor_profile_body() { 111 1.7 riastrad case `uname -m` in 112 1.7 riastrad riscv) atf_expect_fail "PR port-riscv/59301:" \ 113 1.7 riastrad " riscv: missing MKPROFILE=yes support" 114 1.7 riastrad ;; 115 1.7 riastrad esac 116 1.7 riastrad 117 1.2 kamil cat > test.cpp << EOF 118 1.2 kamil #include <iostream> 119 1.2 kamil struct A { 120 1.2 kamil int i; 121 1.2 kamil A(int i):i(i){std::cout << "CTOR A" << std::endl;} 122 1.2 kamil ~A() {std::cout << "DTOR A:" << i << std::endl;} 123 1.2 kamil }; 124 1.2 kamil struct B { 125 1.2 kamil A *m_a; 126 1.2 kamil B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;} 127 1.2 kamil ~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;} 128 1.2 kamil }; 129 1.2 kamil int main(void) {struct B b;return 0;} 130 1.2 kamil EOF 131 1.6 skrll atf_check -s exit:0 -o ignore -e ignore c++ -static -pg -o hello test.cpp 132 1.2 kamil atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello 133 1.2 kamil } 134 1.2 kamil 135 1.2 kamil static_destructor_profile_32_body() { 136 1.2 kamil # check whether this arch is 64bit 137 1.2 kamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 138 1.2 kamil atf_skip "this is not a 64 bit architecture" 139 1.2 kamil fi 140 1.2 kamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 141 1.2 kamil atf_skip "c++ -m32 not supported on this architecture" 142 1.2 kamil else 143 1.2 kamil if fgrep -q _LP64 ./def32; then 144 1.2 kamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 145 1.2 kamil fi 146 1.2 kamil fi 147 1.2 kamil 148 1.7 riastrad case `uname -m` in 149 1.7 riastrad riscv) atf_expect_fail "PR port-riscv/59301:" \ 150 1.7 riastrad " riscv: missing MKPROFILE=yes support" 151 1.7 riastrad ;; 152 1.7 riastrad esac 153 1.7 riastrad 154 1.2 kamil cat > test.cpp << EOF 155 1.2 kamil #include <iostream> 156 1.2 kamil struct A { 157 1.2 kamil int i; 158 1.2 kamil A(int i):i(i){std::cout << "CTOR A" << std::endl;} 159 1.2 kamil ~A() {std::cout << "DTOR A:" << i << std::endl;} 160 1.2 kamil }; 161 1.2 kamil struct B { 162 1.2 kamil A *m_a; 163 1.2 kamil B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;} 164 1.2 kamil ~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;} 165 1.2 kamil }; 166 1.2 kamil int main(void) {struct B b;return 0;} 167 1.2 kamil EOF 168 1.6 skrll atf_check -s exit:0 -o ignore -e ignore c++ -static -m32 -pg -o hello test.cpp 169 1.2 kamil atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello 170 1.2 kamil } 171 1.2 kamil 172 1.2 kamil 173 1.2 kamil static_destructor_static_body() { 174 1.2 kamil cat > test.cpp << EOF 175 1.2 kamil #include <iostream> 176 1.2 kamil struct A { 177 1.2 kamil int i; 178 1.2 kamil A(int i):i(i){std::cout << "CTOR A" << std::endl;} 179 1.2 kamil ~A() {std::cout << "DTOR A:" << i << std::endl;} 180 1.2 kamil }; 181 1.2 kamil struct B { 182 1.2 kamil A *m_a; 183 1.2 kamil B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;} 184 1.2 kamil ~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;} 185 1.2 kamil }; 186 1.2 kamil int main(void) {struct B b;return 0;} 187 1.2 kamil EOF 188 1.2 kamil atf_check -s exit:0 -o ignore -e ignore c++ -static -o hello test.cpp 189 1.2 kamil atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello 190 1.2 kamil } 191 1.2 kamil 192 1.1 kamil static_destructor_pic_body() { 193 1.1 kamil cat > test.cpp << EOF 194 1.1 kamil #include <cstdlib> 195 1.1 kamil int callpic(void); 196 1.1 kamil int main(void) {callpic();exit(0);} 197 1.1 kamil EOF 198 1.1 kamil cat > pic.cpp << EOF 199 1.1 kamil #include <iostream> 200 1.1 kamil struct A { 201 1.1 kamil int i; 202 1.1 kamil A(int i):i(i){std::cout << "CTOR A" << std::endl;} 203 1.1 kamil ~A() {std::cout << "DTOR A:" << i << std::endl;} 204 1.1 kamil }; 205 1.1 kamil struct B { 206 1.1 kamil A *m_a; 207 1.1 kamil B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;} 208 1.1 kamil ~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;} 209 1.1 kamil }; 210 1.1 kamil int callpic(void) {struct B b;} 211 1.1 kamil EOF 212 1.1 kamil 213 1.1 kamil atf_check -s exit:0 -o ignore -e ignore \ 214 1.1 kamil c++ -fPIC -shared -o libtest.so pic.cpp 215 1.1 kamil atf_check -s exit:0 -o ignore -e ignore \ 216 1.1 kamil c++ -o hello test.cpp -L. -ltest 217 1.1 kamil 218 1.1 kamil export LD_LIBRARY_PATH=. 219 1.1 kamil atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello 220 1.1 kamil } 221 1.1 kamil 222 1.2 kamil static_destructor_pic_32_body() { 223 1.2 kamil # check whether this arch is 64bit 224 1.2 kamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 225 1.2 kamil atf_skip "this is not a 64 bit architecture" 226 1.2 kamil fi 227 1.2 kamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 228 1.2 kamil atf_skip "c++ -m32 not supported on this architecture" 229 1.2 kamil else 230 1.2 kamil if fgrep -q _LP64 ./def32; then 231 1.2 kamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 232 1.2 kamil fi 233 1.2 kamil fi 234 1.2 kamil 235 1.2 kamil cat > test.cpp << EOF 236 1.2 kamil #include <cstdlib> 237 1.2 kamil int callpic(void); 238 1.2 kamil int main(void) {callpic();exit(0);} 239 1.2 kamil EOF 240 1.2 kamil cat > pic.cpp << EOF 241 1.2 kamil #include <iostream> 242 1.2 kamil struct A { 243 1.2 kamil int i; 244 1.2 kamil A(int i):i(i){std::cout << "CTOR A" << std::endl;} 245 1.2 kamil ~A() {std::cout << "DTOR A:" << i << std::endl;} 246 1.2 kamil }; 247 1.2 kamil struct B { 248 1.2 kamil A *m_a; 249 1.2 kamil B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;} 250 1.2 kamil ~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;} 251 1.2 kamil }; 252 1.2 kamil int callpic(void) {struct B b;} 253 1.2 kamil EOF 254 1.2 kamil 255 1.2 kamil atf_check -s exit:0 -o ignore -e ignore \ 256 1.2 kamil c++ -m32 -fPIC -shared -o libtest.so pic.cpp 257 1.2 kamil atf_check -s exit:0 -o ignore -e ignore \ 258 1.2 kamil c++ -m32 -o hello test.cpp -L. -ltest 259 1.2 kamil 260 1.2 kamil export LD_LIBRARY_PATH=. 261 1.2 kamil atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello 262 1.2 kamil } 263 1.2 kamil 264 1.2 kamil static_destructor_pic_profile_body() { 265 1.7 riastrad case `uname -m` in 266 1.7 riastrad riscv) atf_expect_fail "PR port-riscv/59301:" \ 267 1.7 riastrad " riscv: missing MKPROFILE=yes support" 268 1.7 riastrad ;; 269 1.7 riastrad esac 270 1.7 riastrad 271 1.2 kamil cat > test.cpp << EOF 272 1.2 kamil #include <cstdlib> 273 1.2 kamil int callpic(void); 274 1.2 kamil int main(void) {callpic();exit(0);} 275 1.2 kamil EOF 276 1.2 kamil cat > pic.cpp << EOF 277 1.2 kamil #include <iostream> 278 1.2 kamil struct A { 279 1.2 kamil int i; 280 1.2 kamil A(int i):i(i){std::cout << "CTOR A" << std::endl;} 281 1.2 kamil ~A() {std::cout << "DTOR A:" << i << std::endl;} 282 1.2 kamil }; 283 1.2 kamil struct B { 284 1.2 kamil A *m_a; 285 1.2 kamil B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;} 286 1.2 kamil ~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;} 287 1.2 kamil }; 288 1.2 kamil int callpic(void) {struct B b;} 289 1.2 kamil EOF 290 1.2 kamil 291 1.2 kamil atf_check -s exit:0 -o ignore -e ignore \ 292 1.2 kamil c++ -pg -fPIC -shared -o libtest.so pic.cpp 293 1.2 kamil atf_check -s exit:0 -o ignore -e ignore \ 294 1.2 kamil c++ -pg -o hello test.cpp -L. -ltest 295 1.2 kamil 296 1.2 kamil export LD_LIBRARY_PATH=. 297 1.2 kamil atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello 298 1.2 kamil } 299 1.2 kamil 300 1.2 kamil static_destructor_pic_profile_32_body() { 301 1.2 kamil # check whether this arch is 64bit 302 1.2 kamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 303 1.2 kamil atf_skip "this is not a 64 bit architecture" 304 1.2 kamil fi 305 1.2 kamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 306 1.2 kamil atf_skip "c++ -m32 not supported on this architecture" 307 1.2 kamil else 308 1.2 kamil if fgrep -q _LP64 ./def32; then 309 1.2 kamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 310 1.2 kamil fi 311 1.2 kamil fi 312 1.2 kamil 313 1.7 riastrad case `uname -m` in 314 1.7 riastrad riscv) atf_expect_fail "PR port-riscv/59301:" \ 315 1.7 riastrad " riscv: missing MKPROFILE=yes support" 316 1.7 riastrad ;; 317 1.7 riastrad esac 318 1.7 riastrad 319 1.2 kamil cat > test.cpp << EOF 320 1.2 kamil #include <cstdlib> 321 1.2 kamil int callpic(void); 322 1.2 kamil int main(void) {callpic();exit(0);} 323 1.2 kamil EOF 324 1.2 kamil cat > pic.cpp << EOF 325 1.2 kamil #include <iostream> 326 1.2 kamil struct A { 327 1.2 kamil int i; 328 1.2 kamil A(int i):i(i){std::cout << "CTOR A" << std::endl;} 329 1.2 kamil ~A() {std::cout << "DTOR A:" << i << std::endl;} 330 1.2 kamil }; 331 1.2 kamil struct B { 332 1.2 kamil A *m_a; 333 1.2 kamil B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;} 334 1.2 kamil ~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;} 335 1.2 kamil }; 336 1.2 kamil int callpic(void) {struct B b;} 337 1.2 kamil EOF 338 1.2 kamil 339 1.2 kamil atf_check -s exit:0 -o ignore -e ignore \ 340 1.2 kamil c++ -m32 -pg -fPIC -shared -o libtest.so pic.cpp 341 1.2 kamil atf_check -s exit:0 -o ignore -e ignore \ 342 1.2 kamil c++ -m32 -pg -o hello test.cpp -L. -ltest 343 1.2 kamil 344 1.2 kamil export LD_LIBRARY_PATH=. 345 1.2 kamil atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello 346 1.2 kamil } 347 1.2 kamil 348 1.1 kamil static_destructor_pie_body() { 349 1.1 kamil # check whether this arch supports -pie 350 1.1 kamil if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then 351 1.1 kamil atf_skip "c++ -pie not supported on this architecture" 352 1.1 kamil fi 353 1.1 kamil cat > test.cpp << EOF 354 1.1 kamil #include <iostream> 355 1.1 kamil struct A { 356 1.1 kamil int i; 357 1.1 kamil A(int i):i(i){std::cout << "CTOR A" << std::endl;} 358 1.1 kamil ~A() {std::cout << "DTOR A:" << i << std::endl;} 359 1.1 kamil }; 360 1.1 kamil struct B { 361 1.1 kamil A *m_a; 362 1.1 kamil B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;} 363 1.1 kamil ~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;} 364 1.1 kamil }; 365 1.1 kamil int main(void) {struct B b;return 0;} 366 1.1 kamil EOF 367 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o hello test.cpp 368 1.1 kamil atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello 369 1.1 kamil } 370 1.1 kamil 371 1.1 kamil static_destructor32_body() { 372 1.1 kamil # check whether this arch is 64bit 373 1.1 kamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 374 1.1 kamil atf_skip "this is not a 64 bit architecture" 375 1.1 kamil fi 376 1.1 kamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 377 1.1 kamil atf_skip "c++ -m32 not supported on this architecture" 378 1.1 kamil else 379 1.1 kamil if fgrep -q _LP64 ./def32; then 380 1.1 kamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 381 1.1 kamil fi 382 1.1 kamil fi 383 1.1 kamil 384 1.1 kamil cat > test.cpp << EOF 385 1.1 kamil #include <iostream> 386 1.1 kamil struct A { 387 1.1 kamil int i; 388 1.1 kamil A(int i):i(i){std::cout << "CTOR A" << std::endl;} 389 1.1 kamil ~A() {std::cout << "DTOR A:" << i << std::endl;} 390 1.1 kamil }; 391 1.1 kamil struct B { 392 1.1 kamil A *m_a; 393 1.1 kamil B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;} 394 1.1 kamil ~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;} 395 1.1 kamil }; 396 1.1 kamil int main(void) {struct B b;return 0;} 397 1.1 kamil EOF 398 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello32 -m32 test.cpp 399 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello64 test.cpp 400 1.1 kamil file -b ./hello32 > ./ftype32 401 1.1 kamil file -b ./hello64 > ./ftype64 402 1.1 kamil if diff ./ftype32 ./ftype64 >/dev/null; then 403 1.1 kamil atf_fail "generated binaries do not differ" 404 1.1 kamil fi 405 1.1 kamil echo "32bit binaries on this platform are:" 406 1.1 kamil cat ./ftype32 407 1.1 kamil echo "While native (64bit) binaries are:" 408 1.1 kamil cat ./ftype64 409 1.1 kamil atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello32 410 1.1 kamil 411 1.1 kamil # do another test with static 32bit binaries 412 1.1 kamil cat > test.cpp << EOF 413 1.1 kamil #include <iostream> 414 1.1 kamil struct A { 415 1.1 kamil int i; 416 1.1 kamil A(int i):i(i){std::cout << "CTOR A" << std::endl;} 417 1.1 kamil ~A() {std::cout << "DTOR A:" << i << std::endl;} 418 1.1 kamil }; 419 1.1 kamil struct B { 420 1.1 kamil A *m_a; 421 1.1 kamil B(){static A s_a(10);m_a=&s_a;std::cout << "CTOR B" << std::endl;} 422 1.1 kamil ~B(){std::cout << "DTOR B:" << (*m_a).i << std::endl;(*m_a).i = 20;} 423 1.1 kamil }; 424 1.1 kamil int main(void) {struct B b;return 0;} 425 1.1 kamil EOF 426 1.1 kamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello -m32 \ 427 1.1 kamil -static test.cpp 428 1.1 kamil atf_check -s exit:0 -o inline:"CTOR A\nCTOR B\nDTOR B:10\nDTOR A:20\n" ./hello 429 1.1 kamil } 430 1.1 kamil 431 1.1 kamil atf_init_test_cases() 432 1.1 kamil { 433 1.1 kamil 434 1.1 kamil atf_add_test_case static_destructor 435 1.2 kamil atf_add_test_case static_destructor_profile 436 1.1 kamil atf_add_test_case static_destructor_pic 437 1.1 kamil atf_add_test_case static_destructor_pie 438 1.1 kamil atf_add_test_case static_destructor32 439 1.2 kamil atf_add_test_case static_destructor_static 440 1.2 kamil atf_add_test_case static_destructor_pic_32 441 1.2 kamil atf_add_test_case static_destructor_pic_profile 442 1.2 kamil atf_add_test_case static_destructor_pic_profile_32 443 1.2 kamil atf_add_test_case static_destructor_profile_32 444 1.1 kamil } 445