x86_64: Remove platform directory library loading test
[glibc.git] / elf / tst-protected1a.c
blobf0076ada1d3767c4b90f9bb96c082f73eb0f8a06
1 /* Test the protected visibility when main is linked with moda and modb
2 in that order:
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 moda, is also used in main and modb.
7 4. Symbol, protected2, defined in main, is used in main.
8 5. Symbol, protected3, defined in moda, is also used in main.
10 Copyright (C) 2015-2022 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 <https://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. */
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
36 #include "tst-protected1mod.h"
38 /* Prototype for our test function. */
39 extern int do_test (void);
41 int protected2 = -1;
43 /* This defines the `main' function and some more. */
44 #include <support/test-driver.c>
46 int
47 do_test (void)
49 int res = 0;
51 /* Check if we get the same address for the protected data symbol. */
52 if (&protected1 != protected1a_p ())
54 puts ("`protected1' in main and moda doesn't have same address");
55 res = 1;
57 if (&protected1 != protected1b_p ())
59 puts ("`protected1' in main and modb doesn't have same address");
60 res = 1;
63 /* Check if we get the right value for the protected data symbol. */
64 if (protected1 != 3)
66 puts ("`protected1' in main and moda doesn't have same value");
67 res = 1;
70 /* Check if we get the right value for data defined in executable. */
71 if (protected2 != -1)
73 puts ("`protected2' in main has the wrong value");
74 res = 1;
77 /* Check `protected1' in moda. */
78 if (!check_protected1 ())
80 puts ("`protected1' in moda has the wrong value");
81 res = 1;
84 /* Check `protected2' in moda. */
85 if (!check_protected2 ())
87 puts ("`protected2' in moda has the wrong value");
88 res = 1;
91 /* Check if we get the same address for the protected data symbol. */
92 if (&protected3 != protected3a_p ())
94 puts ("`protected3' in main and moda doesn't have same address");
95 res = 1;
97 if (&protected3 == protected3b_p ())
99 puts ("`protected3' in main and modb has same address");
100 res = 1;
103 /* Check if we get the right value for the protected data symbol. */
104 if (protected3 != 5)
106 puts ("`protected3' in main and moda doesn't have same value");
107 res = 1;
110 /* Check `protected3' in moda. */
111 if (!check_protected3a ())
113 puts ("`protected3' in moda has the wrong value");
114 res = 1;
117 /* Check `protected3' in modb. */
118 if (!check_protected3b ())
120 puts ("`protected3' in modb has the wrong value");
121 res = 1;
124 /* Set `protected2' in moda to 30. */
125 set_protected2 (300);
127 /* Check `protected2' in moda. */
128 if (!check_protected2 ())
130 puts ("`protected2' in moda has the wrong value");
131 res = 1;
134 /* Set `protected1' in moda to 30. */
135 set_protected1a (30);
137 /* Check `protected1' in moda. */
138 if (!check_protected1 ())
140 puts ("`protected1' in moda has the wrong value");
141 res = 1;
144 /* Check if we get the updated value for the protected data symbol. */
145 if (protected1 != 30)
147 puts ("`protected1' in main doesn't have the updated value");
148 res = 1;
151 protected2 = -300;
153 /* Check `protected2' in moda. */
154 if (!check_protected2 ())
156 puts ("`protected2' in moda has the wrong value");
157 res = 1;
160 /* Check if data defined in executable is changed. */
161 if (protected2 != -300)
163 puts ("`protected2' in main is changed");
164 res = 1;
167 /* Set `protected1' in modb to 40. */
168 set_protected1b (40);
169 set_expected_protected1 (40);
171 /* Check `protected1' in moda. */
172 if (!check_protected1 ())
174 puts ("`protected1' in moda has the wrong value");
175 res = 1;
178 /* Check if we get the updated value for the protected data symbol. */
179 if (protected1 != 40)
181 puts ("`protected1' in main doesn't have the updated value");
182 res = 1;
185 /* Set `protected3' in moda to 80. */
186 set_protected3a (80);
188 /* Check `protected3' in moda. */
189 if (!check_protected3a ())
191 puts ("`protected3' in moda has the wrong value");
192 res = 1;
195 /* Check if we get the updated value for the protected data symbol. */
196 if (protected3 != 80)
198 puts ("`protected3' in main doesn't have the updated value");
199 res = 1;
202 /* Check `protected3' in modb. */
203 if (!check_protected3b ())
205 puts ("`protected3' in modb has the wrong value");
206 res = 1;
209 /* Set `protected3' in modb to 100. */
210 set_protected3b (100);
212 /* Check `protected3' in moda. */
213 if (!check_protected3a ())
215 puts ("`protected3' in moda has the wrong value");
216 res = 1;
219 /* Check if we get the updated value for the protected data symbol. */
220 if (protected3 != 80)
222 puts ("`protected3' in main doesn't have the updated value");
223 res = 1;
226 /* Check `protected3' in modb. */
227 if (!check_protected3b ())
229 puts ("`protected3' in modb has the wrong value");
230 res = 1;
233 return res;