]>
Commit | Line | Data |
---|---|---|
b168057a | 1 | /* Copyright (C) 2000-2015 Free Software Foundation, Inc. |
eec8ef5a UD |
2 | This file is part of the GNU C Library. |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
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. | |
eec8ef5a UD |
8 | |
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 | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
eec8ef5a | 13 | |
41bdb6e2 | 14 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. */ | |
eec8ef5a UD |
17 | |
18 | #include <stdio.h> | |
19 | #include <stdlib.h> | |
20 | #include <string.h> | |
21 | ||
715ed1e9 AJ |
22 | #include "vismod.h" |
23 | ||
741845cb AJ |
24 | /* Prototype for our test function. */ |
25 | extern int do_test (void); | |
26 | ||
27 | #define TEST_FUNCTION do_test () | |
28 | ||
29 | /* This defines the `main' function and some more. */ | |
30 | #include <test-skeleton.c> | |
31 | ||
eec8ef5a UD |
32 | |
33 | /* Prototypes for local functions. */ | |
34 | extern int protlocal (void); | |
35 | ||
36 | const char *protvarlocal = __FILE__; | |
37 | extern const char *protvarinmod; | |
38 | extern const char *protvaritcpt; | |
39 | ||
40 | int | |
741845cb | 41 | do_test (void) |
eec8ef5a UD |
42 | { |
43 | int res = 0; | |
44 | int val; | |
45 | ||
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) | |
51 | { | |
52 | puts ("\ | |
53 | The handling of `.protected' seems to be implemented incorrectly: giving up"); | |
54 | abort (); | |
55 | } | |
56 | puts ("`.protected' seems to be handled correctly, good!"); | |
57 | ||
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 ()) | |
62 | { | |
63 | puts ("`protlocal' in main and mod1 have same address"); | |
64 | res = 1; | |
65 | } | |
66 | if (protlocal == getlocal2 ()) | |
67 | { | |
68 | puts ("`protlocal' in main and mod2 have same address"); | |
69 | res = 1; | |
70 | } | |
71 | if (getlocal1 () == getlocal2 ()) | |
72 | { | |
73 | puts ("`protlocal' in mod1 and mod2 have same address"); | |
74 | res = 1; | |
75 | } | |
76 | if (getlocal1 () () + getlocal2 () () != 0x44) | |
77 | { | |
78 | puts ("pointers to `protlocal' in mod1 or mod2 incorrect"); | |
79 | res = 1; | |
80 | } | |
81 | ||
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 ()) | |
87 | { | |
5972c58b RM |
88 | printf ("&protinmod in main (%p) != &protinmod in mod1 (%p)\n", |
89 | protinmod, getinmod1 ()); | |
eec8ef5a UD |
90 | res = 1; |
91 | } | |
92 | if (protinmod == getinmod2 ()) | |
93 | { | |
94 | puts ("`protinmod' in main and mod2 have same address"); | |
95 | res = 1; | |
96 | } | |
97 | if (getinmod1 () == getinmod2 ()) | |
98 | { | |
99 | puts ("`protinmod' in mod1 and mod2 have same address"); | |
100 | res = 1; | |
101 | } | |
102 | if (protinmod () + getinmod1 () () + getinmod2 () () != 0x4800) | |
103 | { | |
104 | puts ("pointers to `protinmod' in mod1 or mod2 incorrect"); | |
105 | res = 1; | |
106 | } | |
107 | val = protinmod () + callinmod1 () + callinmod2 (); | |
108 | if (val != 0x15800) | |
109 | { | |
110 | printf ("calling of `protinmod' leads to wrong result (%#x)\n", val); | |
111 | res = 1; | |
112 | } | |
113 | ||
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 ()) | |
118 | { | |
5972c58b RM |
119 | printf ("&protitcpt in main (%p) != &protitcpt in mod3 (%p)\n", |
120 | &protitcpt, getitcpt3 ()); | |
eec8ef5a UD |
121 | res = 1; |
122 | } | |
123 | if (protitcpt == getitcpt1 ()) | |
124 | { | |
125 | puts ("`protitcpt' in main and mod1 have same address"); | |
126 | res = 1; | |
127 | } | |
128 | if (protitcpt == getitcpt2 ()) | |
129 | { | |
130 | puts ("`protitcpt' in main and mod2 have same address"); | |
131 | res = 1; | |
132 | } | |
133 | if (getitcpt1 () == getitcpt2 ()) | |
134 | { | |
135 | puts ("`protitcpt' in mod1 and mod2 have same address"); | |
136 | res = 1; | |
137 | } | |
138 | val = protitcpt () + getitcpt1 () () + getitcpt2 () () + getitcpt3 () (); | |
139 | if (val != 0x8440000) | |
140 | { | |
141 | printf ("\ | |
142 | pointers to `protitcpt' in mod1 or mod2 or mod3 incorrect (%#x)\n", val); | |
143 | res = 1; | |
144 | } | |
145 | val = protitcpt () + callitcpt1 () + callitcpt2 () + callitcpt3 (); | |
146 | if (val != 0x19540000) | |
147 | { | |
148 | printf ("calling of `protitcpt' leads to wrong result (%#x)\n", val); | |
149 | res = 1; | |
150 | } | |
151 | ||
152 | /* Now look at variables. First a variable which is available | |
153 | everywhere. We must have three different addresses. */ | |
5972c58b | 154 | if (&protvarlocal == getvarlocal1 ()) |
eec8ef5a UD |
155 | { |
156 | puts ("`protvarlocal' in main and mod1 have same address"); | |
157 | res = 1; | |
158 | } | |
5972c58b | 159 | if (&protvarlocal == getvarlocal2 ()) |
eec8ef5a UD |
160 | { |
161 | puts ("`protvarlocal' in main and mod2 have same address"); | |
162 | res = 1; | |
163 | } | |
164 | if (getvarlocal1 () == getvarlocal2 ()) | |
165 | { | |
166 | puts ("`protvarlocal' in mod1 and mod2 have same address"); | |
167 | res = 1; | |
168 | } | |
169 | if (strcmp (protvarlocal, __FILE__) != 0) | |
170 | { | |
171 | puts ("`protvarlocal in main has wrong value"); | |
172 | res = 1; | |
173 | } | |
5972c58b | 174 | if (strcmp (*getvarlocal1 (), "vismod1.c") != 0) |
eec8ef5a UD |
175 | { |
176 | puts ("`getvarlocal1' returns wrong value"); | |
177 | res = 1; | |
178 | } | |
5972c58b | 179 | if (strcmp (*getvarlocal2 (), "vismod2.c") != 0) |
eec8ef5a UD |
180 | { |
181 | puts ("`getvarlocal2' returns wrong value"); | |
182 | res = 1; | |
183 | } | |
184 | ||
185 | /* Now the case where there is no local definition. */ | |
5972c58b | 186 | if (&protvarinmod != getvarinmod1 ()) |
eec8ef5a | 187 | { |
5972c58b RM |
188 | printf ("&protvarinmod in main (%p) != &protitcpt in mod1 (%p)\n", |
189 | &protvarinmod, getvarinmod1 ()); | |
d403820a UD |
190 | // XXX Possibly enable once fixed. |
191 | // res = 1; | |
eec8ef5a | 192 | } |
5972c58b | 193 | if (&protvarinmod == getvarinmod2 ()) |
eec8ef5a UD |
194 | { |
195 | puts ("`protvarinmod' in main and mod2 have same address"); | |
196 | res = 1; | |
197 | } | |
5972c58b | 198 | if (strcmp (*getvarinmod1 (), "vismod1.c") != 0) |
eec8ef5a UD |
199 | { |
200 | puts ("`getvarinmod1' returns wrong value"); | |
201 | res = 1; | |
202 | } | |
5972c58b | 203 | if (strcmp (*getvarinmod2 (), "vismod2.c") != 0) |
eec8ef5a UD |
204 | { |
205 | puts ("`getvarinmod2' returns wrong value"); | |
206 | res = 1; | |
207 | } | |
208 | ||
209 | /* And a test where a variable definition is intercepted. */ | |
5972c58b | 210 | if (&protvaritcpt == getvaritcpt1 ()) |
eec8ef5a UD |
211 | { |
212 | puts ("`protvaritcpt' in main and mod1 have same address"); | |
213 | res = 1; | |
214 | } | |
5972c58b | 215 | if (&protvaritcpt == getvaritcpt2 ()) |
eec8ef5a UD |
216 | { |
217 | puts ("`protvaritcpt' in main and mod2 have same address"); | |
218 | res = 1; | |
219 | } | |
5972c58b | 220 | if (&protvaritcpt != getvaritcpt3 ()) |
eec8ef5a | 221 | { |
5972c58b RM |
222 | printf ("&protvaritcpt in main (%p) != &protvaritcpt in mod3 (%p)\n", |
223 | &protvaritcpt, getvaritcpt3 ()); | |
d403820a UD |
224 | // XXX Possibly enable once fixed. |
225 | // res = 1; | |
eec8ef5a UD |
226 | } |
227 | if (getvaritcpt1 () == getvaritcpt2 ()) | |
228 | { | |
229 | puts ("`protvaritcpt' in mod1 and mod2 have same address"); | |
230 | res = 1; | |
231 | } | |
232 | if (strcmp (protvaritcpt, "vismod3.c") != 0) | |
233 | { | |
234 | puts ("`protvaritcpt in main has wrong value"); | |
235 | res = 1; | |
236 | } | |
5972c58b | 237 | if (strcmp (*getvaritcpt1 (), "vismod1.c") != 0) |
eec8ef5a UD |
238 | { |
239 | puts ("`getvaritcpt1' returns wrong value"); | |
240 | res = 1; | |
241 | } | |
5972c58b | 242 | if (strcmp (*getvaritcpt2 (), "vismod2.c") != 0) |
eec8ef5a UD |
243 | { |
244 | puts ("`getvaritcpt2' returns wrong value"); | |
245 | res = 1; | |
246 | } | |
247 | ||
248 | return res; | |
249 | } | |
250 | ||
251 | ||
252 | int | |
253 | protlocal (void) | |
254 | { | |
255 | return 0x1; | |
256 | } |