0024-handle-sysroot-support-for-nativesdk-gcc.patch 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. From 35c084a051bcd6587ebc73e4acb045cb2bdf7e99 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. Signed-off-by: Khem Raj <raj.khem@gmail.com>
  21. Added PREFIXVAR and EXEC_PREFIXVAR to support runtime relocation. Without
  22. these as part of the gccrelocprefix the system can't do runtime relocation
  23. if the executable is moved. (These paths were missed in the original
  24. implementation.)
  25. Signed-off-by: Mark Hatle <mark.hatle@kernel.crashing.org>
  26. ---
  27. gcc/c-family/c-opts.c | 4 +--
  28. gcc/cppdefault.c | 63 ++++++++++++++++++++++++++-----------------
  29. gcc/cppdefault.h | 13 ++++-----
  30. gcc/gcc.c | 20 +++++++++-----
  31. gcc/incpath.c | 12 ++++-----
  32. gcc/prefix.c | 6 +++--
  33. 6 files changed, 70 insertions(+), 48 deletions(-)
  34. diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
  35. index bd15b9cd902..2bd667e3f58 100644
  36. --- a/gcc/c-family/c-opts.c
  37. +++ b/gcc/c-family/c-opts.c
  38. @@ -1436,8 +1436,8 @@ add_prefixed_path (const char *suffix, incpath_kind chain)
  39. size_t prefix_len, suffix_len;
  40. suffix_len = strlen (suffix);
  41. - prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
  42. - prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
  43. + prefix = iprefix ? iprefix : GCC_INCLUDE_DIRVAR;
  44. + prefix_len = iprefix ? strlen (iprefix) : strlen(GCC_INCLUDE_DIRVAR) - 7;
  45. path = (char *) xmalloc (prefix_len + suffix_len + 1);
  46. memcpy (path, prefix, prefix_len);
  47. diff --git a/gcc/cppdefault.c b/gcc/cppdefault.c
  48. index d54d6ce0076..784a92a0c24 100644
  49. --- a/gcc/cppdefault.c
  50. +++ b/gcc/cppdefault.c
  51. @@ -35,6 +35,30 @@
  52. # undef CROSS_INCLUDE_DIR
  53. #endif
  54. +static char GPLUSPLUS_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = GPLUSPLUS_INCLUDE_DIR;
  55. +char GCC_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = GCC_INCLUDE_DIR;
  56. +static char GPLUSPLUS_TOOL_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = GPLUSPLUS_TOOL_INCLUDE_DIR;
  57. +static char GPLUSPLUS_BACKWARD_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = GPLUSPLUS_BACKWARD_INCLUDE_DIR;
  58. +static char STANDARD_STARTFILE_PREFIX_2VAR[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_STARTFILE_PREFIX_2 GCC_INCLUDE_SUBDIR_TARGET;
  59. +#ifdef LOCAL_INCLUDE_DIR
  60. +static char LOCAL_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = LOCAL_INCLUDE_DIR;
  61. +#endif
  62. +#ifdef PREFIX_INCLUDE_DIR
  63. +static char PREFIX_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = PREFIX_INCLUDE_DIR;
  64. +#endif
  65. +#ifdef FIXED_INCLUDE_DIR
  66. +static char FIXED_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = FIXED_INCLUDE_DIR;
  67. +#endif
  68. +#ifdef CROSS_INCLUDE_DIR
  69. +static char CROSS_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = CROSS_INCLUDE_DIR;
  70. +#endif
  71. +#ifdef TOOL_INCLUDE_DIR
  72. +static char TOOL_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = TOOL_INCLUDE_DIR;
  73. +#endif
  74. +#ifdef NATIVE_SYSTEM_HEADER_DIR
  75. +static char NATIVE_SYSTEM_HEADER_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = NATIVE_SYSTEM_HEADER_DIR;
  76. +#endif
  77. +
  78. const struct default_include cpp_include_defaults[]
  79. #ifdef INCLUDE_DEFAULTS
  80. = INCLUDE_DEFAULTS;
  81. @@ -42,17 +66,17 @@ const struct default_include cpp_include_defaults[]
  82. = {
  83. #ifdef GPLUSPLUS_INCLUDE_DIR
  84. /* Pick up GNU C++ generic include files. */
  85. - { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1,
  86. + { GPLUSPLUS_INCLUDE_DIRVAR, "G++", 1, 1,
  87. GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
  88. #endif
  89. #ifdef GPLUSPLUS_TOOL_INCLUDE_DIR
  90. /* Pick up GNU C++ target-dependent include files. */
  91. - { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1,
  92. + { GPLUSPLUS_TOOL_INCLUDE_DIRVAR, "G++", 1, 1,
  93. GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 },
  94. #endif
  95. #ifdef GPLUSPLUS_BACKWARD_INCLUDE_DIR
  96. /* Pick up GNU C++ backward and deprecated include files. */
  97. - { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1,
  98. + { GPLUSPLUS_BACKWARD_INCLUDE_DIRVAR, "G++", 1, 1,
  99. GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
  100. #endif
  101. #ifdef GPLUSPLUS_LIBCXX_INCLUDE_DIR
  102. @@ -62,23 +86,23 @@ const struct default_include cpp_include_defaults[]
  103. #endif
  104. #ifdef GCC_INCLUDE_DIR
  105. /* This is the dir for gcc's private headers. */
  106. - { GCC_INCLUDE_DIR, "GCC", 0, 0, 0, 0 },
  107. + { GCC_INCLUDE_DIRVAR, "GCC", 0, 0, 0, 0 },
  108. #endif
  109. #ifdef GCC_INCLUDE_SUBDIR_TARGET
  110. /* This is the dir for gcc's private headers under the specified sysroot. */
  111. - { STANDARD_STARTFILE_PREFIX_2 GCC_INCLUDE_SUBDIR_TARGET, "GCC", 0, 0, 1, 0 },
  112. + { STANDARD_STARTFILE_PREFIX_2VAR, "GCC", 0, 0, 1, 0 },
  113. #endif
  114. #ifdef LOCAL_INCLUDE_DIR
  115. /* /usr/local/include comes before the fixincluded header files. */
  116. - { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 },
  117. - { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
  118. + { LOCAL_INCLUDE_DIRVAR, 0, 0, 1, 1, 2 },
  119. + { LOCAL_INCLUDE_DIRVAR, 0, 0, 1, 1, 0 },
  120. #endif
  121. #ifdef PREFIX_INCLUDE_DIR
  122. - { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0 },
  123. + { PREFIX_INCLUDE_DIRVAR, 0, 0, 1, 0, 0 },
  124. #endif
  125. #ifdef FIXED_INCLUDE_DIR
  126. /* This is the dir for fixincludes. */
  127. - { FIXED_INCLUDE_DIR, "GCC", 0, 0, 0,
  128. + { FIXED_INCLUDE_DIRVAR, "GCC", 0, 0, 0,
  129. /* A multilib suffix needs adding if different multilibs use
  130. different headers. */
  131. #ifdef SYSROOT_HEADERS_SUFFIX_SPEC
  132. @@ -90,33 +114,24 @@ const struct default_include cpp_include_defaults[]
  133. #endif
  134. #ifdef CROSS_INCLUDE_DIR
  135. /* One place the target system's headers might be. */
  136. - { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0 },
  137. + { CROSS_INCLUDE_DIRVAR, "GCC", 0, 0, 0, 0 },
  138. #endif
  139. #ifdef TOOL_INCLUDE_DIR
  140. /* Another place the target system's headers might be. */
  141. - { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0 },
  142. + { TOOL_INCLUDE_DIRVAR, "BINUTILS", 0, 1, 0, 0 },
  143. #endif
  144. #ifdef NATIVE_SYSTEM_HEADER_DIR
  145. /* /usr/include comes dead last. */
  146. - { NATIVE_SYSTEM_HEADER_DIR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 2 },
  147. - { NATIVE_SYSTEM_HEADER_DIR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 0 },
  148. + { NATIVE_SYSTEM_HEADER_DIRVAR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 2 },
  149. + { NATIVE_SYSTEM_HEADER_DIRVAR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 0 },
  150. #endif
  151. { 0, 0, 0, 0, 0, 0 }
  152. };
  153. #endif /* no INCLUDE_DEFAULTS */
  154. -#ifdef GCC_INCLUDE_DIR
  155. -const char cpp_GCC_INCLUDE_DIR[] = GCC_INCLUDE_DIR;
  156. -const size_t cpp_GCC_INCLUDE_DIR_len = sizeof GCC_INCLUDE_DIR - 8;
  157. -#else
  158. -const char cpp_GCC_INCLUDE_DIR[] = "";
  159. -const size_t cpp_GCC_INCLUDE_DIR_len = 0;
  160. -#endif
  161. -
  162. /* The configured prefix. */
  163. -const char cpp_PREFIX[] = PREFIX;
  164. -const size_t cpp_PREFIX_len = sizeof PREFIX - 1;
  165. -const char cpp_EXEC_PREFIX[] = STANDARD_EXEC_PREFIX;
  166. +char PREFIXVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = PREFIX;
  167. +char EXEC_PREFIXVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_EXEC_PREFIX;
  168. /* This value is set by cpp_relocated at runtime */
  169. const char *gcc_exec_prefix;
  170. diff --git a/gcc/cppdefault.h b/gcc/cppdefault.h
  171. index fd3c655db1c..20669ac427d 100644
  172. --- a/gcc/cppdefault.h
  173. +++ b/gcc/cppdefault.h
  174. @@ -33,7 +33,8 @@
  175. struct default_include
  176. {
  177. - const char *const fname; /* The name of the directory. */
  178. + const char *fname; /* The name of the directory. */
  179. +
  180. const char *const component; /* The component containing the directory
  181. (see update_path in prefix.c) */
  182. const char cplusplus; /* When this is non-zero, we should only
  183. @@ -55,17 +56,13 @@ struct default_include
  184. };
  185. extern const struct default_include cpp_include_defaults[];
  186. -extern const char cpp_GCC_INCLUDE_DIR[];
  187. -extern const size_t cpp_GCC_INCLUDE_DIR_len;
  188. +extern char GCC_INCLUDE_DIRVAR[] __attribute__ ((section (".gccrelocprefix")));
  189. /* The configure-time prefix, i.e., the value supplied as the argument
  190. to --prefix=. */
  191. -extern const char cpp_PREFIX[];
  192. +extern char PREFIXVAR[] __attribute__ ((section (".gccrelocprefix")));
  193. /* The length of the configure-time prefix. */
  194. -extern const size_t cpp_PREFIX_len;
  195. -/* The configure-time execution prefix. This is typically the lib/gcc
  196. - subdirectory of cpp_PREFIX. */
  197. -extern const char cpp_EXEC_PREFIX[];
  198. +extern char EXEC_PREFIXVAR[] __attribute__ ((section (".gccrelocprefix")));
  199. /* The run-time execution prefix. This is typically the lib/gcc
  200. subdirectory of the actual installation. */
  201. extern const char *gcc_exec_prefix;
  202. diff --git a/gcc/gcc.c b/gcc/gcc.c
  203. index 8737bae5353..aa6fbe43965 100644
  204. --- a/gcc/gcc.c
  205. +++ b/gcc/gcc.c
  206. @@ -252,6 +252,8 @@ FILE *report_times_to_file = NULL;
  207. #endif
  208. static const char *target_system_root = DEFAULT_TARGET_SYSTEM_ROOT;
  209. +static char target_relocatable_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = SYSTEMLIBS_DIR;
  210. +
  211. /* Nonzero means pass the updated target_system_root to the compiler. */
  212. static int target_system_root_changed;
  213. @@ -568,6 +570,7 @@ or with constant text in a single argument.
  214. %G process LIBGCC_SPEC as a spec.
  215. %R Output the concatenation of target_system_root and
  216. target_sysroot_suffix.
  217. + %r Output the base path target_relocatable_prefix
  218. %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
  219. %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
  220. %C process CPP_SPEC as a spec.
  221. @@ -1621,10 +1624,10 @@ static const char *gcc_libexec_prefix;
  222. gcc_exec_prefix is set because, in that case, we know where the
  223. compiler has been installed, and use paths relative to that
  224. location instead. */
  225. -static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX;
  226. -static const char *const standard_libexec_prefix = STANDARD_LIBEXEC_PREFIX;
  227. -static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX;
  228. -static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
  229. +static char standard_exec_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_EXEC_PREFIX;
  230. +static char standard_libexec_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_LIBEXEC_PREFIX;
  231. +static char standard_bindir_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_BINDIR_PREFIX;
  232. +static char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
  233. /* For native compilers, these are well-known paths containing
  234. components that may be provided by the system. For cross
  235. @@ -1632,9 +1635,9 @@ static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
  236. static const char *md_exec_prefix = MD_EXEC_PREFIX;
  237. static const char *md_startfile_prefix = MD_STARTFILE_PREFIX;
  238. static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
  239. -static const char *const standard_startfile_prefix_1
  240. +static char standard_startfile_prefix_1[4096] __attribute__ ((section (".gccrelocprefix")))
  241. = STANDARD_STARTFILE_PREFIX_1;
  242. -static const char *const standard_startfile_prefix_2
  243. +static char standard_startfile_prefix_2[4096] __attribute__ ((section (".gccrelocprefix")))
  244. = STANDARD_STARTFILE_PREFIX_2;
  245. /* A relative path to be used in finding the location of tools
  246. @@ -6564,6 +6567,11 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
  247. }
  248. break;
  249. + case 'r':
  250. + obstack_grow (&obstack, target_relocatable_prefix,
  251. + strlen (target_relocatable_prefix));
  252. + break;
  253. +
  254. case 'S':
  255. value = do_spec_1 (startfile_spec, 0, NULL);
  256. if (value != 0)
  257. diff --git a/gcc/incpath.c b/gcc/incpath.c
  258. index fbfc0ce03b8..a82e543428b 100644
  259. --- a/gcc/incpath.c
  260. +++ b/gcc/incpath.c
  261. @@ -131,7 +131,7 @@ add_standard_paths (const char *sysroot, const char *iprefix,
  262. int relocated = cpp_relocated ();
  263. size_t len;
  264. - if (iprefix && (len = cpp_GCC_INCLUDE_DIR_len) != 0)
  265. + if (iprefix && (len = strlen(GCC_INCLUDE_DIRVAR) - 7) != 0)
  266. {
  267. /* Look for directories that start with the standard prefix.
  268. "Translate" them, i.e. replace /usr/local/lib/gcc... with
  269. @@ -146,7 +146,7 @@ add_standard_paths (const char *sysroot, const char *iprefix,
  270. now. */
  271. if (sysroot && p->add_sysroot)
  272. continue;
  273. - if (!filename_ncmp (p->fname, cpp_GCC_INCLUDE_DIR, len))
  274. + if (!filename_ncmp (p->fname, GCC_INCLUDE_DIRVAR, len))
  275. {
  276. char *str = concat (iprefix, p->fname + len, NULL);
  277. if (p->multilib == 1 && imultilib)
  278. @@ -187,7 +187,7 @@ add_standard_paths (const char *sysroot, const char *iprefix,
  279. free (sysroot_no_trailing_dir_separator);
  280. }
  281. else if (!p->add_sysroot && relocated
  282. - && !filename_ncmp (p->fname, cpp_PREFIX, cpp_PREFIX_len))
  283. + && !filename_ncmp (p->fname, PREFIXVAR, strlen(PREFIXVAR)))
  284. {
  285. static const char *relocated_prefix;
  286. char *ostr;
  287. @@ -204,12 +204,12 @@ add_standard_paths (const char *sysroot, const char *iprefix,
  288. dummy = concat (gcc_exec_prefix, "dummy", NULL);
  289. relocated_prefix
  290. = make_relative_prefix (dummy,
  291. - cpp_EXEC_PREFIX,
  292. - cpp_PREFIX);
  293. + EXEC_PREFIXVAR,
  294. + PREFIXVAR);
  295. free (dummy);
  296. }
  297. ostr = concat (relocated_prefix,
  298. - p->fname + cpp_PREFIX_len,
  299. + p->fname + strlen(PREFIXVAR),
  300. NULL);
  301. str = update_path (ostr, p->component);
  302. free (ostr);
  303. diff --git a/gcc/prefix.c b/gcc/prefix.c
  304. index 747c09de638..f728638dc65 100644
  305. --- a/gcc/prefix.c
  306. +++ b/gcc/prefix.c
  307. @@ -72,7 +72,9 @@ License along with GCC; see the file COPYING3. If not see
  308. #include "prefix.h"
  309. #include "common/common-target.h"
  310. -static const char *std_prefix = PREFIX;
  311. +char PREFIXVAR1[4096] __attribute__ ((section (".gccrelocprefix"))) = PREFIX;
  312. +
  313. +static const char *std_prefix = PREFIXVAR1;
  314. static const char *get_key_value (char *);
  315. static char *translate_name (char *);
  316. @@ -212,7 +214,7 @@ translate_name (char *name)
  317. prefix = getenv (key);
  318. if (prefix == 0)
  319. - prefix = PREFIX;
  320. + prefix = PREFIXVAR1;
  321. /* We used to strip trailing DIR_SEPARATORs here, but that can
  322. sometimes yield a result with no separator when one was coded