7 static sigjmp_buf jmpbuf
;
14 __attribute__ ((noreturn
))
17 siglongjmp (jmpbuf
, 1);
21 #define TEST_FUNCTION do_test ()
25 /* We are testing the two possibilities to mark an object as not deletable:
26 - marked on the linker commandline with `-z nodelete'
27 - with the RTLD_NODELETE flag at dlopen()-time.
29 The test we are performing should be safe. We are loading the objects,
30 get the address of variables in the respective object, unload the object
31 and then try to read the variable. If the object is unloaded this
32 should lead to an segmentation fault. */
37 sa
.sa_handler
= handler
;
38 sigfillset (&sa
.sa_mask
);
39 sa
.sa_flags
= SA_RESTART
;
41 if (sigaction (SIGSEGV
, &sa
, NULL
) == -1)
42 printf ("cannot install signal handler: %m\n");
44 p
= dlopen ("nodelmod1.so", RTLD_LAZY
);
47 printf ("failed to load \"nodelmod1.so\": %s\n", dlerror ());
54 puts ("succeeded loading \"nodelmod1.so\"");
56 varp
= dlsym (p
, "var1");
59 puts ("failed to get address of \"var1\" in \"nodelmod1.so\"");
66 /* Now close the object. */
70 puts ("failed to close \"nodelmod1.so\"");
73 else if (! sigsetjmp (jmpbuf
, 1))
75 /* Access the variable again. */
76 if (*varp
!= 20000720)
78 puts ("\"var1\" value not correct");
81 else if (fini_ran
!= 0)
83 puts ("destructor of \"nodelmod1.so\" ran");
87 puts ("-z nodelete test succeeded");
91 /* We caught an segmentation fault. */
92 puts ("\"nodelmod1.so\" got deleted");
98 p
= dlopen ("nodelmod2.so", RTLD_LAZY
| RTLD_NODELETE
);
101 printf ("failed to load \"nodelmod2.so\": %s\n", dlerror ());
108 puts ("succeeded loading \"nodelmod2.so\"");
110 varp
= dlsym (p
, "var2");
113 puts ("failed to get address of \"var2\" in \"nodelmod2.so\"");
120 /* Now close the object. */
122 if (dlclose (p
) != 0)
124 puts ("failed to close \"nodelmod2.so\"");
127 else if (! sigsetjmp (jmpbuf
, 1))
129 /* Access the variable again. */
132 puts ("\"var2\" value not correct");
135 else if (fini_ran
!= 0)
137 puts ("destructor of \"nodelmod2.so\" ran");
141 puts ("RTLD_NODELETE test succeeded");
145 /* We caught an segmentation fault. */
146 puts ("\"nodelmod2.so\" got deleted");
152 p
= dlopen ("nodelmod3.so", RTLD_LAZY
);
155 printf ("failed to load \"nodelmod3.so\": %s\n", dlerror ());
162 puts ("succeeded loading \"nodelmod3.so\"");
164 fctp
= dlsym (p
, "addr");
167 puts ("failed to get address of \"addr\" in \"nodelmod3.so\"");
176 /* Now close the object. */
178 if (dlclose (p
) != 0)
180 puts ("failed to close \"nodelmod3.so\"");
183 else if (! sigsetjmp (jmpbuf
, 1))
185 /* Access the variable again. */
188 puts ("\"var_in_mod4\" value not correct");
191 else if (fini_ran
!= 0)
193 puts ("destructor of \"nodelmod4.so\" ran");
197 puts ("-z nodelete in dependency succeeded");
201 /* We caught an segmentation fault. */
202 puts ("\"nodelmod4.so\" got deleted");
211 #include "../test-skeleton.c"