Remove i486 subdirectory
[glibc.git] / elf / vismain.c
blob05b374812c80c6cae7037ee0a49f0a149ecc9754
1 /* Copyright (C) 2000-2015 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 /* This file must be compiled as PIE to avoid copy relocation when
19 accessing protected symbols defined in shared libaries since copy
20 relocation doesn't work with protected symbols and linker in
21 binutils 2.26 enforces this rule. */
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
27 #include "vismod.h"
29 /* Prototype for our test function. */
30 extern int do_test (void);
32 #define TEST_FUNCTION do_test ()
34 /* This defines the `main' function and some more. */
35 #include <test-skeleton.c>
38 /* Prototypes for local functions. */
39 extern int protlocal (void);
41 const char *protvarlocal = __FILE__;
42 extern const char *protvarinmod;
43 extern const char *protvaritcpt;
45 int
46 do_test (void)
48 int res = 0;
49 int val;
51 /* First test: check whether .protected is handled correctly by the
52 assembler/linker. The uses of `protlocal' in the DSOs and in the
53 main program should all be resolved with the local definitions. */
54 val = protlocal () + calllocal1 () + calllocal2 ();
55 if (val != 0x155)
57 puts ("\
58 The handling of `.protected' seems to be implemented incorrectly: giving up");
59 abort ();
61 puts ("`.protected' seems to be handled correctly, good!");
63 /* Function pointers: for functions which are marked local and for
64 which definitions are available all function pointers must be
65 distinct. */
66 if (protlocal == getlocal1 ())
68 puts ("`protlocal' in main and mod1 have same address");
69 res = 1;
71 if (protlocal == getlocal2 ())
73 puts ("`protlocal' in main and mod2 have same address");
74 res = 1;
76 if (getlocal1 () == getlocal2 ())
78 puts ("`protlocal' in mod1 and mod2 have same address");
79 res = 1;
81 if (getlocal1 () () + getlocal2 () () != 0x44)
83 puts ("pointers to `protlocal' in mod1 or mod2 incorrect");
84 res = 1;
87 /* Next test. This is similar to the last one but the function we
88 are calling is not defined in the main object. This means that
89 the invocation in the main object uses the definition in the
90 first DSO. */
91 if (protinmod != getinmod1 ())
93 printf ("&protinmod in main (%p) != &protinmod in mod1 (%p)\n",
94 protinmod, getinmod1 ());
95 res = 1;
97 if (protinmod == getinmod2 ())
99 puts ("`protinmod' in main and mod2 have same address");
100 res = 1;
102 if (getinmod1 () == getinmod2 ())
104 puts ("`protinmod' in mod1 and mod2 have same address");
105 res = 1;
107 if (protinmod () + getinmod1 () () + getinmod2 () () != 0x4800)
109 puts ("pointers to `protinmod' in mod1 or mod2 incorrect");
110 res = 1;
112 val = protinmod () + callinmod1 () + callinmod2 ();
113 if (val != 0x15800)
115 printf ("calling of `protinmod' leads to wrong result (%#x)\n", val);
116 res = 1;
119 /* A very similar text. Same setup for the main object and the modules
120 but this time we have another definition in a preloaded module. This
121 one intercepts the references from the main object. */
122 if (protitcpt != getitcpt3 ())
124 printf ("&protitcpt in main (%p) != &protitcpt in mod3 (%p)\n",
125 &protitcpt, getitcpt3 ());
126 res = 1;
128 if (protitcpt == getitcpt1 ())
130 puts ("`protitcpt' in main and mod1 have same address");
131 res = 1;
133 if (protitcpt == getitcpt2 ())
135 puts ("`protitcpt' in main and mod2 have same address");
136 res = 1;
138 if (getitcpt1 () == getitcpt2 ())
140 puts ("`protitcpt' in mod1 and mod2 have same address");
141 res = 1;
143 val = protitcpt () + getitcpt1 () () + getitcpt2 () () + getitcpt3 () ();
144 if (val != 0x8440000)
146 printf ("\
147 pointers to `protitcpt' in mod1 or mod2 or mod3 incorrect (%#x)\n", val);
148 res = 1;
150 val = protitcpt () + callitcpt1 () + callitcpt2 () + callitcpt3 ();
151 if (val != 0x19540000)
153 printf ("calling of `protitcpt' leads to wrong result (%#x)\n", val);
154 res = 1;
157 /* Now look at variables. First a variable which is available
158 everywhere. We must have three different addresses. */
159 if (&protvarlocal == getvarlocal1 ())
161 puts ("`protvarlocal' in main and mod1 have same address");
162 res = 1;
164 if (&protvarlocal == getvarlocal2 ())
166 puts ("`protvarlocal' in main and mod2 have same address");
167 res = 1;
169 if (getvarlocal1 () == getvarlocal2 ())
171 puts ("`protvarlocal' in mod1 and mod2 have same address");
172 res = 1;
174 if (strcmp (protvarlocal, __FILE__) != 0)
176 puts ("`protvarlocal in main has wrong value");
177 res = 1;
179 if (strcmp (*getvarlocal1 (), "vismod1.c") != 0)
181 puts ("`getvarlocal1' returns wrong value");
182 res = 1;
184 if (strcmp (*getvarlocal2 (), "vismod2.c") != 0)
186 puts ("`getvarlocal2' returns wrong value");
187 res = 1;
190 /* Now the case where there is no local definition. */
191 if (&protvarinmod != getvarinmod1 ())
193 printf ("&protvarinmod in main (%p) != &protitcpt in mod1 (%p)\n",
194 &protvarinmod, getvarinmod1 ());
195 // XXX Possibly enable once fixed.
196 // res = 1;
198 if (&protvarinmod == getvarinmod2 ())
200 puts ("`protvarinmod' in main and mod2 have same address");
201 res = 1;
203 if (strcmp (*getvarinmod1 (), "vismod1.c") != 0)
205 puts ("`getvarinmod1' returns wrong value");
206 res = 1;
208 if (strcmp (*getvarinmod2 (), "vismod2.c") != 0)
210 puts ("`getvarinmod2' returns wrong value");
211 res = 1;
214 /* And a test where a variable definition is intercepted. */
215 if (&protvaritcpt == getvaritcpt1 ())
217 puts ("`protvaritcpt' in main and mod1 have same address");
218 res = 1;
220 if (&protvaritcpt == getvaritcpt2 ())
222 puts ("`protvaritcpt' in main and mod2 have same address");
223 res = 1;
225 if (&protvaritcpt != getvaritcpt3 ())
227 printf ("&protvaritcpt in main (%p) != &protvaritcpt in mod3 (%p)\n",
228 &protvaritcpt, getvaritcpt3 ());
229 // XXX Possibly enable once fixed.
230 // res = 1;
232 if (getvaritcpt1 () == getvaritcpt2 ())
234 puts ("`protvaritcpt' in mod1 and mod2 have same address");
235 res = 1;
237 if (strcmp (protvaritcpt, "vismod3.c") != 0)
239 puts ("`protvaritcpt in main has wrong value");
240 res = 1;
242 if (strcmp (*getvaritcpt1 (), "vismod1.c") != 0)
244 puts ("`getvaritcpt1' returns wrong value");
245 res = 1;
247 if (strcmp (*getvaritcpt2 (), "vismod2.c") != 0)
249 puts ("`getvaritcpt2' returns wrong value");
250 res = 1;
253 return res;
258 protlocal (void)
260 return 0x1;