* locale/newlocale.c (__newlocale): Don't leak old data or names.
[glibc.git] / elf / vismain.c
blobad9c8470acf5d0336dd839ad5925c74fb4b4d2b7
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 Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the 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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
23 #include "vismod.h"
25 /* Prototype for our test function. */
26 extern int do_test (void);
28 #define TEST_FUNCTION do_test ()
30 /* This defines the `main' function and some more. */
31 #include <test-skeleton.c>
34 /* Prototypes for local functions. */
35 extern int protlocal (void);
37 const char *protvarlocal = __FILE__;
38 extern const char *protvarinmod;
39 extern const char *protvaritcpt;
41 int
42 do_test (void)
44 int res = 0;
45 int val;
47 /* First test: check whether .protected is handled correctly by the
48 assembler/linker. The uses of `protlocal' in the DSOs and in the
49 main program should all be resolved with the local definitions. */
50 val = protlocal () + calllocal1 () + calllocal2 ();
51 if (val != 0x155)
53 puts ("\
54 The handling of `.protected' seems to be implemented incorrectly: giving up");
55 abort ();
57 puts ("`.protected' seems to be handled correctly, good!");
59 /* Function pointers: for functions which are marked local and for
60 which definitions are available all function pointers must be
61 distinct. */
62 if (protlocal == getlocal1 ())
64 puts ("`protlocal' in main and mod1 have same address");
65 res = 1;
67 if (protlocal == getlocal2 ())
69 puts ("`protlocal' in main and mod2 have same address");
70 res = 1;
72 if (getlocal1 () == getlocal2 ())
74 puts ("`protlocal' in mod1 and mod2 have same address");
75 res = 1;
77 if (getlocal1 () () + getlocal2 () () != 0x44)
79 puts ("pointers to `protlocal' in mod1 or mod2 incorrect");
80 res = 1;
83 /* Next test. This is similar to the last one but the function we
84 are calling is not defined in the main object. This means that
85 the invocation in the main object uses the definition in the
86 first DSO. */
87 if (protinmod != getinmod1 ())
89 puts ("`protinmod' in main and mod1 don't have same address");
90 res = 1;
92 if (protinmod == getinmod2 ())
94 puts ("`protinmod' in main and mod2 have same address");
95 res = 1;
97 if (getinmod1 () == getinmod2 ())
99 puts ("`protinmod' in mod1 and mod2 have same address");
100 res = 1;
102 if (protinmod () + getinmod1 () () + getinmod2 () () != 0x4800)
104 puts ("pointers to `protinmod' in mod1 or mod2 incorrect");
105 res = 1;
107 val = protinmod () + callinmod1 () + callinmod2 ();
108 if (val != 0x15800)
110 printf ("calling of `protinmod' leads to wrong result (%#x)\n", val);
111 res = 1;
114 /* A very similar text. Same setup for the main object and the modules
115 but this time we have another definition in a preloaded module. This
116 one intercepts the references from the main object. */
117 if (protitcpt != getitcpt3 ())
119 puts ("`protitcpt' in main and mod3 don't have same address");
120 res = 1;
122 if (protitcpt == getitcpt1 ())
124 puts ("`protitcpt' in main and mod1 have same address");
125 res = 1;
127 if (protitcpt == getitcpt2 ())
129 puts ("`protitcpt' in main and mod2 have same address");
130 res = 1;
132 if (getitcpt1 () == getitcpt2 ())
134 puts ("`protitcpt' in mod1 and mod2 have same address");
135 res = 1;
137 val = protitcpt () + getitcpt1 () () + getitcpt2 () () + getitcpt3 () ();
138 if (val != 0x8440000)
140 printf ("\
141 pointers to `protitcpt' in mod1 or mod2 or mod3 incorrect (%#x)\n", val);
142 res = 1;
144 val = protitcpt () + callitcpt1 () + callitcpt2 () + callitcpt3 ();
145 if (val != 0x19540000)
147 printf ("calling of `protitcpt' leads to wrong result (%#x)\n", val);
148 res = 1;
151 /* Now look at variables. First a variable which is available
152 everywhere. We must have three different addresses. */
153 if (protvarlocal == getvarlocal1 ())
155 puts ("`protvarlocal' in main and mod1 have same address");
156 res = 1;
158 if (protvarlocal == getvarlocal2 ())
160 puts ("`protvarlocal' in main and mod2 have same address");
161 res = 1;
163 if (getvarlocal1 () == getvarlocal2 ())
165 puts ("`protvarlocal' in mod1 and mod2 have same address");
166 res = 1;
168 if (strcmp (protvarlocal, __FILE__) != 0)
170 puts ("`protvarlocal in main has wrong value");
171 res = 1;
173 if (strcmp (getvarlocal1 (), "vismod1.c") != 0)
175 puts ("`getvarlocal1' returns wrong value");
176 res = 1;
178 if (strcmp (getvarlocal2 (), "vismod2.c") != 0)
180 puts ("`getvarlocal2' returns wrong value");
181 res = 1;
184 /* Now the case where there is no local definition. */
185 if (protvarinmod != getvarinmod1 ())
187 puts ("`protvarinmod' in main and mod1 have not same address");
188 res = 1;
190 if (protvarinmod == getvarinmod2 ())
192 puts ("`protvarinmod' in main and mod2 have same address");
193 res = 1;
195 if (strcmp (getvarinmod1 (), "vismod1.c") != 0)
197 puts ("`getvarinmod1' returns wrong value");
198 res = 1;
200 if (strcmp (getvarinmod2 (), "vismod2.c") != 0)
202 puts ("`getvarinmod2' returns wrong value");
203 res = 1;
206 /* And a test where a variable definition is intercepted. */
207 if (protvaritcpt == getvaritcpt1 ())
209 puts ("`protvaritcpt' in main and mod1 have same address");
210 res = 1;
212 if (protvaritcpt == getvaritcpt2 ())
214 puts ("`protvaritcpt' in main and mod2 have same address");
215 res = 1;
217 if (protvaritcpt != getvaritcpt3 ())
219 puts ("`protvaritcpt' in main and mod3 have not same address");
220 res = 1;
222 if (getvaritcpt1 () == getvaritcpt2 ())
224 puts ("`protvaritcpt' in mod1 and mod2 have same address");
225 res = 1;
227 if (strcmp (protvaritcpt, "vismod3.c") != 0)
229 puts ("`protvaritcpt in main has wrong value");
230 res = 1;
232 if (strcmp (getvaritcpt1 (), "vismod1.c") != 0)
234 puts ("`getvaritcpt1' returns wrong value");
235 res = 1;
237 if (strcmp (getvaritcpt2 (), "vismod2.c") != 0)
239 puts ("`getvaritcpt2' returns wrong value");
240 res = 1;
243 return res;
248 protlocal (void)
250 return 0x1;