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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
#ifdef PROTECTED_CHECK
#include <features.h>
#include <stdio.h>
int
main (void)
{
#if defined (__GLIBC__) && (__GLIBC__ > 2 \
|| (__GLIBC__ == 2 \
&& __GLIBC_MINOR__ >= 2))
puts ("yes");
#else
puts ("no");
#endif
return 0;
}
#else
/* This is the main program for the shared library test. */
#include <stdio.h>
int mainvar = 1;
int overriddenvar = 2;
extern int shlibvar1;
extern int shlib_mainvar ();
extern int shlib_overriddenvar ();
extern int shlib_shlibvar1 ();
extern int shlib_shlibvar2 ();
extern int shlib_shlibcall ();
extern int shlib_maincall ();
extern int shlib_checkfunptr1 ();
extern int shlib_checkfunptr2 ();
extern int (*shlib_getfunptr1 ()) ();
extern int (*shlib_getfunptr2 ()) ();
extern int shlib_check ();
extern int shlib_shlibcall2 ();
extern int visibility_check ();
extern int visibility_checkfunptr ();
extern void *visibility_funptr ();
extern int visibility_checkvar ();
extern int visibility_checkvarptr ();
extern int visibility_varval ();
extern void *visibility_varptr ();
extern int shlib_visibility_checkcom ();
extern int shlib_visibility_checkweak ();
int shlib_visibility_com = 1;
int shlib_visibility_var_weak = 1;
int
shlib_visibility_func_weak ()
{
return 1;
}
#ifdef HIDDEN_WEAK_TEST
#define WEAK_TEST
#endif
#ifdef PROTECTED_WEAK_TEST
#define WEAK_TEST
#endif
#ifdef PROTECTED_UNDEF_TEST
#define PROTECTED_TEST
#endif
#ifndef WEAK_TEST
extern int visibility ();
extern int visibility_var;
#endif
#if !defined (HIDDEN_TEST) && defined (PROTECTED_TEST)
int
visibility ()
{
return 1;
}
static int
main_visibility_check ()
{
return ((int (*) (void)) visibility_funptr ()) != visibility;
}
int visibility_var = 1;
static int
main_visibility_checkvar ()
{
return visibility_varval () != visibility_var
&& visibility_varptr () != &visibility_var;
}
#ifndef PROTECTED_UNDEF_TEST
int shared_data = 1;
asm (".protected shared_data");
int
shared_func ()
{
return 1;
}
asm (".protected shared_func");
extern int * shared_data_p ();
typedef int (*func) ();
extern func shared_func_p ();
#endif
#else
static int
main_visibility_check ()
{
#ifdef WEAK_TEST
return visibility_funptr () == NULL;
#else
return ((int (*) (void)) visibility_funptr ()) == visibility;
#endif
}
static int
main_visibility_checkvar ()
{
#ifdef WEAK_TEST
return visibility_varval () == 0
&& visibility_varptr () == NULL;
#else
return visibility_varval () == visibility_var
&& visibility_varptr () == &visibility_var;
#endif
}
#endif
/* This function is called by the shared library. */
int
main_called ()
{
return 6;
}
/* This function overrides a function in the shared library. */
int
shlib_overriddencall2 ()
{
return 8;
}
#ifdef HIDDEN_NORMAL_TEST
int visibility_com;
asm (".hidden visibility_com");
int
main_visibility_checkcom ()
{
return visibility_com == 0;
}
int
main_visibility_checkweak ()
{
return 1;
}
#elif defined (HIDDEN_WEAK_TEST)
int
main_visibility_checkcom ()
{
return 1;
}
#pragma weak visibility_undef_var_weak
extern int visibility_undef_var_weak;
asm (".hidden visibility_undef_var_weak");
#pragma weak visibility_undef_func_weak
extern int visibility_undef_func_weak ();
asm (".hidden visibility_undef_func_weak");
#pragma weak visibility_var_weak
extern int visibility_var_weak;
asm (".hidden visibility_var_weak");
#pragma weak visibility_func_weak
extern int visibility_func_weak ();
asm (".hidden visibility_func_weak");
int
main_visibility_checkweak ()
{
return &visibility_undef_var_weak == NULL
&& &visibility_undef_func_weak == NULL
&& &visibility_func_weak == NULL
&& &visibility_var_weak == NULL;
}
#elif defined (HIDDEN_UNDEF_TEST)
extern int visibility_def;
asm (".hidden visibility_def");
extern int visibility_func ();
asm (".hidden visibility_func");
int
main_visibility_checkcom ()
{
return &visibility_def != NULL;
}
int
main_visibility_checkweak ()
{
return &visibility_func != NULL;
}
#else
int
main_visibility_checkcom ()
{
return 1;
}
int
main_visibility_checkweak ()
{
return 1;
}
#endif
int
main ()
{
int (*p) ();
int ret = 0;
printf ("mainvar == %d\n", mainvar);
printf ("overriddenvar == %d\n", overriddenvar);
printf ("shlibvar1 == %d\n", shlibvar1);
#ifndef XCOFF_TEST
printf ("shlib_mainvar () == %d\n", shlib_mainvar ());
printf ("shlib_overriddenvar () == %d\n", shlib_overriddenvar ());
#endif
printf ("shlib_shlibvar1 () == %d\n", shlib_shlibvar1 ());
printf ("shlib_shlibvar2 () == %d\n", shlib_shlibvar2 ());
printf ("shlib_shlibcall () == %d\n", shlib_shlibcall ());
#ifndef XCOFF_TEST
printf ("shlib_shlibcall2 () == %d\n", shlib_shlibcall2 ());
printf ("shlib_maincall () == %d\n", shlib_maincall ());
#endif
printf ("main_called () == %d\n", main_called ());
printf ("shlib_checkfunptr1 (shlib_shlibvar1) == %d\n",
shlib_checkfunptr1 (shlib_shlibvar1));
#ifndef XCOFF_TEST
printf ("shlib_checkfunptr2 (main_called) == %d\n",
shlib_checkfunptr2 (main_called));
#endif
p = shlib_getfunptr1 ();
printf ("shlib_getfunptr1 () ");
if (p == shlib_shlibvar1)
printf ("==");
else
printf ("!=");
printf (" shlib_shlibvar1\n");
#ifndef XCOFF_TEST
p = shlib_getfunptr2 ();
printf ("shlib_getfunptr2 () ");
if (p == main_called)
printf ("==");
else
printf ("!=");
printf (" main_called\n");
#endif
printf ("shlib_check () == %d\n", shlib_check ());
printf ("visibility_check () == %d\n", visibility_check ());
printf ("visibility_checkfunptr () == %d\n",
visibility_checkfunptr ());
printf ("main_visibility_check () == %d\n", main_visibility_check ());
printf ("visibility_checkvar () == %d\n", visibility_checkvar ());
printf ("visibility_checkvarptr () == %d\n",
visibility_checkvarptr ());
printf ("main_visibility_checkvar () == %d\n",
main_visibility_checkvar ());
printf ("main_visibility_checkcom () == %d\n",
main_visibility_checkcom ());
printf ("shlib_visibility_checkcom () == %d\n",
shlib_visibility_checkcom ());
printf ("main_visibility_checkweak () == %d\n",
main_visibility_checkweak ());
printf ("shlib_visibility_checkweak () == %d\n",
shlib_visibility_checkweak ());
#if !defined (PROTECTED_UNDEF_TEST) && defined (PROTECTED_TEST)
if (&shared_data != shared_data_p ())
ret = 1;
p = shared_func_p ();
if (shared_func != p)
ret = 1;
if (shared_data != *shared_data_p ())
ret = 1;
if (shared_func () != (*p) () )
ret = 1;
#endif
return ret;
}
#endif
|