Fix unwind info in x86 memcmp-ssse3.
[glibc.git] / elf / vismain.c
blobebf9b65c347a1daca5084f5cc01f84f87acb59c7
1 /* Copyright (C) 2000, 2003 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 printf ("&protinmod in main (%p) != &protinmod in mod1 (%p)\n",
90 protinmod, getinmod1 ());
91 res = 1;
93 if (protinmod == getinmod2 ())
95 puts ("`protinmod' in main and mod2 have same address");
96 res = 1;
98 if (getinmod1 () == getinmod2 ())
100 puts ("`protinmod' in mod1 and mod2 have same address");
101 res = 1;
103 if (protinmod () + getinmod1 () () + getinmod2 () () != 0x4800)
105 puts ("pointers to `protinmod' in mod1 or mod2 incorrect");
106 res = 1;
108 val = protinmod () + callinmod1 () + callinmod2 ();
109 if (val != 0x15800)
111 printf ("calling of `protinmod' leads to wrong result (%#x)\n", val);
112 res = 1;
115 /* A very similar text. Same setup for the main object and the modules
116 but this time we have another definition in a preloaded module. This
117 one intercepts the references from the main object. */
118 if (protitcpt != getitcpt3 ())
120 printf ("&protitcpt in main (%p) != &protitcpt in mod3 (%p)\n",
121 &protitcpt, getitcpt3 ());
122 res = 1;
124 if (protitcpt == getitcpt1 ())
126 puts ("`protitcpt' in main and mod1 have same address");
127 res = 1;
129 if (protitcpt == getitcpt2 ())
131 puts ("`protitcpt' in main and mod2 have same address");
132 res = 1;
134 if (getitcpt1 () == getitcpt2 ())
136 puts ("`protitcpt' in mod1 and mod2 have same address");
137 res = 1;
139 val = protitcpt () + getitcpt1 () () + getitcpt2 () () + getitcpt3 () ();
140 if (val != 0x8440000)
142 printf ("\
143 pointers to `protitcpt' in mod1 or mod2 or mod3 incorrect (%#x)\n", val);
144 res = 1;
146 val = protitcpt () + callitcpt1 () + callitcpt2 () + callitcpt3 ();
147 if (val != 0x19540000)
149 printf ("calling of `protitcpt' leads to wrong result (%#x)\n", val);
150 res = 1;
153 /* Now look at variables. First a variable which is available
154 everywhere. We must have three different addresses. */
155 if (&protvarlocal == getvarlocal1 ())
157 puts ("`protvarlocal' in main and mod1 have same address");
158 res = 1;
160 if (&protvarlocal == getvarlocal2 ())
162 puts ("`protvarlocal' in main and mod2 have same address");
163 res = 1;
165 if (getvarlocal1 () == getvarlocal2 ())
167 puts ("`protvarlocal' in mod1 and mod2 have same address");
168 res = 1;
170 if (strcmp (protvarlocal, __FILE__) != 0)
172 puts ("`protvarlocal in main has wrong value");
173 res = 1;
175 if (strcmp (*getvarlocal1 (), "vismod1.c") != 0)
177 puts ("`getvarlocal1' returns wrong value");
178 res = 1;
180 if (strcmp (*getvarlocal2 (), "vismod2.c") != 0)
182 puts ("`getvarlocal2' returns wrong value");
183 res = 1;
186 /* Now the case where there is no local definition. */
187 if (&protvarinmod != getvarinmod1 ())
189 printf ("&protvarinmod in main (%p) != &protitcpt in mod1 (%p)\n",
190 &protvarinmod, getvarinmod1 ());
191 // XXX Possibly enable once fixed.
192 // res = 1;
194 if (&protvarinmod == getvarinmod2 ())
196 puts ("`protvarinmod' in main and mod2 have same address");
197 res = 1;
199 if (strcmp (*getvarinmod1 (), "vismod1.c") != 0)
201 puts ("`getvarinmod1' returns wrong value");
202 res = 1;
204 if (strcmp (*getvarinmod2 (), "vismod2.c") != 0)
206 puts ("`getvarinmod2' returns wrong value");
207 res = 1;
210 /* And a test where a variable definition is intercepted. */
211 if (&protvaritcpt == getvaritcpt1 ())
213 puts ("`protvaritcpt' in main and mod1 have same address");
214 res = 1;
216 if (&protvaritcpt == getvaritcpt2 ())
218 puts ("`protvaritcpt' in main and mod2 have same address");
219 res = 1;
221 if (&protvaritcpt != getvaritcpt3 ())
223 printf ("&protvaritcpt in main (%p) != &protvaritcpt in mod3 (%p)\n",
224 &protvaritcpt, getvaritcpt3 ());
225 // XXX Possibly enable once fixed.
226 // res = 1;
228 if (getvaritcpt1 () == getvaritcpt2 ())
230 puts ("`protvaritcpt' in mod1 and mod2 have same address");
231 res = 1;
233 if (strcmp (protvaritcpt, "vismod3.c") != 0)
235 puts ("`protvaritcpt in main has wrong value");
236 res = 1;
238 if (strcmp (*getvaritcpt1 (), "vismod1.c") != 0)
240 puts ("`getvaritcpt1' returns wrong value");
241 res = 1;
243 if (strcmp (*getvaritcpt2 (), "vismod2.c") != 0)
245 puts ("`getvaritcpt2' returns wrong value");
246 res = 1;
249 return res;
254 protlocal (void)
256 return 0x1;