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. */
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
;
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 ();
58 The handling of `.protected' seems to be implemented incorrectly: giving up");
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
66 if (protlocal
== getlocal1 ())
68 puts ("`protlocal' in main and mod1 have same address");
71 if (protlocal
== getlocal2 ())
73 puts ("`protlocal' in main and mod2 have same address");
76 if (getlocal1 () == getlocal2 ())
78 puts ("`protlocal' in mod1 and mod2 have same address");
81 if (getlocal1 () () + getlocal2 () () != 0x44)
83 puts ("pointers to `protlocal' in mod1 or mod2 incorrect");
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
91 if (protinmod
!= getinmod1 ())
93 printf ("&protinmod in main (%p) != &protinmod in mod1 (%p)\n",
94 protinmod
, getinmod1 ());
97 if (protinmod
== getinmod2 ())
99 puts ("`protinmod' in main and mod2 have same address");
102 if (getinmod1 () == getinmod2 ())
104 puts ("`protinmod' in mod1 and mod2 have same address");
107 if (protinmod () + getinmod1 () () + getinmod2 () () != 0x4800)
109 puts ("pointers to `protinmod' in mod1 or mod2 incorrect");
112 val
= protinmod () + callinmod1 () + callinmod2 ();
115 printf ("calling of `protinmod' leads to wrong result (%#x)\n", val
);
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 ());
128 if (protitcpt
== getitcpt1 ())
130 puts ("`protitcpt' in main and mod1 have same address");
133 if (protitcpt
== getitcpt2 ())
135 puts ("`protitcpt' in main and mod2 have same address");
138 if (getitcpt1 () == getitcpt2 ())
140 puts ("`protitcpt' in mod1 and mod2 have same address");
143 val
= protitcpt () + getitcpt1 () () + getitcpt2 () () + getitcpt3 () ();
144 if (val
!= 0x8440000)
147 pointers to `protitcpt' in mod1 or mod2 or mod3 incorrect (%#x)\n", val
);
150 val
= protitcpt () + callitcpt1 () + callitcpt2 () + callitcpt3 ();
151 if (val
!= 0x19540000)
153 printf ("calling of `protitcpt' leads to wrong result (%#x)\n", val
);
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");
164 if (&protvarlocal
== getvarlocal2 ())
166 puts ("`protvarlocal' in main and mod2 have same address");
169 if (getvarlocal1 () == getvarlocal2 ())
171 puts ("`protvarlocal' in mod1 and mod2 have same address");
174 if (strcmp (protvarlocal
, __FILE__
) != 0)
176 puts ("`protvarlocal in main has wrong value");
179 if (strcmp (*getvarlocal1 (), "vismod1.c") != 0)
181 puts ("`getvarlocal1' returns wrong value");
184 if (strcmp (*getvarlocal2 (), "vismod2.c") != 0)
186 puts ("`getvarlocal2' returns wrong value");
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.
198 if (&protvarinmod
== getvarinmod2 ())
200 puts ("`protvarinmod' in main and mod2 have same address");
203 if (strcmp (*getvarinmod1 (), "vismod1.c") != 0)
205 puts ("`getvarinmod1' returns wrong value");
208 if (strcmp (*getvarinmod2 (), "vismod2.c") != 0)
210 puts ("`getvarinmod2' returns wrong value");
214 /* And a test where a variable definition is intercepted. */
215 if (&protvaritcpt
== getvaritcpt1 ())
217 puts ("`protvaritcpt' in main and mod1 have same address");
220 if (&protvaritcpt
== getvaritcpt2 ())
222 puts ("`protvaritcpt' in main and mod2 have same address");
225 if (&protvaritcpt
!= getvaritcpt3 ())
227 printf ("&protvaritcpt in main (%p) != &protvaritcpt in mod3 (%p)\n",
228 &protvaritcpt
, getvaritcpt3 ());
229 // XXX Possibly enable once fixed.
232 if (getvaritcpt1 () == getvaritcpt2 ())
234 puts ("`protvaritcpt' in mod1 and mod2 have same address");
237 if (strcmp (protvaritcpt
, "vismod3.c") != 0)
239 puts ("`protvaritcpt in main has wrong value");
242 if (strcmp (*getvaritcpt1 (), "vismod1.c") != 0)
244 puts ("`getvaritcpt1' returns wrong value");
247 if (strcmp (*getvaritcpt2 (), "vismod2.c") != 0)
249 puts ("`getvaritcpt2' returns wrong value");