1 /* Copyright (C) 2000 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 puts ("`protinmod' in main and mod1 don't have same address");
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 puts ("`protitcpt' in main and mod3 don't have same address");
122 if (protitcpt
== getitcpt1 ())
124 puts ("`protitcpt' in main and mod1 have same address");
127 if (protitcpt
== getitcpt2 ())
129 puts ("`protitcpt' in main and mod2 have same address");
132 if (getitcpt1 () == getitcpt2 ())
134 puts ("`protitcpt' in mod1 and mod2 have same address");
137 val
= protitcpt () + getitcpt1 () () + getitcpt2 () () + getitcpt3 () ();
138 if (val
!= 0x8440000)
141 pointers to `protitcpt' in mod1 or mod2 or mod3 incorrect (%#x)\n", val
);
144 val
= protitcpt () + callitcpt1 () + callitcpt2 () + callitcpt3 ();
145 if (val
!= 0x19540000)
147 printf ("calling of `protitcpt' leads to wrong result (%#x)\n", val
);
151 /* Now look at variables. First a variable which is available
152 everywhere. We must have three different addresses. */
153 if (protvarlocal
== getvarlocal1 ())
155 puts ("`protvarlocal' in main and mod1 have same address");
158 if (protvarlocal
== getvarlocal2 ())
160 puts ("`protvarlocal' in main and mod2 have same address");
163 if (getvarlocal1 () == getvarlocal2 ())
165 puts ("`protvarlocal' in mod1 and mod2 have same address");
168 if (strcmp (protvarlocal
, __FILE__
) != 0)
170 puts ("`protvarlocal in main has wrong value");
173 if (strcmp (getvarlocal1 (), "vismod1.c") != 0)
175 puts ("`getvarlocal1' returns wrong value");
178 if (strcmp (getvarlocal2 (), "vismod2.c") != 0)
180 puts ("`getvarlocal2' returns wrong value");
184 /* Now the case where there is no local definition. */
185 if (protvarinmod
!= getvarinmod1 ())
187 puts ("`protvarinmod' in main and mod1 have not same address");
190 if (protvarinmod
== getvarinmod2 ())
192 puts ("`protvarinmod' in main and mod2 have same address");
195 if (strcmp (getvarinmod1 (), "vismod1.c") != 0)
197 puts ("`getvarinmod1' returns wrong value");
200 if (strcmp (getvarinmod2 (), "vismod2.c") != 0)
202 puts ("`getvarinmod2' returns wrong value");
206 /* And a test where a variable definition is intercepted. */
207 if (protvaritcpt
== getvaritcpt1 ())
209 puts ("`protvaritcpt' in main and mod1 have same address");
212 if (protvaritcpt
== getvaritcpt2 ())
214 puts ("`protvaritcpt' in main and mod2 have same address");
217 if (protvaritcpt
!= getvaritcpt3 ())
219 puts ("`protvaritcpt' in main and mod3 have not same address");
222 if (getvaritcpt1 () == getvaritcpt2 ())
224 puts ("`protvaritcpt' in mod1 and mod2 have same address");
227 if (strcmp (protvaritcpt
, "vismod3.c") != 0)
229 puts ("`protvaritcpt in main has wrong value");
232 if (strcmp (getvaritcpt1 (), "vismod1.c") != 0)
234 puts ("`getvaritcpt1' returns wrong value");
237 if (strcmp (getvaritcpt2 (), "vismod2.c") != 0)
239 puts ("`getvaritcpt2' returns wrong value");