1 /* Test the protected visibility when main is linked with modb and moda
3 1. Protected symbols, protected1, protected2 and protected3, defined
4 in moda, are used in moda.
5 2. Protected symbol, protected3, defined in modb, are used in modb
6 3. Symbol, protected1, defined in modb, is used in main and modb.
7 4. Symbol, protected2, defined in main, is used in main.
8 5. Symbol, protected3, defined in modb, is also used in main.
10 Copyright (C) 2015 Free Software Foundation, Inc.
11 This file is part of the GNU C Library.
13 The GNU C Library is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 2.1 of the License, or (at your option) any later version.
18 The GNU C Library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
23 You should have received a copy of the GNU Lesser General Public
24 License along with the GNU C Library; if not, see
25 <http://www.gnu.org/licenses/>. */
27 /* This file must be compiled as PIE to avoid copy relocation when
28 accessing protected symbols defined in shared libaries since copy
29 relocation doesn't work with protected symbols and linker in
30 binutils 2.26 enforces this rule. */
36 #include "tst-protected1mod.h"
38 /* Prototype for our test function. */
39 extern int do_test (void);
43 #define TEST_FUNCTION do_test ()
45 /* This defines the `main' function and some more. */
46 #include <test-skeleton.c>
53 /* Check if we get the same address for the protected data symbol. */
54 if (&protected1
== protected1a_p ())
56 puts ("`protected1' in main and moda has same address");
59 if (&protected1
!= protected1b_p ())
61 puts ("`protected1' in main and modb doesn't have same address");
65 /* Check if we get the right value for the protected data symbol. */
68 puts ("`protected1' in main and modb doesn't have same value");
72 /* Check if we get the right value for data defined in executable. */
75 puts ("`protected2' in main has the wrong value");
79 /* Check `protected1' in moda. */
80 if (!check_protected1 ())
82 puts ("`protected1' in moda has the wrong value");
86 /* Check `protected2' in moda. */
87 if (!check_protected2 ())
89 puts ("`protected2' in moda has the wrong value");
93 /* Check if we get the same address for the protected data symbol. */
94 if (&protected3
== protected3a_p ())
96 puts ("`protected3' in main and moda has same address");
99 if (&protected3
!= protected3b_p ())
101 puts ("`protected3' in main and modb doesn't have same address");
105 /* Check if we get the right value for the protected data symbol. */
106 if (protected3
!= -5)
108 puts ("`protected3' in main and modb doesn't have same value");
112 /* Check `protected3' in moda. */
113 if (!check_protected3a ())
115 puts ("`protected3' in moda has the wrong value");
119 /* Check `protected3' in modb. */
120 if (!check_protected3b ())
122 puts ("`protected3' in modb has the wrong value");
126 /* Set `protected2' in moda to 30. */
127 set_protected2 (300);
129 /* Check `protected2' in moda. */
130 if (!check_protected2 ())
132 puts ("`protected2' in moda has the wrong value");
136 /* Check if we get the right value for data defined in executable. */
137 if (protected2
!= -1)
139 puts ("`protected2' in main has the wrong value");
143 /* Set `protected1' in moda to 30. */
144 set_protected1a (30);
146 /* Check `protected1' in moda. */
147 if (!check_protected1 ())
149 puts ("`protected1' in moda has the wrong value");
153 /* Check if we get the same value for the protected data symbol. */
154 if (protected1
!= -3)
156 puts ("`protected1' in main has the wrong value");
162 /* Check `protected2' in moda. */
163 if (!check_protected2 ())
165 puts ("`protected2' in moda has the wrong value");
169 /* Check if data defined in executable is changed. */
170 if (protected2
!= -300)
172 puts ("`protected2' in main is changed");
176 /* Set `protected1' in modb to 40. */
177 set_protected1b (40);
179 /* Check `protected1' in moda. */
180 if (!check_protected1 ())
182 puts ("`protected1' in moda has the wrong value");
186 /* Check if we get the updated value for the protected data symbol. */
187 if (protected1
!= 40)
189 puts ("`protected1' in main doesn't have the updated value");
193 /* Set `protected3' in moda to 80. */
194 set_protected3a (80);
196 /* Check `protected3' in moda. */
197 if (!check_protected3a ())
199 puts ("`protected3' in moda has the wrong value");
203 /* Check if we get the updated value for the protected data symbol. */
204 if (protected3
!= -5)
206 puts ("`protected3' in main doesn't have the updated value");
210 /* Check `protected3' in modb. */
211 if (!check_protected3b ())
213 puts ("`protected3' in modb has the wrong value");
217 /* Set `protected3' in modb to 100. */
218 set_protected3b (100);
220 /* Check `protected3' in moda. */
221 if (!check_protected3a ())
223 puts ("`protected3' in moda has the wrong value");
227 /* Check if we get the updated value for the protected data symbol. */
228 if (protected3
!= 100)
230 puts ("`protected3' in main doesn't have the updated value");
234 /* Check `protected3' in modb. */
235 if (!check_protected3b ())
237 puts ("`protected3' in modb has the wrong value");