xref: /haiku/src/tests/system/runtime_loader/test_suite/load_init_order1 (revision 3a75ef9ad1db52cba9b96ddcdd03b35587e14057)
1#!/bin/sh
2
3# program
4# <- liba.so
5# Expected: preinit function in program runs before constructor in liba.so.
6
7
8. ./test_setup
9
10
11# create liba.so
12cat > liba.c << EOI
13extern int i;
14void __attribute__((constructor)) a() { i = 2 * i + 1; }
15EOI
16
17# build
18compile_lib -o liba.so liba.c
19
20# create program
21cat > program.c << EOI
22
23int i = 1;
24
25void b() { i = 4 * i + 1; }
26
27int
28main()
29{
30	return i;
31}
32
33__attribute__((section(".preinit_array"), used))
34void (*__local_b_preinit)(void) = b;
35
36EOI
37
38# build
39compile_program -o program program.c ./liba.so -pie
40
41# run
42test_run_ok ./program 11
43
44