1From bbc75b93bff66891fa7ffb3af5c6ad53df1fff68 Mon Sep 17 00:00:00 2001 2From: Khem Raj <raj.khem@gmail.com> 3Date: Mon, 7 Dec 2015 23:39:54 +0000 4Subject: [PATCH] handle sysroot support for nativesdk-gcc 5 6Being able to build a nativesdk gcc is useful, particularly in cases 7where the host compiler may be of an incompatible version (or a 32 8bit compiler is needed). 9 10Sadly, building nativesdk-gcc is not straight forward. We install 11nativesdk-gcc into a relocatable location and this means that its 12library locations can change. "Normal" sysroot support doesn't help 13in this case since the values of paths like "libdir" change, not just 14base root directory of the system. 15 16In order to handle this we do two things: 17 18a) Add %r into spec file markup which can be used for injected paths 19 such as SYSTEMLIBS_DIR (see gcc_multilib_setup()). 20b) Add other paths which need relocation into a .gccrelocprefix section 21 which the relocation code will notice and adjust automatically. 22 23Upstream-Status: Inappropriate 24RP 2015/7/28 25 26Extend the gccrelocprefix support to musl config too, this ensures 27that gcc will get right bits in SDK installations 28 29Signed-off-by: Khem Raj <raj.khem@gmail.com> 30 31Added PREFIXVAR and EXEC_PREFIXVAR to support runtime relocation. Without 32these as part of the gccrelocprefix the system can't do runtime relocation 33if the executable is moved. (These paths were missed in the original 34implementation.) 35 36Signed-off-by: Mark Hatle <mark.hatle@kernel.crashing.org> 37--- 38 gcc/c-family/c-opts.cc | 4 +-- 39 gcc/config/linux.h | 24 +++++++-------- 40 gcc/config/rs6000/sysv4.h | 24 +++++++-------- 41 gcc/cppdefault.cc | 65 ++++++++++++++++++++++++--------------- 42 gcc/cppdefault.h | 13 +++----- 43 gcc/gcc.cc | 20 ++++++++---- 44 gcc/incpath.cc | 12 ++++---- 45 gcc/prefix.cc | 6 ++-- 46 8 files changed, 95 insertions(+), 73 deletions(-) 47 48diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc 49index c68a2a27469..77e9b5eceaa 100644 50--- a/gcc/c-family/c-opts.cc 51+++ b/gcc/c-family/c-opts.cc 52@@ -1458,8 +1458,8 @@ add_prefixed_path (const char *suffix, incpath_kind chain) 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); 63diff --git a/gcc/config/linux.h b/gcc/config/linux.h 64index 57496ff1f2f..c921cf6ef63 100644 65--- a/gcc/config/linux.h 66+++ b/gcc/config/linux.h 67@@ -121,53 +121,53 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 68 * Unfortunately, this is mostly duplicated from cppdefault.cc */ 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@@ -192,7 +192,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 141diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h 142index 3a443abcf6b..ef83a5a432e 100644 143--- a/gcc/config/rs6000/sysv4.h 144+++ b/gcc/config/rs6000/sysv4.h 145@@ -950,53 +950,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@@ -1021,7 +1021,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 219diff --git a/gcc/cppdefault.cc b/gcc/cppdefault.cc 220index 734590a7059..b4a8fc29e4a 100644 221--- a/gcc/cppdefault.cc 222+++ b/gcc/cppdefault.cc 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,26 +86,26 @@ 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 #ifndef SYSROOT_HEADERS_SUFFIX_SPEC 301- { FIXED_INCLUDE_DIR, "GCC", 0, 0, 0, 2 }, 302+ { FIXED_INCLUDE_DIRVAR, "GCC", 0, 0, 0, 2 }, 303 #endif 304- { FIXED_INCLUDE_DIR, "GCC", 0, 0, 0, 305+ { FIXED_INCLUDE_DIRVAR, "GCC", 0, 0, 0, 306 /* A multilib suffix needs adding if different multilibs use 307 different headers. */ 308 #ifdef SYSROOT_HEADERS_SUFFIX_SPEC 309@@ -93,33 +117,24 @@ const struct default_include cpp_include_defaults[] 310 #endif 311 #ifdef CROSS_INCLUDE_DIR 312 /* One place the target system's headers might be. */ 313- { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0 }, 314+ { CROSS_INCLUDE_DIRVAR, "GCC", 0, 0, 0, 0 }, 315 #endif 316 #ifdef TOOL_INCLUDE_DIR 317 /* Another place the target system's headers might be. */ 318- { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0 }, 319+ { TOOL_INCLUDE_DIRVAR, "BINUTILS", 0, 1, 0, 0 }, 320 #endif 321 #ifdef NATIVE_SYSTEM_HEADER_DIR 322 /* /usr/include comes dead last. */ 323- { NATIVE_SYSTEM_HEADER_DIR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 2 }, 324- { NATIVE_SYSTEM_HEADER_DIR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 0 }, 325+ { NATIVE_SYSTEM_HEADER_DIRVAR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 2 }, 326+ { NATIVE_SYSTEM_HEADER_DIRVAR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 0 }, 327 #endif 328 { 0, 0, 0, 0, 0, 0 } 329 }; 330 #endif /* no INCLUDE_DEFAULTS */ 331 332-#ifdef GCC_INCLUDE_DIR 333-const char cpp_GCC_INCLUDE_DIR[] = GCC_INCLUDE_DIR; 334-const size_t cpp_GCC_INCLUDE_DIR_len = sizeof GCC_INCLUDE_DIR - 8; 335-#else 336-const char cpp_GCC_INCLUDE_DIR[] = ""; 337-const size_t cpp_GCC_INCLUDE_DIR_len = 0; 338-#endif 339- 340 /* The configured prefix. */ 341-const char cpp_PREFIX[] = PREFIX; 342-const size_t cpp_PREFIX_len = sizeof PREFIX - 1; 343-const char cpp_EXEC_PREFIX[] = STANDARD_EXEC_PREFIX; 344+char PREFIXVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = PREFIX; 345+char EXEC_PREFIXVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_EXEC_PREFIX; 346 347 /* This value is set by cpp_relocated at runtime */ 348 const char *gcc_exec_prefix; 349diff --git a/gcc/cppdefault.h b/gcc/cppdefault.h 350index e26b424e99c..c9abb090dcd 100644 351--- a/gcc/cppdefault.h 352+++ b/gcc/cppdefault.h 353@@ -33,7 +33,8 @@ 354 355 struct default_include 356 { 357- const char *const fname; /* The name of the directory. */ 358+ const char *fname; /* The name of the directory. */ 359+ 360 const char *const component; /* The component containing the directory 361 (see update_path in prefix.cc) */ 362 const char cplusplus; /* When this is non-zero, we should only 363@@ -55,17 +56,13 @@ struct default_include 364 }; 365 366 extern const struct default_include cpp_include_defaults[]; 367-extern const char cpp_GCC_INCLUDE_DIR[]; 368-extern const size_t cpp_GCC_INCLUDE_DIR_len; 369+extern char GCC_INCLUDE_DIRVAR[] __attribute__ ((section (".gccrelocprefix"))); 370 371 /* The configure-time prefix, i.e., the value supplied as the argument 372 to --prefix=. */ 373-extern const char cpp_PREFIX[]; 374+extern char PREFIXVAR[] __attribute__ ((section (".gccrelocprefix"))); 375 /* The length of the configure-time prefix. */ 376-extern const size_t cpp_PREFIX_len; 377-/* The configure-time execution prefix. This is typically the lib/gcc 378- subdirectory of cpp_PREFIX. */ 379-extern const char cpp_EXEC_PREFIX[]; 380+extern char EXEC_PREFIXVAR[] __attribute__ ((section (".gccrelocprefix"))); 381 /* The run-time execution prefix. This is typically the lib/gcc 382 subdirectory of the actual installation. */ 383 extern const char *gcc_exec_prefix; 384diff --git a/gcc/gcc.cc b/gcc/gcc.cc 385index 8af0c814c33..605fe3b8c0d 100644 386--- a/gcc/gcc.cc 387+++ b/gcc/gcc.cc 388@@ -255,6 +255,8 @@ FILE *report_times_to_file = NULL; 389 #endif 390 static const char *target_system_root = DEFAULT_TARGET_SYSTEM_ROOT; 391 392+static char target_relocatable_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = SYSTEMLIBS_DIR; 393+ 394 /* Nonzero means pass the updated target_system_root to the compiler. */ 395 396 static int target_system_root_changed; 397@@ -578,6 +580,7 @@ or with constant text in a single argument. 398 %G process LIBGCC_SPEC as a spec. 399 %R Output the concatenation of target_system_root and 400 target_sysroot_suffix. 401+ %r Output the base path target_relocatable_prefix 402 %S process STARTFILE_SPEC as a spec. A capital S is actually used here. 403 %E process ENDFILE_SPEC as a spec. A capital E is actually used here. 404 %C process CPP_SPEC as a spec. 405@@ -1619,10 +1622,10 @@ static const char *gcc_libexec_prefix; 406 gcc_exec_prefix is set because, in that case, we know where the 407 compiler has been installed, and use paths relative to that 408 location instead. */ 409-static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX; 410-static const char *const standard_libexec_prefix = STANDARD_LIBEXEC_PREFIX; 411-static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX; 412-static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX; 413+static char standard_exec_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_EXEC_PREFIX; 414+static char standard_libexec_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_LIBEXEC_PREFIX; 415+static char standard_bindir_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_BINDIR_PREFIX; 416+static char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX; 417 418 /* For native compilers, these are well-known paths containing 419 components that may be provided by the system. For cross 420@@ -1630,9 +1633,9 @@ static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX; 421 static const char *md_exec_prefix = MD_EXEC_PREFIX; 422 static const char *md_startfile_prefix = MD_STARTFILE_PREFIX; 423 static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1; 424-static const char *const standard_startfile_prefix_1 425+static char standard_startfile_prefix_1[4096] __attribute__ ((section (".gccrelocprefix"))) 426 = STANDARD_STARTFILE_PREFIX_1; 427-static const char *const standard_startfile_prefix_2 428+static char standard_startfile_prefix_2[4096] __attribute__ ((section (".gccrelocprefix"))) 429 = STANDARD_STARTFILE_PREFIX_2; 430 431 /* A relative path to be used in finding the location of tools 432@@ -6652,6 +6655,11 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) 433 } 434 break; 435 436+ case 'r': 437+ obstack_grow (&obstack, target_relocatable_prefix, 438+ strlen (target_relocatable_prefix)); 439+ break; 440+ 441 case 'S': 442 value = do_spec_1 (startfile_spec, 0, NULL); 443 if (value != 0) 444diff --git a/gcc/incpath.cc b/gcc/incpath.cc 445index 46c0d543205..d088dae7b04 100644 446--- a/gcc/incpath.cc 447+++ b/gcc/incpath.cc 448@@ -135,7 +135,7 @@ add_standard_paths (const char *sysroot, const char *iprefix, 449 int relocated = cpp_relocated (); 450 size_t len; 451 452- if (iprefix && (len = cpp_GCC_INCLUDE_DIR_len) != 0) 453+ if (iprefix && (len = strlen(GCC_INCLUDE_DIRVAR) - 7) != 0) 454 { 455 /* Look for directories that start with the standard prefix. 456 "Translate" them, i.e. replace /usr/local/lib/gcc... with 457@@ -150,7 +150,7 @@ add_standard_paths (const char *sysroot, const char *iprefix, 458 now. */ 459 if (sysroot && p->add_sysroot) 460 continue; 461- if (!filename_ncmp (p->fname, cpp_GCC_INCLUDE_DIR, len)) 462+ if (!filename_ncmp (p->fname, GCC_INCLUDE_DIRVAR, len)) 463 { 464 char *str = concat (iprefix, p->fname + len, NULL); 465 if (p->multilib == 1 && imultilib) 466@@ -191,7 +191,7 @@ add_standard_paths (const char *sysroot, const char *iprefix, 467 free (sysroot_no_trailing_dir_separator); 468 } 469 else if (!p->add_sysroot && relocated 470- && !filename_ncmp (p->fname, cpp_PREFIX, cpp_PREFIX_len)) 471+ && !filename_ncmp (p->fname, PREFIXVAR, strlen(PREFIXVAR))) 472 { 473 static const char *relocated_prefix; 474 char *ostr; 475@@ -208,12 +208,12 @@ add_standard_paths (const char *sysroot, const char *iprefix, 476 dummy = concat (gcc_exec_prefix, "dummy", NULL); 477 relocated_prefix 478 = make_relative_prefix (dummy, 479- cpp_EXEC_PREFIX, 480- cpp_PREFIX); 481+ EXEC_PREFIXVAR, 482+ PREFIXVAR); 483 free (dummy); 484 } 485 ostr = concat (relocated_prefix, 486- p->fname + cpp_PREFIX_len, 487+ p->fname + strlen(PREFIXVAR), 488 NULL); 489 str = update_path (ostr, p->component); 490 free (ostr); 491diff --git a/gcc/prefix.cc b/gcc/prefix.cc 492index c2a37bde5ea..33944701ced 100644 493--- a/gcc/prefix.cc 494+++ b/gcc/prefix.cc 495@@ -73,7 +73,9 @@ License along with GCC; see the file COPYING3. If not see 496 #include "prefix.h" 497 #include "common/common-target.h" 498 499-static const char *std_prefix = PREFIX; 500+char PREFIXVAR1[4096] __attribute__ ((section (".gccrelocprefix"))) = PREFIX; 501+ 502+static const char *std_prefix = PREFIXVAR1; 503 504 static const char *get_key_value (char *); 505 static char *translate_name (char *); 506@@ -213,7 +215,7 @@ translate_name (char *name) 507 prefix = getenv (key); 508 509 if (prefix == 0) 510- prefix = PREFIX; 511+ prefix = PREFIXVAR1; 512 513 /* We used to strip trailing DIR_SEPARATORs here, but that can 514 sometimes yield a result with no separator when one was coded 515