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, see
16 <http://www.gnu.org/licenses/>. */
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
;
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 ();
53 The handling of `.protected' seems to be implemented incorrectly: giving up");
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
61 if (protlocal
== getlocal1 ())
63 puts ("`protlocal' in main and mod1 have same address");
66 if (protlocal
== getlocal2 ())
68 puts ("`protlocal' in main and mod2 have same address");
71 if (getlocal1 () == getlocal2 ())
73 puts ("`protlocal' in mod1 and mod2 have same address");
76 if (getlocal1 () () + getlocal2 () () != 0x44)
78 puts ("pointers to `protlocal' in mod1 or mod2 incorrect");
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
86 if (protinmod
!= getinmod1 ())
88 printf ("&protinmod in main (%p) != &protinmod in mod1 (%p)\n",
89 protinmod
, getinmod1 ());
92 if (protinmod
== getinmod2 ())
94 puts ("`protinmod' in main and mod2 have same address");
97 if (getinmod1 () == getinmod2 ())
99 puts ("`protinmod' in mod1 and mod2 have same address");
102 if (protinmod () + getinmod1 () () + getinmod2 () () != 0x4800)
104 puts ("pointers to `protinmod' in mod1 or mod2 incorrect");
107 val
= protinmod () + callinmod1 () + callinmod2 ();
110 printf ("calling of `protinmod' leads to wrong result (%#x)\n", val
);
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 ());
123 if (protitcpt
== getitcpt1 ())
125 puts ("`protitcpt' in main and mod1 have same address");
128 if (protitcpt
== getitcpt2 ())
130 puts ("`protitcpt' in main and mod2 have same address");
133 if (getitcpt1 () == getitcpt2 ())
135 puts ("`protitcpt' in mod1 and mod2 have same address");
138 val
= protitcpt () + getitcpt1 () () + getitcpt2 () () + getitcpt3 () ();
139 if (val
!= 0x8440000)
142 pointers to `protitcpt' in mod1 or mod2 or mod3 incorrect (%#x)\n", val
);
145 val
= protitcpt () + callitcpt1 () + callitcpt2 () + callitcpt3 ();
146 if (val
!= 0x19540000)
148 printf ("calling of `protitcpt' leads to wrong result (%#x)\n", val
);
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");
159 if (&protvarlocal
== getvarlocal2 ())
161 puts ("`protvarlocal' in main and mod2 have same address");
164 if (getvarlocal1 () == getvarlocal2 ())
166 puts ("`protvarlocal' in mod1 and mod2 have same address");
169 if (strcmp (protvarlocal
, __FILE__
) != 0)
171 puts ("`protvarlocal in main has wrong value");
174 if (strcmp (*getvarlocal1 (), "vismod1.c") != 0)
176 puts ("`getvarlocal1' returns wrong value");
179 if (strcmp (*getvarlocal2 (), "vismod2.c") != 0)
181 puts ("`getvarlocal2' returns wrong value");
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.
193 if (&protvarinmod
== getvarinmod2 ())
195 puts ("`protvarinmod' in main and mod2 have same address");
198 if (strcmp (*getvarinmod1 (), "vismod1.c") != 0)
200 puts ("`getvarinmod1' returns wrong value");
203 if (strcmp (*getvarinmod2 (), "vismod2.c") != 0)
205 puts ("`getvarinmod2' returns wrong value");
209 /* And a test where a variable definition is intercepted. */
210 if (&protvaritcpt
== getvaritcpt1 ())
212 puts ("`protvaritcpt' in main and mod1 have same address");
215 if (&protvaritcpt
== getvaritcpt2 ())
217 puts ("`protvaritcpt' in main and mod2 have same address");
220 if (&protvaritcpt
!= getvaritcpt3 ())
222 printf ("&protvaritcpt in main (%p) != &protvaritcpt in mod3 (%p)\n",
223 &protvaritcpt
, getvaritcpt3 ());
224 // XXX Possibly enable once fixed.
227 if (getvaritcpt1 () == getvaritcpt2 ())
229 puts ("`protvaritcpt' in mod1 and mod2 have same address");
232 if (strcmp (protvaritcpt
, "vismod3.c") != 0)
234 puts ("`protvaritcpt in main has wrong value");
237 if (strcmp (*getvaritcpt1 (), "vismod1.c") != 0)
239 puts ("`getvaritcpt1' returns wrong value");
242 if (strcmp (*getvaritcpt2 (), "vismod2.c") != 0)
244 puts ("`getvaritcpt2' returns wrong value");