Update copyright notices with scripts/update-copyrights
[glibc.git] / elf / vismain.c
blobf91428b8a88bf69f1acd2e9e53bd73e658b9f3d1
1 /* Copyright (C) 2000-2014 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, see
16 <http://www.gnu.org/licenses/>. */
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
22 #include "vismod.h"
24 /* Prototype for our test function. */
25 extern int do_test (void);
27 #define TEST_FUNCTION do_test ()
29 /* This defines the `main' function and some more. */
30 #include <test-skeleton.c>
33 /* Prototypes for local functions. */
34 extern int protlocal (void);
36 const char *protvarlocal = __FILE__;
37 extern const char *protvarinmod;
38 extern const char *protvaritcpt;
40 int
41 do_test (void)
43 int res = 0;
44 int val;
46 /* First test: check whether .protected is handled correctly by the
47 assembler/linker. The uses of `protlocal' in the DSOs and in the
48 main program should all be resolved with the local definitions. */
49 val = protlocal () + calllocal1 () + calllocal2 ();
50 if (val != 0x155)
52 puts ("\
53 The handling of `.protected' seems to be implemented incorrectly: giving up");
54 abort ();
56 puts ("`.protected' seems to be handled correctly, good!");
58 /* Function pointers: for functions which are marked local and for
59 which definitions are available all function pointers must be
60 distinct. */
61 if (protlocal == getlocal1 ())
63 puts ("`protlocal' in main and mod1 have same address");
64 res = 1;
66 if (protlocal == getlocal2 ())
68 puts ("`protlocal' in main and mod2 have same address");
69 res = 1;
71 if (getlocal1 () == getlocal2 ())
73 puts ("`protlocal' in mod1 and mod2 have same address");
74 res = 1;
76 if (getlocal1 () () + getlocal2 () () != 0x44)
78 puts ("pointers to `protlocal' in mod1 or mod2 incorrect");
79 res = 1;
82 /* Next test. This is similar to the last one but the function we
83 are calling is not defined in the main object. This means that
84 the invocation in the main object uses the definition in the
85 first DSO. */
86 if (protinmod != getinmod1 ())
88 printf ("&protinmod in main (%p) != &protinmod in mod1 (%p)\n",
89 protinmod, getinmod1 ());
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 printf ("&protitcpt in main (%p) != &protitcpt in mod3 (%p)\n",
120 &protitcpt, getitcpt3 ());
121 res = 1;
123 if (protitcpt == getitcpt1 ())
125 puts ("`protitcpt' in main and mod1 have same address");
126 res = 1;
128 if (protitcpt == getitcpt2 ())
130 puts ("`protitcpt' in main and mod2 have same address");
131 res = 1;
133 if (getitcpt1 () == getitcpt2 ())
135 puts ("`protitcpt' in mod1 and mod2 have same address");
136 res = 1;
138 val = protitcpt () + getitcpt1 () () + getitcpt2 () () + getitcpt3 () ();
139 if (val != 0x8440000)
141 printf ("\
142 pointers to `protitcpt' in mod1 or mod2 or mod3 incorrect (%#x)\n", val);
143 res = 1;
145 val = protitcpt () + callitcpt1 () + callitcpt2 () + callitcpt3 ();
146 if (val != 0x19540000)
148 printf ("calling of `protitcpt' leads to wrong result (%#x)\n", val);
149 res = 1;
152 /* Now look at variables. First a variable which is available
153 everywhere. We must have three different addresses. */
154 if (&protvarlocal == getvarlocal1 ())
156 puts ("`protvarlocal' in main and mod1 have same address");
157 res = 1;
159 if (&protvarlocal == getvarlocal2 ())
161 puts ("`protvarlocal' in main and mod2 have same address");
162 res = 1;
164 if (getvarlocal1 () == getvarlocal2 ())
166 puts ("`protvarlocal' in mod1 and mod2 have same address");
167 res = 1;
169 if (strcmp (protvarlocal, __FILE__) != 0)
171 puts ("`protvarlocal in main has wrong value");
172 res = 1;
174 if (strcmp (*getvarlocal1 (), "vismod1.c") != 0)
176 puts ("`getvarlocal1' returns wrong value");
177 res = 1;
179 if (strcmp (*getvarlocal2 (), "vismod2.c") != 0)
181 puts ("`getvarlocal2' returns wrong value");
182 res = 1;
185 /* Now the case where there is no local definition. */
186 if (&protvarinmod != getvarinmod1 ())
188 printf ("&protvarinmod in main (%p) != &protitcpt in mod1 (%p)\n",
189 &protvarinmod, getvarinmod1 ());
190 // XXX Possibly enable once fixed.
191 // res = 1;
193 if (&protvarinmod == getvarinmod2 ())
195 puts ("`protvarinmod' in main and mod2 have same address");
196 res = 1;
198 if (strcmp (*getvarinmod1 (), "vismod1.c") != 0)
200 puts ("`getvarinmod1' returns wrong value");
201 res = 1;
203 if (strcmp (*getvarinmod2 (), "vismod2.c") != 0)
205 puts ("`getvarinmod2' returns wrong value");
206 res = 1;
209 /* And a test where a variable definition is intercepted. */
210 if (&protvaritcpt == getvaritcpt1 ())
212 puts ("`protvaritcpt' in main and mod1 have same address");
213 res = 1;
215 if (&protvaritcpt == getvaritcpt2 ())
217 puts ("`protvaritcpt' in main and mod2 have same address");
218 res = 1;
220 if (&protvaritcpt != getvaritcpt3 ())
222 printf ("&protvaritcpt in main (%p) != &protvaritcpt in mod3 (%p)\n",
223 &protvaritcpt, getvaritcpt3 ());
224 // XXX Possibly enable once fixed.
225 // res = 1;
227 if (getvaritcpt1 () == getvaritcpt2 ())
229 puts ("`protvaritcpt' in mod1 and mod2 have same address");
230 res = 1;
232 if (strcmp (protvaritcpt, "vismod3.c") != 0)
234 puts ("`protvaritcpt in main has wrong value");
235 res = 1;
237 if (strcmp (*getvaritcpt1 (), "vismod1.c") != 0)
239 puts ("`getvaritcpt1' returns wrong value");
240 res = 1;
242 if (strcmp (*getvaritcpt2 (), "vismod2.c") != 0)
244 puts ("`getvaritcpt2' returns wrong value");
245 res = 1;
248 return res;
253 protlocal (void)
255 return 0x1;