aboutsummaryrefslogtreecommitdiff
path: root/ld/testsuite/ld-elfvsb/sh1.c
blob: 2299f83bdc36715fcc8a3fb6e8b777f03a794d2e (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
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#ifndef NULL
#define NULL ((void *) 0)
#endif

/* This is part of the shared library ld test.  This file becomes part
   of a shared library.  */

/* This variable is supplied by the main program.  */
#ifndef XCOFF_TEST
extern int mainvar;
#endif

/* This variable is defined in the shared library, and overridden by
   the main program.  */
#ifndef XCOFF_TEST
int overriddenvar = -1;
#endif

/* This variable is defined in the shared library.  */
int shlibvar1 = 3;

/* This variable is defined by another object in the shared library.  */
extern int shlibvar2;

/* These functions return the values of the above variables as seen in
   the shared library.  */

#ifndef XCOFF_TEST
int
shlib_mainvar ()
{
  return mainvar;
}
#endif

#ifndef XCOFF_TEST
int
shlib_overriddenvar ()
{
  return overriddenvar;
}
#endif

int
shlib_shlibvar1 ()
{
  return shlibvar1;
}

int
shlib_shlibvar2 ()
{
  return shlibvar2;
}

/* This function calls a function defined by another object in the
   shared library.  */

extern int shlib_shlibcalled ();

int
shlib_shlibcall ()
{
  return shlib_shlibcalled ();
}

#ifndef XCOFF_TEST
/* This function calls a function defined in this object in the shared
   library.  The main program will override the called function.  */

extern int shlib_overriddencall2 ();

int
shlib_shlibcall2 ()
{
  return shlib_overriddencall2 ();
}

int
shlib_overriddencall2 ()
{
  return 7;
}
#endif

/* This function calls a function defined by the main program.  */

#ifndef XCOFF_TEST
extern int main_called ();

int
shlib_maincall ()
{
  return main_called ();
}
#endif

/* This function is passed a function pointer to shlib_mainvar.  It
   confirms that the pointer compares equally.  */

int 
shlib_checkfunptr1 (p)
     int (*p) ();
{
  return p == shlib_shlibvar1;
}

/* This function is passed a function pointer to main_called.  It
   confirms that the pointer compares equally.  */

#ifndef XCOFF_TEST
int
shlib_checkfunptr2 (p)
     int (*p) ();
{
  return p == main_called;
}
#endif

/* This function returns a pointer to shlib_mainvar.  */

int
(*shlib_getfunptr1 ()) ()
{
  return shlib_shlibvar1;
}

/* This function returns a pointer to main_called.  */

#ifndef XCOFF_TEST
int
(*shlib_getfunptr2 ()) ()
{
  return main_called;
}
#endif

/* This function makes sure that constant data and local functions
   work.  */

#ifndef __STDC__
#define const
#endif

static int i = 6;
static const char *str = "Hello, world\n";

int
shlib_check ()
{
  const char *s1, *s2;

  if (i != 6)
    return 0;

  /* To isolate the test, don't rely on any external functions, such
     as strcmp.  */
  s1 = "Hello, world\n";
  s2 = str;
  while (*s1 != '\0')
    if (*s1++ != *s2++)
      return 0;
  if (*s2 != '\0')
    return 0;

  if (shlib_shlibvar1 () != 3)
    return 0;

  return 1;
}

#ifdef HIDDEN_WEAK_TEST
#define HIDDEN_UNDEF_TEST
#define WEAK_TEST
#endif

#ifdef PROTECTED_WEAK_TEST
#define PROTECTED_UNDEF_TEST
#define WEAK_TEST
#endif

#if defined (HIDDEN_UNDEF_TEST) || defined (PROTECTED_UNDEF_TEST)
extern int visibility ();
#else
int
visibility ()
{
  return 2;
}
#endif

#ifdef HIDDEN_NORMAL_TEST
asm (".hidden visibility_normal");

int
visibility_normal ()
{
  return 2;
}
#endif

int
visibility_checkfunptr ()
{
#ifdef WEAK_TEST
  return 1;
#else
#ifdef HIDDEN_NORMAL_TEST
  int (*v) () = visibility_normal;
#else
  int (*v) () = visibility;
#endif
  return (*v) () == 2;
#endif
}

int
visibility_check ()
{
#ifdef WEAK_TEST
  if (&visibility)
    return visibility () == 1;
  else
    return 1;
#else
#ifdef HIDDEN_NORMAL_TEST
  return visibility_normal () == 2;
#else
  return visibility () == 2;
#endif
#endif
}

void *
visibility_funptr ()
{
#ifdef WEAK_TEST
  if (&visibility == NULL)
    return NULL;
  else
#endif
    return visibility;
}

#if defined (HIDDEN_UNDEF_TEST) || defined (PROTECTED_UNDEF_TEST)
extern int visibility_var;
#else
int visibility_var = 2;
#endif

#ifdef HIDDEN_NORMAL_TEST
asm (".hidden visibility_var_normal");

int visibility_var_normal = 2;
#endif

int
visibility_checkvarptr ()
{
#ifdef WEAK_TEST
  if (&visibility_var)
    return visibility_var == 1;
  else
    return 1;
#else
#ifdef HIDDEN_NORMAL_TEST
  int *v = &visibility_var_normal;
#else
  int *v = &visibility_var;
#endif
  return *v == 2;
#endif
}

int
visibility_checkvar ()
{
#ifdef WEAK_TEST
  return 1;
#else
#ifdef HIDDEN_NORMAL_TEST
  return visibility_var_normal == 2;
#else
  return visibility_var == 2;
#endif
#endif
}

void *
visibility_varptr ()
{
#ifdef WEAK_TEST
  if (&visibility_var == NULL)
    return NULL;
  else
#endif
    return &visibility_var;
}

int
visibility_varval ()
{
#ifdef WEAK_TEST
  if (&visibility_var == NULL)
    return 0;
  else
#endif
    return visibility_var;
}

#if defined (HIDDEN_TEST) || defined (HIDDEN_UNDEF_TEST)
asm (".hidden visibility");
asm (".hidden visibility_var");
#else
#if defined (PROTECTED_TEST) || defined (PROTECTED_UNDEF_TEST) || defined (PROTECTED_WEAK_TEST)
asm (".protected visibility");
asm (".protected visibility_var");
#endif
#endif

#ifdef WEAK_TEST
asm (".weak visibility");
asm (".weak visibility_var");
#endif