7 static sigjmp_buf jmpbuf
;
14 __attribute__ ((noreturn
))
17 siglongjmp (jmpbuf
, 1);
24 /* We are testing the two possibilities to mark an object as not deletable:
25 - marked on the linker commandline with `-z nodelete'
26 - with the RTLD_NODELETE flag at dlopen()-time.
28 The test we are performing should be safe. We are loading the objects,
29 get the address of variables in the respective object, unload the object
30 and then try to read the variable. If the object is unloaded this
31 should lead to an segmentation fault. */
36 sa
.sa_handler
= handler
;
37 sigfillset (&sa
.sa_mask
);
38 sa
.sa_flags
= SA_RESTART
;
40 if (sigaction (SIGSEGV
, &sa
, NULL
) == -1)
41 printf ("cannot install signal handler: %m\n");
43 p
= dlopen ("nodelmod1.so", RTLD_LAZY
);
46 printf ("failed to load \"nodelmod1.so\": %s\n", dlerror ());
53 puts ("succeeded loading \"nodelmod1.so\"");
55 varp
= dlsym (p
, "var1");
58 puts ("failed to get address of \"var1\" in \"nodelmod1.so\"");
65 /* Now close the object. */
69 puts ("failed to close \"nodelmod1.so\"");
72 else if (! sigsetjmp (jmpbuf
, 1))
74 /* Access the variable again. */
75 if (*varp
!= 20000720)
77 puts ("\"var1\" value not correct");
80 else if (fini_ran
!= 0)
82 puts ("destructor of \"nodelmod1.so\" ran");
86 puts ("-z nodelete test succeeded");
90 /* We caught an segmentation fault. */
91 puts ("\"nodelmod1.so\" got deleted");
97 p
= dlopen ("nodelmod2.so", RTLD_LAZY
| RTLD_NODELETE
);
100 printf ("failed to load \"nodelmod2.so\": %s\n", dlerror ());
107 puts ("succeeded loading \"nodelmod2.so\"");
109 varp
= dlsym (p
, "var2");
112 puts ("failed to get address of \"var2\" in \"nodelmod2.so\"");
119 /* Now close the object. */
121 if (dlclose (p
) != 0)
123 puts ("failed to close \"nodelmod2.so\"");
126 else if (! sigsetjmp (jmpbuf
, 1))
128 /* Access the variable again. */
131 puts ("\"var2\" value not correct");
134 else if (fini_ran
!= 0)
136 puts ("destructor of \"nodelmod2.so\" ran");
140 puts ("RTLD_NODELETE test succeeded");
144 /* We caught an segmentation fault. */
145 puts ("\"nodelmod2.so\" got deleted");
151 p
= dlopen ("nodelmod3.so", RTLD_LAZY
);
154 printf ("failed to load \"nodelmod3.so\": %s\n", dlerror ());
161 puts ("succeeded loading \"nodelmod3.so\"");
163 fctp
= dlsym (p
, "addr");
166 puts ("failed to get address of \"addr\" in \"nodelmod3.so\"");
175 /* Now close the object. */
177 if (dlclose (p
) != 0)
179 puts ("failed to close \"nodelmod3.so\"");
182 else if (! sigsetjmp (jmpbuf
, 1))
184 /* Access the variable again. */
187 puts ("\"var_in_mod4\" value not correct");
190 else if (fini_ran
!= 0)
192 puts ("destructor of \"nodelmod4.so\" ran");
196 puts ("-z nodelete in dependency succeeded");
200 /* We caught an segmentation fault. */
201 puts ("\"nodelmod4.so\" got deleted");
210 #include <support/test-driver.c>