0016-handle-sysroot-support-for-nativesdk-gcc.patch 20 KB

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