xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame^] | 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. |
| 9 | |
| 10 | Copyright (C) 2015-2016 Free Software Foundation, Inc. |
| 11 | This file is part of the GNU C Library. |
| 12 | |
| 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. |
| 17 | |
| 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. |
| 22 | |
| 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/>. */ |
| 26 | |
| 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. */ |
| 31 | |
| 32 | #include <stdio.h> |
| 33 | #include <stdlib.h> |
| 34 | #include <string.h> |
| 35 | |
| 36 | #include "tst-protected1mod.h" |
| 37 | |
| 38 | /* Prototype for our test function. */ |
| 39 | extern int do_test (void); |
| 40 | |
| 41 | int protected2 = -1; |
| 42 | |
| 43 | #define TEST_FUNCTION do_test () |
| 44 | |
| 45 | /* This defines the `main' function and some more. */ |
| 46 | #include <test-skeleton.c> |
| 47 | |
| 48 | int |
| 49 | do_test (void) |
| 50 | { |
| 51 | int res = 0; |
| 52 | |
| 53 | /* Check if we get the same address for the protected data symbol. */ |
| 54 | if (&protected1 != protected1a_p ()) |
| 55 | { |
| 56 | puts ("`protected1' in main and moda doesn't have same address"); |
| 57 | res = 1; |
| 58 | } |
| 59 | if (&protected1 != protected1b_p ()) |
| 60 | { |
| 61 | puts ("`protected1' in main and modb doesn't have same address"); |
| 62 | res = 1; |
| 63 | } |
| 64 | |
| 65 | /* Check if we get the right value for the protected data symbol. */ |
| 66 | if (protected1 != 3) |
| 67 | { |
| 68 | puts ("`protected1' in main and moda doesn't have same value"); |
| 69 | res = 1; |
| 70 | } |
| 71 | |
| 72 | /* Check if we get the right value for data defined in executable. */ |
| 73 | if (protected2 != -1) |
| 74 | { |
| 75 | puts ("`protected2' in main has the wrong value"); |
| 76 | res = 1; |
| 77 | } |
| 78 | |
| 79 | /* Check `protected1' in moda. */ |
| 80 | if (!check_protected1 ()) |
| 81 | { |
| 82 | puts ("`protected1' in moda has the wrong value"); |
| 83 | res = 1; |
| 84 | } |
| 85 | |
| 86 | /* Check `protected2' in moda. */ |
| 87 | if (!check_protected2 ()) |
| 88 | { |
| 89 | puts ("`protected2' in moda has the wrong value"); |
| 90 | res = 1; |
| 91 | } |
| 92 | |
| 93 | /* Check if we get the same address for the protected data symbol. */ |
| 94 | if (&protected3 != protected3a_p ()) |
| 95 | { |
| 96 | puts ("`protected3' in main and moda doesn't have same address"); |
| 97 | res = 1; |
| 98 | } |
| 99 | if (&protected3 == protected3b_p ()) |
| 100 | { |
| 101 | puts ("`protected3' in main and modb has same address"); |
| 102 | res = 1; |
| 103 | } |
| 104 | |
| 105 | /* Check if we get the right value for the protected data symbol. */ |
| 106 | if (protected3 != 5) |
| 107 | { |
| 108 | puts ("`protected3' in main and moda doesn't have same value"); |
| 109 | res = 1; |
| 110 | } |
| 111 | |
| 112 | /* Check `protected3' in moda. */ |
| 113 | if (!check_protected3a ()) |
| 114 | { |
| 115 | puts ("`protected3' in moda has the wrong value"); |
| 116 | res = 1; |
| 117 | } |
| 118 | |
| 119 | /* Check `protected3' in modb. */ |
| 120 | if (!check_protected3b ()) |
| 121 | { |
| 122 | puts ("`protected3' in modb has the wrong value"); |
| 123 | res = 1; |
| 124 | } |
| 125 | |
| 126 | /* Set `protected2' in moda to 30. */ |
| 127 | set_protected2 (300); |
| 128 | |
| 129 | /* Check `protected2' in moda. */ |
| 130 | if (!check_protected2 ()) |
| 131 | { |
| 132 | puts ("`protected2' in moda has the wrong value"); |
| 133 | res = 1; |
| 134 | } |
| 135 | |
| 136 | /* Set `protected1' in moda to 30. */ |
| 137 | set_protected1a (30); |
| 138 | |
| 139 | /* Check `protected1' in moda. */ |
| 140 | if (!check_protected1 ()) |
| 141 | { |
| 142 | puts ("`protected1' in moda has the wrong value"); |
| 143 | res = 1; |
| 144 | } |
| 145 | |
| 146 | /* Check if we get the updated value for the protected data symbol. */ |
| 147 | if (protected1 != 30) |
| 148 | { |
| 149 | puts ("`protected1' in main doesn't have the updated value"); |
| 150 | res = 1; |
| 151 | } |
| 152 | |
| 153 | protected2 = -300; |
| 154 | |
| 155 | /* Check `protected2' in moda. */ |
| 156 | if (!check_protected2 ()) |
| 157 | { |
| 158 | puts ("`protected2' in moda has the wrong value"); |
| 159 | res = 1; |
| 160 | } |
| 161 | |
| 162 | /* Check if data defined in executable is changed. */ |
| 163 | if (protected2 != -300) |
| 164 | { |
| 165 | puts ("`protected2' in main is changed"); |
| 166 | res = 1; |
| 167 | } |
| 168 | |
| 169 | /* Set `protected1' in modb to 40. */ |
| 170 | set_protected1b (40); |
| 171 | set_expected_protected1 (40); |
| 172 | |
| 173 | /* Check `protected1' in moda. */ |
| 174 | if (!check_protected1 ()) |
| 175 | { |
| 176 | puts ("`protected1' in moda has the wrong value"); |
| 177 | res = 1; |
| 178 | } |
| 179 | |
| 180 | /* Check if we get the updated value for the protected data symbol. */ |
| 181 | if (protected1 != 40) |
| 182 | { |
| 183 | puts ("`protected1' in main doesn't have the updated value"); |
| 184 | res = 1; |
| 185 | } |
| 186 | |
| 187 | /* Set `protected3' in moda to 80. */ |
| 188 | set_protected3a (80); |
| 189 | |
| 190 | /* Check `protected3' in moda. */ |
| 191 | if (!check_protected3a ()) |
| 192 | { |
| 193 | puts ("`protected3' in moda has the wrong value"); |
| 194 | res = 1; |
| 195 | } |
| 196 | |
| 197 | /* Check if we get the updated value for the protected data symbol. */ |
| 198 | if (protected3 != 80) |
| 199 | { |
| 200 | puts ("`protected3' in main doesn't have the updated value"); |
| 201 | res = 1; |
| 202 | } |
| 203 | |
| 204 | /* Check `protected3' in modb. */ |
| 205 | if (!check_protected3b ()) |
| 206 | { |
| 207 | puts ("`protected3' in modb has the wrong value"); |
| 208 | res = 1; |
| 209 | } |
| 210 | |
| 211 | /* Set `protected3' in modb to 100. */ |
| 212 | set_protected3b (100); |
| 213 | |
| 214 | /* Check `protected3' in moda. */ |
| 215 | if (!check_protected3a ()) |
| 216 | { |
| 217 | puts ("`protected3' in moda has the wrong value"); |
| 218 | res = 1; |
| 219 | } |
| 220 | |
| 221 | /* Check if we get the updated value for the protected data symbol. */ |
| 222 | if (protected3 != 80) |
| 223 | { |
| 224 | puts ("`protected3' in main doesn't have the updated value"); |
| 225 | res = 1; |
| 226 | } |
| 227 | |
| 228 | /* Check `protected3' in modb. */ |
| 229 | if (!check_protected3b ()) |
| 230 | { |
| 231 | puts ("`protected3' in modb has the wrong value"); |
| 232 | res = 1; |
| 233 | } |
| 234 | |
| 235 | return res; |
| 236 | } |