Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 1 | From 68802ca536b01ab21cfa58e11ef332e30d9a3c5e Mon Sep 17 00:00:00 2001 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Mon, 7 Dec 2015 23:39:54 +0000 |
| 4 | Subject: [PATCH] handle sysroot support for nativesdk-gcc |
| 5 | |
| 6 | Being able to build a nativesdk gcc is useful, particularly in cases |
| 7 | where the host compiler may be of an incompatible version (or a 32 |
| 8 | bit compiler is needed). |
| 9 | |
| 10 | Sadly, building nativesdk-gcc is not straight forward. We install |
| 11 | nativesdk-gcc into a relocatable location and this means that its |
| 12 | library locations can change. "Normal" sysroot support doesn't help |
| 13 | in this case since the values of paths like "libdir" change, not just |
| 14 | base root directory of the system. |
| 15 | |
| 16 | In order to handle this we do two things: |
| 17 | |
| 18 | a) Add %r into spec file markup which can be used for injected paths |
| 19 | such as SYSTEMLIBS_DIR (see gcc_multilib_setup()). |
| 20 | b) Add other paths which need relocation into a .gccrelocprefix section |
| 21 | which the relocation code will notice and adjust automatically. |
| 22 | |
| 23 | Upstream-Status: Inappropriate |
| 24 | RP 2015/7/28 |
| 25 | |
| 26 | Extend the gccrelocprefix support to musl config too, this ensures |
| 27 | that gcc will get right bits in SDK installations |
| 28 | |
| 29 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 30 | |
| 31 | Added PREFIXVAR and EXEC_PREFIXVAR to support runtime relocation. Without |
| 32 | these as part of the gccrelocprefix the system can't do runtime relocation |
| 33 | if the executable is moved. (These paths were missed in the original |
| 34 | implementation.) |
| 35 | |
| 36 | Signed-off-by: Mark Hatle <mark.hatle@kernel.crashing.org> |
| 37 | --- |
| 38 | gcc/c-family/c-opts.c | 4 +-- |
| 39 | gcc/config/linux.h | 24 +++++++-------- |
| 40 | gcc/config/rs6000/sysv4.h | 24 +++++++-------- |
| 41 | gcc/cppdefault.c | 63 ++++++++++++++++++++++++--------------- |
| 42 | gcc/cppdefault.h | 13 ++++---- |
| 43 | gcc/gcc.c | 20 +++++++++---- |
| 44 | gcc/incpath.c | 12 ++++---- |
| 45 | gcc/prefix.c | 6 ++-- |
| 46 | 8 files changed, 94 insertions(+), 72 deletions(-) |
| 47 | |
| 48 | diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 49 | index 6f001e0bb6c..55ab07c278f 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 50 | --- a/gcc/c-family/c-opts.c |
| 51 | +++ b/gcc/c-family/c-opts.c |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 52 | @@ -1438,8 +1438,8 @@ add_prefixed_path (const char *suffix, incpath_kind chain) |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 53 | size_t prefix_len, suffix_len; |
| 54 | |
| 55 | suffix_len = strlen (suffix); |
| 56 | - prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR; |
| 57 | - prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len; |
| 58 | + prefix = iprefix ? iprefix : GCC_INCLUDE_DIRVAR; |
| 59 | + prefix_len = iprefix ? strlen (iprefix) : strlen(GCC_INCLUDE_DIRVAR) - 7; |
| 60 | |
| 61 | path = (char *) xmalloc (prefix_len + suffix_len + 1); |
| 62 | memcpy (path, prefix, prefix_len); |
| 63 | diff --git a/gcc/config/linux.h b/gcc/config/linux.h |
| 64 | index b525bcd56b3..ba02c013e30 100644 |
| 65 | --- a/gcc/config/linux.h |
| 66 | +++ b/gcc/config/linux.h |
| 67 | @@ -129,53 +129,53 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 68 | * Unfortunately, this is mostly duplicated from cppdefault.c */ |
| 69 | #if DEFAULT_LIBC == LIBC_MUSL |
| 70 | #define INCLUDE_DEFAULTS_MUSL_GPP \ |
| 71 | - { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \ |
| 72 | + { GPLUSPLUS_INCLUDE_DIRVAR, "G++", 1, 1, \ |
| 73 | GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \ |
| 74 | - { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \ |
| 75 | + { GPLUSPLUS_TOOL_INCLUDE_DIRVAR, "G++", 1, 1, \ |
| 76 | GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \ |
| 77 | - { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \ |
| 78 | + { GPLUSPLUS_BACKWARD_INCLUDE_DIRVAR, "G++", 1, 1, \ |
| 79 | GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, |
| 80 | |
| 81 | #ifdef LOCAL_INCLUDE_DIR |
| 82 | #define INCLUDE_DEFAULTS_MUSL_LOCAL \ |
| 83 | - { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \ |
| 84 | - { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 }, |
| 85 | + { LOCAL_INCLUDE_DIRVAR, 0, 0, 1, 1, 2 }, \ |
| 86 | + { LOCAL_INCLUDE_DIRVAR, 0, 0, 1, 1, 0 }, |
| 87 | #else |
| 88 | #define INCLUDE_DEFAULTS_MUSL_LOCAL |
| 89 | #endif |
| 90 | |
| 91 | #ifdef PREFIX_INCLUDE_DIR |
| 92 | #define INCLUDE_DEFAULTS_MUSL_PREFIX \ |
| 93 | - { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0}, |
| 94 | + { PREFIX_INCLUDE_DIRVAR, 0, 0, 1, 0, 0}, |
| 95 | #else |
| 96 | #define INCLUDE_DEFAULTS_MUSL_PREFIX |
| 97 | #endif |
| 98 | |
| 99 | #ifdef CROSS_INCLUDE_DIR |
| 100 | #define INCLUDE_DEFAULTS_MUSL_CROSS \ |
| 101 | - { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0}, |
| 102 | + { CROSS_INCLUDE_DIRVAR, "GCC", 0, 0, 0, 0}, |
| 103 | #else |
| 104 | #define INCLUDE_DEFAULTS_MUSL_CROSS |
| 105 | #endif |
| 106 | |
| 107 | #ifdef TOOL_INCLUDE_DIR |
| 108 | #define INCLUDE_DEFAULTS_MUSL_TOOL \ |
| 109 | - { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0}, |
| 110 | + { TOOL_INCLUDE_DIRVAR, "BINUTILS", 0, 1, 0, 0}, |
| 111 | #else |
| 112 | #define INCLUDE_DEFAULTS_MUSL_TOOL |
| 113 | #endif |
| 114 | |
| 115 | #ifdef GCC_INCLUDE_SUBDIR_TARGET |
| 116 | #define INCLUDE_DEFAULTS_MUSL_SUBDIR_TARGET \ |
| 117 | - { STANDARD_STARTFILE_PREFIX_2 GCC_INCLUDE_SUBDIR_TARGET, "GCC", 0, 0, 1, 0}, |
| 118 | + { STANDARD_STARTFILE_PREFIX_2VAR, "GCC", 0, 0, 1, 0}, |
| 119 | #else |
| 120 | #define INCLUDE_DEFAULTS_MUSL_SUBDIR_TARGET |
| 121 | #endif |
| 122 | |
| 123 | #ifdef NATIVE_SYSTEM_HEADER_DIR |
| 124 | #define INCLUDE_DEFAULTS_MUSL_NATIVE \ |
| 125 | - { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \ |
| 126 | - { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 }, |
| 127 | + { NATIVE_SYSTEM_HEADER_DIRVAR, 0, 0, 0, 1, 2 }, \ |
| 128 | + { NATIVE_SYSTEM_HEADER_DIRVAR, 0, 0, 0, 1, 0 }, |
| 129 | #else |
| 130 | #define INCLUDE_DEFAULTS_MUSL_NATIVE |
| 131 | #endif |
| 132 | @@ -200,7 +200,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 133 | INCLUDE_DEFAULTS_MUSL_TOOL \ |
| 134 | INCLUDE_DEFAULTS_MUSL_SUBDIR_TARGET \ |
| 135 | INCLUDE_DEFAULTS_MUSL_NATIVE \ |
| 136 | - { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \ |
| 137 | + { GCC_INCLUDE_DIRVAR, "GCC", 0, 1, 0, 0 }, \ |
| 138 | { 0, 0, 0, 0, 0, 0 } \ |
| 139 | } |
| 140 | #endif |
| 141 | diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h |
| 142 | index 0c2bba5ea32..313a8de4417 100644 |
| 143 | --- a/gcc/config/rs6000/sysv4.h |
| 144 | +++ b/gcc/config/rs6000/sysv4.h |
| 145 | @@ -959,53 +959,53 @@ ncrtn.o%s" |
| 146 | /* Include order changes for musl, same as in generic linux.h. */ |
| 147 | #if DEFAULT_LIBC == LIBC_MUSL |
| 148 | #define INCLUDE_DEFAULTS_MUSL_GPP \ |
| 149 | - { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \ |
| 150 | + { GPLUSPLUS_INCLUDE_DIRVAR, "G++", 1, 1, \ |
| 151 | GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \ |
| 152 | - { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \ |
| 153 | + { GPLUSPLUS_TOOL_INCLUDE_DIRVAR, "G++", 1, 1, \ |
| 154 | GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \ |
| 155 | - { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \ |
| 156 | + { GPLUSPLUS_BACKWARD_INCLUDE_DIRVAR, "G++", 1, 1, \ |
| 157 | GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, |
| 158 | |
| 159 | #ifdef LOCAL_INCLUDE_DIR |
| 160 | #define INCLUDE_DEFAULTS_MUSL_LOCAL \ |
| 161 | - { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \ |
| 162 | - { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 }, |
| 163 | + { LOCAL_INCLUDE_DIRVAR, 0, 0, 1, 1, 2 }, \ |
| 164 | + { LOCAL_INCLUDE_DIRVAR, 0, 0, 1, 1, 0 }, |
| 165 | #else |
| 166 | #define INCLUDE_DEFAULTS_MUSL_LOCAL |
| 167 | #endif |
| 168 | |
| 169 | #ifdef PREFIX_INCLUDE_DIR |
| 170 | #define INCLUDE_DEFAULTS_MUSL_PREFIX \ |
| 171 | - { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0}, |
| 172 | + { PREFIX_INCLUDE_DIRVAR, 0, 0, 1, 0, 0}, |
| 173 | #else |
| 174 | #define INCLUDE_DEFAULTS_MUSL_PREFIX |
| 175 | #endif |
| 176 | |
| 177 | #ifdef CROSS_INCLUDE_DIR |
| 178 | #define INCLUDE_DEFAULTS_MUSL_CROSS \ |
| 179 | - { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0}, |
| 180 | + { CROSS_INCLUDE_DIRVAR, "GCC", 0, 0, 0, 0}, |
| 181 | #else |
| 182 | #define INCLUDE_DEFAULTS_MUSL_CROSS |
| 183 | #endif |
| 184 | |
| 185 | #ifdef TOOL_INCLUDE_DIR |
| 186 | #define INCLUDE_DEFAULTS_MUSL_TOOL \ |
| 187 | - { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0}, |
| 188 | + { TOOL_INCLUDE_DIRVAR, "BINUTILS", 0, 1, 0, 0}, |
| 189 | #else |
| 190 | #define INCLUDE_DEFAULTS_MUSL_TOOL |
| 191 | #endif |
| 192 | |
| 193 | #ifdef GCC_INCLUDE_SUBDIR_TARGET |
| 194 | #define INCLUDE_DEFAULTS_MUSL_SUBDIR_TARGET \ |
| 195 | - { STANDARD_STARTFILE_PREFIX_2 GCC_INCLUDE_SUBDIR_TARGET, "GCC", 0, 0, 1, 0}, |
| 196 | + { STANDARD_STARTFILE_PREFIX_2VAR, "GCC", 0, 0, 1, 0}, |
| 197 | #else |
| 198 | #define INCLUDE_DEFAULTS_MUSL_SUBDIR_TARGET |
| 199 | #endif |
| 200 | |
| 201 | #ifdef NATIVE_SYSTEM_HEADER_DIR |
| 202 | #define INCLUDE_DEFAULTS_MUSL_NATIVE \ |
| 203 | - { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \ |
| 204 | - { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 }, |
| 205 | + { NATIVE_SYSTEM_HEADER_DIRVAR, 0, 0, 0, 1, 2 }, \ |
| 206 | + { NATIVE_SYSTEM_HEADER_DIRVAR, 0, 0, 0, 1, 0 }, |
| 207 | #else |
| 208 | #define INCLUDE_DEFAULTS_MUSL_NATIVE |
| 209 | #endif |
| 210 | @@ -1030,7 +1030,7 @@ ncrtn.o%s" |
| 211 | INCLUDE_DEFAULTS_MUSL_TOOL \ |
| 212 | INCLUDE_DEFAULTS_MUSL_SUBDIR_TARGET \ |
| 213 | INCLUDE_DEFAULTS_MUSL_NATIVE \ |
| 214 | - { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \ |
| 215 | + { GCC_INCLUDE_DIRVAR, "GCC", 0, 1, 0, 0 }, \ |
| 216 | { 0, 0, 0, 0, 0, 0 } \ |
| 217 | } |
| 218 | #endif |
| 219 | diff --git a/gcc/cppdefault.c b/gcc/cppdefault.c |
| 220 | index d54d6ce0076..784a92a0c24 100644 |
| 221 | --- a/gcc/cppdefault.c |
| 222 | +++ b/gcc/cppdefault.c |
| 223 | @@ -35,6 +35,30 @@ |
| 224 | # undef CROSS_INCLUDE_DIR |
| 225 | #endif |
| 226 | |
| 227 | +static char GPLUSPLUS_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = GPLUSPLUS_INCLUDE_DIR; |
| 228 | +char GCC_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = GCC_INCLUDE_DIR; |
| 229 | +static char GPLUSPLUS_TOOL_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = GPLUSPLUS_TOOL_INCLUDE_DIR; |
| 230 | +static char GPLUSPLUS_BACKWARD_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = GPLUSPLUS_BACKWARD_INCLUDE_DIR; |
| 231 | +static char STANDARD_STARTFILE_PREFIX_2VAR[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_STARTFILE_PREFIX_2 GCC_INCLUDE_SUBDIR_TARGET; |
| 232 | +#ifdef LOCAL_INCLUDE_DIR |
| 233 | +static char LOCAL_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = LOCAL_INCLUDE_DIR; |
| 234 | +#endif |
| 235 | +#ifdef PREFIX_INCLUDE_DIR |
| 236 | +static char PREFIX_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = PREFIX_INCLUDE_DIR; |
| 237 | +#endif |
| 238 | +#ifdef FIXED_INCLUDE_DIR |
| 239 | +static char FIXED_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = FIXED_INCLUDE_DIR; |
| 240 | +#endif |
| 241 | +#ifdef CROSS_INCLUDE_DIR |
| 242 | +static char CROSS_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = CROSS_INCLUDE_DIR; |
| 243 | +#endif |
| 244 | +#ifdef TOOL_INCLUDE_DIR |
| 245 | +static char TOOL_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = TOOL_INCLUDE_DIR; |
| 246 | +#endif |
| 247 | +#ifdef NATIVE_SYSTEM_HEADER_DIR |
| 248 | +static char NATIVE_SYSTEM_HEADER_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = NATIVE_SYSTEM_HEADER_DIR; |
| 249 | +#endif |
| 250 | + |
| 251 | const struct default_include cpp_include_defaults[] |
| 252 | #ifdef INCLUDE_DEFAULTS |
| 253 | = INCLUDE_DEFAULTS; |
| 254 | @@ -42,17 +66,17 @@ const struct default_include cpp_include_defaults[] |
| 255 | = { |
| 256 | #ifdef GPLUSPLUS_INCLUDE_DIR |
| 257 | /* Pick up GNU C++ generic include files. */ |
| 258 | - { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, |
| 259 | + { GPLUSPLUS_INCLUDE_DIRVAR, "G++", 1, 1, |
| 260 | GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, |
| 261 | #endif |
| 262 | #ifdef GPLUSPLUS_TOOL_INCLUDE_DIR |
| 263 | /* Pick up GNU C++ target-dependent include files. */ |
| 264 | - { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, |
| 265 | + { GPLUSPLUS_TOOL_INCLUDE_DIRVAR, "G++", 1, 1, |
| 266 | GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, |
| 267 | #endif |
| 268 | #ifdef GPLUSPLUS_BACKWARD_INCLUDE_DIR |
| 269 | /* Pick up GNU C++ backward and deprecated include files. */ |
| 270 | - { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, |
| 271 | + { GPLUSPLUS_BACKWARD_INCLUDE_DIRVAR, "G++", 1, 1, |
| 272 | GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, |
| 273 | #endif |
| 274 | #ifdef GPLUSPLUS_LIBCXX_INCLUDE_DIR |
| 275 | @@ -62,23 +86,23 @@ const struct default_include cpp_include_defaults[] |
| 276 | #endif |
| 277 | #ifdef GCC_INCLUDE_DIR |
| 278 | /* This is the dir for gcc's private headers. */ |
| 279 | - { GCC_INCLUDE_DIR, "GCC", 0, 0, 0, 0 }, |
| 280 | + { GCC_INCLUDE_DIRVAR, "GCC", 0, 0, 0, 0 }, |
| 281 | #endif |
| 282 | #ifdef GCC_INCLUDE_SUBDIR_TARGET |
| 283 | /* This is the dir for gcc's private headers under the specified sysroot. */ |
| 284 | - { STANDARD_STARTFILE_PREFIX_2 GCC_INCLUDE_SUBDIR_TARGET, "GCC", 0, 0, 1, 0 }, |
| 285 | + { STANDARD_STARTFILE_PREFIX_2VAR, "GCC", 0, 0, 1, 0 }, |
| 286 | #endif |
| 287 | #ifdef LOCAL_INCLUDE_DIR |
| 288 | /* /usr/local/include comes before the fixincluded header files. */ |
| 289 | - { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, |
| 290 | - { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 }, |
| 291 | + { LOCAL_INCLUDE_DIRVAR, 0, 0, 1, 1, 2 }, |
| 292 | + { LOCAL_INCLUDE_DIRVAR, 0, 0, 1, 1, 0 }, |
| 293 | #endif |
| 294 | #ifdef PREFIX_INCLUDE_DIR |
| 295 | - { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0 }, |
| 296 | + { PREFIX_INCLUDE_DIRVAR, 0, 0, 1, 0, 0 }, |
| 297 | #endif |
| 298 | #ifdef FIXED_INCLUDE_DIR |
| 299 | /* This is the dir for fixincludes. */ |
| 300 | - { FIXED_INCLUDE_DIR, "GCC", 0, 0, 0, |
| 301 | + { FIXED_INCLUDE_DIRVAR, "GCC", 0, 0, 0, |
| 302 | /* A multilib suffix needs adding if different multilibs use |
| 303 | different headers. */ |
| 304 | #ifdef SYSROOT_HEADERS_SUFFIX_SPEC |
| 305 | @@ -90,33 +114,24 @@ const struct default_include cpp_include_defaults[] |
| 306 | #endif |
| 307 | #ifdef CROSS_INCLUDE_DIR |
| 308 | /* One place the target system's headers might be. */ |
| 309 | - { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0 }, |
| 310 | + { CROSS_INCLUDE_DIRVAR, "GCC", 0, 0, 0, 0 }, |
| 311 | #endif |
| 312 | #ifdef TOOL_INCLUDE_DIR |
| 313 | /* Another place the target system's headers might be. */ |
| 314 | - { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0 }, |
| 315 | + { TOOL_INCLUDE_DIRVAR, "BINUTILS", 0, 1, 0, 0 }, |
| 316 | #endif |
| 317 | #ifdef NATIVE_SYSTEM_HEADER_DIR |
| 318 | /* /usr/include comes dead last. */ |
| 319 | - { NATIVE_SYSTEM_HEADER_DIR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 2 }, |
| 320 | - { NATIVE_SYSTEM_HEADER_DIR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 0 }, |
| 321 | + { NATIVE_SYSTEM_HEADER_DIRVAR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 2 }, |
| 322 | + { NATIVE_SYSTEM_HEADER_DIRVAR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 0 }, |
| 323 | #endif |
| 324 | { 0, 0, 0, 0, 0, 0 } |
| 325 | }; |
| 326 | #endif /* no INCLUDE_DEFAULTS */ |
| 327 | |
| 328 | -#ifdef GCC_INCLUDE_DIR |
| 329 | -const char cpp_GCC_INCLUDE_DIR[] = GCC_INCLUDE_DIR; |
| 330 | -const size_t cpp_GCC_INCLUDE_DIR_len = sizeof GCC_INCLUDE_DIR - 8; |
| 331 | -#else |
| 332 | -const char cpp_GCC_INCLUDE_DIR[] = ""; |
| 333 | -const size_t cpp_GCC_INCLUDE_DIR_len = 0; |
| 334 | -#endif |
| 335 | - |
| 336 | /* The configured prefix. */ |
| 337 | -const char cpp_PREFIX[] = PREFIX; |
| 338 | -const size_t cpp_PREFIX_len = sizeof PREFIX - 1; |
| 339 | -const char cpp_EXEC_PREFIX[] = STANDARD_EXEC_PREFIX; |
| 340 | +char PREFIXVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = PREFIX; |
| 341 | +char EXEC_PREFIXVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_EXEC_PREFIX; |
| 342 | |
| 343 | /* This value is set by cpp_relocated at runtime */ |
| 344 | const char *gcc_exec_prefix; |
| 345 | diff --git a/gcc/cppdefault.h b/gcc/cppdefault.h |
| 346 | index fd3c655db1c..20669ac427d 100644 |
| 347 | --- a/gcc/cppdefault.h |
| 348 | +++ b/gcc/cppdefault.h |
| 349 | @@ -33,7 +33,8 @@ |
| 350 | |
| 351 | struct default_include |
| 352 | { |
| 353 | - const char *const fname; /* The name of the directory. */ |
| 354 | + const char *fname; /* The name of the directory. */ |
| 355 | + |
| 356 | const char *const component; /* The component containing the directory |
| 357 | (see update_path in prefix.c) */ |
| 358 | const char cplusplus; /* When this is non-zero, we should only |
| 359 | @@ -55,17 +56,13 @@ struct default_include |
| 360 | }; |
| 361 | |
| 362 | extern const struct default_include cpp_include_defaults[]; |
| 363 | -extern const char cpp_GCC_INCLUDE_DIR[]; |
| 364 | -extern const size_t cpp_GCC_INCLUDE_DIR_len; |
| 365 | +extern char GCC_INCLUDE_DIRVAR[] __attribute__ ((section (".gccrelocprefix"))); |
| 366 | |
| 367 | /* The configure-time prefix, i.e., the value supplied as the argument |
| 368 | to --prefix=. */ |
| 369 | -extern const char cpp_PREFIX[]; |
| 370 | +extern char PREFIXVAR[] __attribute__ ((section (".gccrelocprefix"))); |
| 371 | /* The length of the configure-time prefix. */ |
| 372 | -extern const size_t cpp_PREFIX_len; |
| 373 | -/* The configure-time execution prefix. This is typically the lib/gcc |
| 374 | - subdirectory of cpp_PREFIX. */ |
| 375 | -extern const char cpp_EXEC_PREFIX[]; |
| 376 | +extern char EXEC_PREFIXVAR[] __attribute__ ((section (".gccrelocprefix"))); |
| 377 | /* The run-time execution prefix. This is typically the lib/gcc |
| 378 | subdirectory of the actual installation. */ |
| 379 | extern const char *gcc_exec_prefix; |
| 380 | diff --git a/gcc/gcc.c b/gcc/gcc.c |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 381 | index bdee2671532..36e8af38630 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 382 | --- a/gcc/gcc.c |
| 383 | +++ b/gcc/gcc.c |
| 384 | @@ -252,6 +252,8 @@ FILE *report_times_to_file = NULL; |
| 385 | #endif |
| 386 | static const char *target_system_root = DEFAULT_TARGET_SYSTEM_ROOT; |
| 387 | |
| 388 | +static char target_relocatable_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = SYSTEMLIBS_DIR; |
| 389 | + |
| 390 | /* Nonzero means pass the updated target_system_root to the compiler. */ |
| 391 | |
| 392 | static int target_system_root_changed; |
| 393 | @@ -568,6 +570,7 @@ or with constant text in a single argument. |
| 394 | %G process LIBGCC_SPEC as a spec. |
| 395 | %R Output the concatenation of target_system_root and |
| 396 | target_sysroot_suffix. |
| 397 | + %r Output the base path target_relocatable_prefix |
| 398 | %S process STARTFILE_SPEC as a spec. A capital S is actually used here. |
| 399 | %E process ENDFILE_SPEC as a spec. A capital E is actually used here. |
| 400 | %C process CPP_SPEC as a spec. |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 401 | @@ -1620,10 +1623,10 @@ static const char *gcc_libexec_prefix; |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 402 | gcc_exec_prefix is set because, in that case, we know where the |
| 403 | compiler has been installed, and use paths relative to that |
| 404 | location instead. */ |
| 405 | -static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX; |
| 406 | -static const char *const standard_libexec_prefix = STANDARD_LIBEXEC_PREFIX; |
| 407 | -static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX; |
| 408 | -static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX; |
| 409 | +static char standard_exec_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_EXEC_PREFIX; |
| 410 | +static char standard_libexec_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_LIBEXEC_PREFIX; |
| 411 | +static char standard_bindir_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_BINDIR_PREFIX; |
| 412 | +static char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX; |
| 413 | |
| 414 | /* For native compilers, these are well-known paths containing |
| 415 | components that may be provided by the system. For cross |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 416 | @@ -1631,9 +1634,9 @@ static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX; |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 417 | static const char *md_exec_prefix = MD_EXEC_PREFIX; |
| 418 | static const char *md_startfile_prefix = MD_STARTFILE_PREFIX; |
| 419 | static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1; |
| 420 | -static const char *const standard_startfile_prefix_1 |
| 421 | +static char standard_startfile_prefix_1[4096] __attribute__ ((section (".gccrelocprefix"))) |
| 422 | = STANDARD_STARTFILE_PREFIX_1; |
| 423 | -static const char *const standard_startfile_prefix_2 |
| 424 | +static char standard_startfile_prefix_2[4096] __attribute__ ((section (".gccrelocprefix"))) |
| 425 | = STANDARD_STARTFILE_PREFIX_2; |
| 426 | |
| 427 | /* A relative path to be used in finding the location of tools |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 428 | @@ -6570,6 +6573,11 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 429 | } |
| 430 | break; |
| 431 | |
| 432 | + case 'r': |
| 433 | + obstack_grow (&obstack, target_relocatable_prefix, |
| 434 | + strlen (target_relocatable_prefix)); |
| 435 | + break; |
| 436 | + |
| 437 | case 'S': |
| 438 | value = do_spec_1 (startfile_spec, 0, NULL); |
| 439 | if (value != 0) |
| 440 | diff --git a/gcc/incpath.c b/gcc/incpath.c |
| 441 | index fbfc0ce03b8..a82e543428b 100644 |
| 442 | --- a/gcc/incpath.c |
| 443 | +++ b/gcc/incpath.c |
| 444 | @@ -131,7 +131,7 @@ add_standard_paths (const char *sysroot, const char *iprefix, |
| 445 | int relocated = cpp_relocated (); |
| 446 | size_t len; |
| 447 | |
| 448 | - if (iprefix && (len = cpp_GCC_INCLUDE_DIR_len) != 0) |
| 449 | + if (iprefix && (len = strlen(GCC_INCLUDE_DIRVAR) - 7) != 0) |
| 450 | { |
| 451 | /* Look for directories that start with the standard prefix. |
| 452 | "Translate" them, i.e. replace /usr/local/lib/gcc... with |
| 453 | @@ -146,7 +146,7 @@ add_standard_paths (const char *sysroot, const char *iprefix, |
| 454 | now. */ |
| 455 | if (sysroot && p->add_sysroot) |
| 456 | continue; |
| 457 | - if (!filename_ncmp (p->fname, cpp_GCC_INCLUDE_DIR, len)) |
| 458 | + if (!filename_ncmp (p->fname, GCC_INCLUDE_DIRVAR, len)) |
| 459 | { |
| 460 | char *str = concat (iprefix, p->fname + len, NULL); |
| 461 | if (p->multilib == 1 && imultilib) |
| 462 | @@ -187,7 +187,7 @@ add_standard_paths (const char *sysroot, const char *iprefix, |
| 463 | free (sysroot_no_trailing_dir_separator); |
| 464 | } |
| 465 | else if (!p->add_sysroot && relocated |
| 466 | - && !filename_ncmp (p->fname, cpp_PREFIX, cpp_PREFIX_len)) |
| 467 | + && !filename_ncmp (p->fname, PREFIXVAR, strlen(PREFIXVAR))) |
| 468 | { |
| 469 | static const char *relocated_prefix; |
| 470 | char *ostr; |
| 471 | @@ -204,12 +204,12 @@ add_standard_paths (const char *sysroot, const char *iprefix, |
| 472 | dummy = concat (gcc_exec_prefix, "dummy", NULL); |
| 473 | relocated_prefix |
| 474 | = make_relative_prefix (dummy, |
| 475 | - cpp_EXEC_PREFIX, |
| 476 | - cpp_PREFIX); |
| 477 | + EXEC_PREFIXVAR, |
| 478 | + PREFIXVAR); |
| 479 | free (dummy); |
| 480 | } |
| 481 | ostr = concat (relocated_prefix, |
| 482 | - p->fname + cpp_PREFIX_len, |
| 483 | + p->fname + strlen(PREFIXVAR), |
| 484 | NULL); |
| 485 | str = update_path (ostr, p->component); |
| 486 | free (ostr); |
| 487 | diff --git a/gcc/prefix.c b/gcc/prefix.c |
| 488 | index 747c09de638..f728638dc65 100644 |
| 489 | --- a/gcc/prefix.c |
| 490 | +++ b/gcc/prefix.c |
| 491 | @@ -72,7 +72,9 @@ License along with GCC; see the file COPYING3. If not see |
| 492 | #include "prefix.h" |
| 493 | #include "common/common-target.h" |
| 494 | |
| 495 | -static const char *std_prefix = PREFIX; |
| 496 | +char PREFIXVAR1[4096] __attribute__ ((section (".gccrelocprefix"))) = PREFIX; |
| 497 | + |
| 498 | +static const char *std_prefix = PREFIXVAR1; |
| 499 | |
| 500 | static const char *get_key_value (char *); |
| 501 | static char *translate_name (char *); |
| 502 | @@ -212,7 +214,7 @@ translate_name (char *name) |
| 503 | prefix = getenv (key); |
| 504 | |
| 505 | if (prefix == 0) |
| 506 | - prefix = PREFIX; |
| 507 | + prefix = PREFIXVAR1; |
| 508 | |
| 509 | /* We used to strip trailing DIR_SEPARATORs here, but that can |
| 510 | sometimes yield a result with no separator when one was coded |