7 static sigjmp_buf jmpbuf
;
13 siglongjmp (jmpbuf
, 1);
17 #define TEST_FUNCTION do_test ()
21 /* We are testing the two possibilities to mark an object as not deletable:
22 - marked on the linker commandline with `-z nodelete'
23 - with the RTLD_NODELETE flag at dlopen()-time.
25 The test we are performing should be safe. We are loading the objects,
26 get the address of variables in the respective object, unload the object
27 and then try to read the variable. If the object is unloaded this
28 should lead to an segmentation fault. */
33 sa
.sa_handler
= handler
;
34 sigfillset (&sa
.sa_mask
);
35 sa
.sa_flags
= SA_RESTART
;
36 sa
.sa_restorer
= NULL
;
38 if (sigaction (SIGSEGV
, &sa
, NULL
) == -1)
39 printf ("cannot install signal handler: %m\n");
41 p
= dlopen ("nodelmod1.so", RTLD_LAZY
);
44 printf ("failed to load \"nodelmod1.so\": %s\n", dlerror ());
51 puts ("succeeded loading \"nodelmod1.so\"");
53 varp
= dlsym (p
, "var1");
56 puts ("failed to get address of \"var1\" in \"nodelmod1.so\"");
63 /* Now close the object. */
66 puts ("failed to close \"nodelmod1.so\"");
69 else if (! sigsetjmp (jmpbuf
, 1))
71 /* Access the variable again. */
72 if (*varp
!= 20000720)
74 puts ("\"var1\" value not correct");
78 puts ("-z nodelete test succeeded");
82 /* We caught an segmentation fault. */
83 puts ("\"nodelmod1.so\" got deleted");
89 p
= dlopen ("nodelmod2.so", RTLD_LAZY
| RTLD_NODELETE
);
92 printf ("failed to load \"nodelmod2.so\": %s\n", dlerror ());
99 puts ("succeeded loading \"nodelmod2.so\"");
101 varp
= dlsym (p
, "var2");
104 puts ("failed to get address of \"var2\" in \"nodelmod2.so\"");
111 /* Now close the object. */
112 if (dlclose (p
) != 0)
114 puts ("failed to close \"nodelmod2.so\"");
117 else if (! sigsetjmp (jmpbuf
, 1))
119 /* Access the variable again. */
122 puts ("\"var2\" value not correct");
126 puts ("RTLD_NODELETE test succeeded");
130 /* We caught an segmentation fault. */
131 puts ("\"nodelmod2.so\" got deleted");
137 p
= dlopen ("nodelmod3.so", RTLD_LAZY
);
140 printf ("failed to load \"nodelmod3.so\": %s\n", dlerror ());
147 puts ("succeeded loading \"nodelmod3.so\"");
149 fctp
= dlsym (p
, "addr");
152 puts ("failed to get address of \"addr\" in \"nodelmod3.so\"");
161 /* Now close the object. */
162 if (dlclose (p
) != 0)
164 puts ("failed to close \"nodelmod3.so\"");
167 else if (! sigsetjmp (jmpbuf
, 1))
169 /* Access the variable again. */
172 puts ("\"var_in_mod4\" value not correct");
176 puts ("-z nodelete in dependency succeeded");
180 /* We caught an segmentation fault. */
181 puts ("\"nodelmod4.so\" got deleted");
190 #include "../test-skeleton.c"