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
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
;
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 ();
54 The handling of `.protected' seems to be implemented incorrectly: giving up");
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
62 if (protlocal
== getlocal1 ())
64 puts ("`protlocal' in main and mod1 have same address");
67 if (protlocal
== getlocal2 ())
69 puts ("`protlocal' in main and mod2 have same address");
72 if (getlocal1 () == getlocal2 ())
74 puts ("`protlocal' in mod1 and mod2 have same address");
77 if (getlocal1 () () + getlocal2 () () != 0x44)
79 puts ("pointers to `protlocal' in mod1 or mod2 incorrect");
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
87 if (protinmod
!= getinmod1 ())
89 printf ("&protinmod in main (%p) != &protinmod in mod1 (%p)\n",
90 protinmod
, getinmod1 ());
93 if (protinmod
== getinmod2 ())
95 puts ("`protinmod' in main and mod2 have same address");
98 if (getinmod1 () == getinmod2 ())
100 puts ("`protinmod' in mod1 and mod2 have same address");
103 if (protinmod () + getinmod1 () () + getinmod2 () () != 0x4800)
105 puts ("pointers to `protinmod' in mod1 or mod2 incorrect");
108 val
= protinmod () + callinmod1 () + callinmod2 ();
111 printf ("calling of `protinmod' leads to wrong result (%#x)\n", val
);
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 ());
124 if (protitcpt
== getitcpt1 ())
126 puts ("`protitcpt' in main and mod1 have same address");
129 if (protitcpt
== getitcpt2 ())
131 puts ("`protitcpt' in main and mod2 have same address");
134 if (getitcpt1 () == getitcpt2 ())
136 puts ("`protitcpt' in mod1 and mod2 have same address");
139 val
= protitcpt () + getitcpt1 () () + getitcpt2 () () + getitcpt3 () ();
140 if (val
!= 0x8440000)
143 pointers to `protitcpt' in mod1 or mod2 or mod3 incorrect (%#x)\n", val
);
146 val
= protitcpt () + callitcpt1 () + callitcpt2 () + callitcpt3 ();
147 if (val
!= 0x19540000)
149 printf ("calling of `protitcpt' leads to wrong result (%#x)\n", val
);
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");
160 if (&protvarlocal
== getvarlocal2 ())
162 puts ("`protvarlocal' in main and mod2 have same address");
165 if (getvarlocal1 () == getvarlocal2 ())
167 puts ("`protvarlocal' in mod1 and mod2 have same address");
170 if (strcmp (protvarlocal
, __FILE__
) != 0)
172 puts ("`protvarlocal in main has wrong value");
175 if (strcmp (*getvarlocal1 (), "vismod1.c") != 0)
177 puts ("`getvarlocal1' returns wrong value");
180 if (strcmp (*getvarlocal2 (), "vismod2.c") != 0)
182 puts ("`getvarlocal2' returns wrong value");
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.
194 if (&protvarinmod
== getvarinmod2 ())
196 puts ("`protvarinmod' in main and mod2 have same address");
199 if (strcmp (*getvarinmod1 (), "vismod1.c") != 0)
201 puts ("`getvarinmod1' returns wrong value");
204 if (strcmp (*getvarinmod2 (), "vismod2.c") != 0)
206 puts ("`getvarinmod2' returns wrong value");
210 /* And a test where a variable definition is intercepted. */
211 if (&protvaritcpt
== getvaritcpt1 ())
213 puts ("`protvaritcpt' in main and mod1 have same address");
216 if (&protvaritcpt
== getvaritcpt2 ())
218 puts ("`protvaritcpt' in main and mod2 have same address");
221 if (&protvaritcpt
!= getvaritcpt3 ())
223 printf ("&protvaritcpt in main (%p) != &protvaritcpt in mod3 (%p)\n",
224 &protvaritcpt
, getvaritcpt3 ());
225 // XXX Possibly enable once fixed.
228 if (getvaritcpt1 () == getvaritcpt2 ())
230 puts ("`protvaritcpt' in mod1 and mod2 have same address");
233 if (strcmp (protvaritcpt
, "vismod3.c") != 0)
235 puts ("`protvaritcpt in main has wrong value");
238 if (strcmp (*getvaritcpt1 (), "vismod1.c") != 0)
240 puts ("`getvaritcpt1' returns wrong value");
243 if (strcmp (*getvaritcpt2 (), "vismod2.c") != 0)
245 puts ("`getvaritcpt2' returns wrong value");