blob: d70998c0896dbe1b810bf10e734e2a49807f110a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include <cstdlib>
#include <cstdio>
#include <iostream>
static void
bye_main()
{
std::cout << "mD " << __FUNCTION__ << std::endl;
}
static void
bye_setup()
{
std::cout << "mD " << __FUNCTION__ << std::endl;
}
static void
bye_func()
{
std::cout << "mD " << __FUNCTION__ << std::endl;
}
void
func3() __attribute__((__import_module__("mE"), __import_name__("func1")));
void
func4() __attribute__((__import_module__("mE"), __import_name__("func2")));
void
func1()
{
std::printf("mD %s\n", __FUNCTION__);
if (std::atexit(bye_func) != 0) {
std::perror("register an atexit handler failed");
}
func3();
}
void
func2()
{
std::printf("mD %s\n", __FUNCTION__);
func4();
}
__attribute__((constructor)) void
setup()
{
std::cout << "mD " << __FUNCTION__ << std::endl;
if (std::atexit(bye_setup) != 0) {
std::perror("register an atexit handler failed");
}
}
__attribute__((destructor)) void
teardown()
{
std::cout << "mD " << __FUNCTION__ << std::endl;
}
int
main()
{
std::printf("mD %s\n", __FUNCTION__);
if (std::atexit(bye_main) != 0) {
std::perror("register an atexit handler failed");
return EXIT_FAILURE;
}
func1();
func2();
return EXIT_SUCCESS;
}
|