* sysdeps/m68k/dl-machine.h (_dl_start_user): Pass correct
[glibc.git] / elf / vismain.c
bloba9769202c34e44ef7f496c15be9ef7bdb15ab7a7
1 /* Copyright (C) 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
23 /* Prototype for our test function. */
24 extern int do_test (void);
26 #define TEST_FUNCTION do_test ()
28 /* This defines the `main' function and some more. */
29 #include <test-skeleton.c>
31 /* Prototypes for the functions in the DSOs. */
32 extern int calllocal1 (void);
33 extern int (*getlocal1 (void)) (void);
34 extern int callinmod1 (void);
35 extern int (*getinmod1 (void)) (void);
36 extern int callitcpt1 (void);
37 extern int (*getitcpt1 (void)) (void);
38 extern const char *getvarlocal1 (void);
39 extern const char *getvarinmod1 (void);
40 extern const char *getvaritcpt1 (void);
41 extern int calllocal2 (void);
42 extern int (*getlocal2 (void)) (void);
43 extern int callinmod2 (void);
44 extern int (*getinmod2 (void)) (void);
45 extern int callitcpt2 (void);
46 extern int (*getitcpt2 (void)) (void);
47 extern const char *getvarlocal2 (void);
48 extern const char *getvarinmod2 (void);
49 extern const char *getvaritcpt2 (void);
50 extern int callitcpt3 (void);
51 extern int (*getitcpt3 (void)) (void);
52 extern const char *getvaritcpt3 (void);
54 extern int protinmod (void);
55 extern int protitcpt (void);
57 /* Prototypes for local functions. */
58 extern int protlocal (void);
60 const char *protvarlocal = __FILE__;
61 extern const char *protvarinmod;
62 extern const char *protvaritcpt;
64 int
65 do_test (void)
67 int res = 0;
68 int val;
70 /* First test: check whether .protected is handled correctly by the
71 assembler/linker. The uses of `protlocal' in the DSOs and in the
72 main program should all be resolved with the local definitions. */
73 val = protlocal () + calllocal1 () + calllocal2 ();
74 if (val != 0x155)
76 puts ("\
77 The handling of `.protected' seems to be implemented incorrectly: giving up");
78 abort ();
80 puts ("`.protected' seems to be handled correctly, good!");
82 /* Function pointers: for functions which are marked local and for
83 which definitions are available all function pointers must be
84 distinct. */
85 if (protlocal == getlocal1 ())
87 puts ("`protlocal' in main and mod1 have same address");
88 res = 1;
90 if (protlocal == getlocal2 ())
92 puts ("`protlocal' in main and mod2 have same address");
93 res = 1;
95 if (getlocal1 () == getlocal2 ())
97 puts ("`protlocal' in mod1 and mod2 have same address");
98 res = 1;
100 if (getlocal1 () () + getlocal2 () () != 0x44)
102 puts ("pointers to `protlocal' in mod1 or mod2 incorrect");
103 res = 1;
106 /* Next test. This is similar to the last one but the function we
107 are calling is not defined in the main object. This means that
108 the invocation in the main object uses the definition in the
109 first DSO. */
110 if (protinmod != getinmod1 ())
112 puts ("`protinmod' in main and mod1 don't have same address");
113 res = 1;
115 if (protinmod == getinmod2 ())
117 puts ("`protinmod' in main and mod2 have same address");
118 res = 1;
120 if (getinmod1 () == getinmod2 ())
122 puts ("`protinmod' in mod1 and mod2 have same address");
123 res = 1;
125 if (protinmod () + getinmod1 () () + getinmod2 () () != 0x4800)
127 puts ("pointers to `protinmod' in mod1 or mod2 incorrect");
128 res = 1;
130 val = protinmod () + callinmod1 () + callinmod2 ();
131 if (val != 0x15800)
133 printf ("calling of `protinmod' leads to wrong result (%#x)\n", val);
134 res = 1;
137 /* A very similar text. Same setup for the main object and the modules
138 but this time we have another definition in a preloaded module. This
139 one intercepts the references from the main object. */
140 if (protitcpt != getitcpt3 ())
142 puts ("`protitcpt' in main and mod3 don't have same address");
143 res = 1;
145 if (protitcpt == getitcpt1 ())
147 puts ("`protitcpt' in main and mod1 have same address");
148 res = 1;
150 if (protitcpt == getitcpt2 ())
152 puts ("`protitcpt' in main and mod2 have same address");
153 res = 1;
155 if (getitcpt1 () == getitcpt2 ())
157 puts ("`protitcpt' in mod1 and mod2 have same address");
158 res = 1;
160 val = protitcpt () + getitcpt1 () () + getitcpt2 () () + getitcpt3 () ();
161 if (val != 0x8440000)
163 printf ("\
164 pointers to `protitcpt' in mod1 or mod2 or mod3 incorrect (%#x)\n", val);
165 res = 1;
167 val = protitcpt () + callitcpt1 () + callitcpt2 () + callitcpt3 ();
168 if (val != 0x19540000)
170 printf ("calling of `protitcpt' leads to wrong result (%#x)\n", val);
171 res = 1;
174 /* Now look at variables. First a variable which is available
175 everywhere. We must have three different addresses. */
176 if (protvarlocal == getvarlocal1 ())
178 puts ("`protvarlocal' in main and mod1 have same address");
179 res = 1;
181 if (protvarlocal == getvarlocal2 ())
183 puts ("`protvarlocal' in main and mod2 have same address");
184 res = 1;
186 if (getvarlocal1 () == getvarlocal2 ())
188 puts ("`protvarlocal' in mod1 and mod2 have same address");
189 res = 1;
191 if (strcmp (protvarlocal, __FILE__) != 0)
193 puts ("`protvarlocal in main has wrong value");
194 res = 1;
196 if (strcmp (getvarlocal1 (), "vismod1.c") != 0)
198 puts ("`getvarlocal1' returns wrong value");
199 res = 1;
201 if (strcmp (getvarlocal2 (), "vismod2.c") != 0)
203 puts ("`getvarlocal2' returns wrong value");
204 res = 1;
207 /* Now the case where there is no local definition. */
208 if (protvarinmod != getvarinmod1 ())
210 puts ("`protvarinmod' in main and mod1 have not same address");
211 res = 1;
213 if (protvarinmod == getvarinmod2 ())
215 puts ("`protvarinmod' in main and mod2 have same address");
216 res = 1;
218 if (strcmp (getvarinmod1 (), "vismod1.c") != 0)
220 puts ("`getvarinmod1' returns wrong value");
221 res = 1;
223 if (strcmp (getvarinmod2 (), "vismod2.c") != 0)
225 puts ("`getvarinmod2' returns wrong value");
226 res = 1;
229 /* And a test where a variable definition is intercepted. */
230 if (protvaritcpt == getvaritcpt1 ())
232 puts ("`protvaritcpt' in main and mod1 have same address");
233 res = 1;
235 if (protvaritcpt == getvaritcpt2 ())
237 puts ("`protvaritcpt' in main and mod2 have same address");
238 res = 1;
240 if (protvaritcpt != getvaritcpt3 ())
242 puts ("`protvaritcpt' in main and mod3 have not same address");
243 res = 1;
245 if (getvaritcpt1 () == getvaritcpt2 ())
247 puts ("`protvaritcpt' in mod1 and mod2 have same address");
248 res = 1;
250 if (strcmp (protvaritcpt, "vismod3.c") != 0)
252 puts ("`protvaritcpt in main has wrong value");
253 res = 1;
255 if (strcmp (getvaritcpt1 (), "vismod1.c") != 0)
257 puts ("`getvaritcpt1' returns wrong value");
258 res = 1;
260 if (strcmp (getvaritcpt2 (), "vismod2.c") != 0)
262 puts ("`getvaritcpt2' returns wrong value");
263 res = 1;
266 return res;
271 protlocal (void)
273 return 0x1;