blob: fd81ae24495e68c05d4056ce4d1b27116a20919d [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001Being able to build a nativesdk gcc is useful, particularly in cases
2where the host compiler may be of an incompatible version (or a 32
3bit compiler is needed).
4
5Sadly, building nativesdk-gcc is not straight forward. We install
6nativesdk-gcc into a relocatable location and this means that its
7library locations can change. "Normal" sysroot support doesn't help
8in this case since the values of paths like "libdir" change, not just
9base root directory of the system.
10
11In order to handle this we do two things:
12
13a) Add %r into spec file markup which can be used for injected paths
14 such as SYSTEMLIBS_DIR (see gcc_multilib_setup()).
15b) Add other paths which need relocation into a .gccrelocprefix section
16 which the relocation code will notice and adjust automatically.
17
18
19Upstream-Status: Inappropriate
20RP 2015/7/28
21
22diff --git a/gcc/cppdefault.c b/gcc/cppdefault.c
23--- a/gcc/cppdefault.c
24+++ b/gcc/cppdefault.c
25@@ -35,6 +35,30 @@
26 # undef CROSS_INCLUDE_DIR
27 #endif
28
29+static char GPLUSPLUS_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = GPLUSPLUS_INCLUDE_DIR;
30+static char GCC_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = GCC_INCLUDE_DIR;
31+static char GPLUSPLUS_TOOL_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = GPLUSPLUS_TOOL_INCLUDE_DIR;
32+static char GPLUSPLUS_BACKWARD_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = GPLUSPLUS_BACKWARD_INCLUDE_DIR;
33+static char STANDARD_STARTFILE_PREFIX_2VAR[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_STARTFILE_PREFIX_2 GCC_INCLUDE_SUBDIR_TARGET;
34+#ifdef LOCAL_INCLUDE_DIR
35+static char LOCAL_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = LOCAL_INCLUDE_DIR;
36+#endif
37+#ifdef PREFIX_INCLUDE_DIR
38+static char PREFIX_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = PREFIX_INCLUDE_DIR;
39+#endif
40+#ifdef FIXED_INCLUDE_DIR
41+static char FIXED_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = FIXED_INCLUDE_DIR;
42+#endif
43+#ifdef CROSS_INCLUDE_DIR
44+static char CROSS_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = CROSS_INCLUDE_DIR;
45+#endif
46+#ifdef TOOL_INCLUDE_DIR
47+static char TOOL_INCLUDE_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = TOOL_INCLUDE_DIR;
48+#endif
49+#ifdef NATIVE_SYSTEM_HEADER_DIR
50+static char NATIVE_SYSTEM_HEADER_DIRVAR[4096] __attribute__ ((section (".gccrelocprefix"))) = NATIVE_SYSTEM_HEADER_DIR;
51+#endif
52+
53 const struct default_include cpp_include_defaults[]
54 #ifdef INCLUDE_DEFAULTS
55 = INCLUDE_DEFAULTS;
56@@ -42,38 +66,38 @@ const struct default_include cpp_include_defaults[]
57 = {
58 #ifdef GPLUSPLUS_INCLUDE_DIR
59 /* Pick up GNU C++ generic include files. */
60- { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1,
61+ { GPLUSPLUS_INCLUDE_DIRVAR, "G++", 1, 1,
62 GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
63 #endif
64 #ifdef GPLUSPLUS_TOOL_INCLUDE_DIR
65 /* Pick up GNU C++ target-dependent include files. */
66- { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1,
67+ { GPLUSPLUS_TOOL_INCLUDE_DIRVAR, "G++", 1, 1,
68 GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 },
69 #endif
70 #ifdef GPLUSPLUS_BACKWARD_INCLUDE_DIR
71 /* Pick up GNU C++ backward and deprecated include files. */
72- { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1,
73+ { GPLUSPLUS_BACKWARD_INCLUDE_DIRVAR, "G++", 1, 1,
74 GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
75 #endif
76 #ifdef GCC_INCLUDE_DIR
77 /* This is the dir for gcc's private headers. */
78- { GCC_INCLUDE_DIR, "GCC", 0, 0, 0, 0 },
79+ { GCC_INCLUDE_DIRVAR, "GCC", 0, 0, 0, 0 },
80 #endif
81 #ifdef GCC_INCLUDE_SUBDIR_TARGET
82 /* This is the dir for gcc's private headers under the specified sysroot. */
83- { STANDARD_STARTFILE_PREFIX_2 GCC_INCLUDE_SUBDIR_TARGET, "GCC", 0, 0, 1, 0 },
84+ { STANDARD_STARTFILE_PREFIX_2VAR, "GCC", 0, 0, 1, 0 },
85 #endif
86 #ifdef LOCAL_INCLUDE_DIR
87 /* /usr/local/include comes before the fixincluded header files. */
88- { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 },
89- { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
90+ { LOCAL_INCLUDE_DIRVAR, 0, 0, 1, 1, 2 },
91+ { LOCAL_INCLUDE_DIRVAR, 0, 0, 1, 1, 0 },
92 #endif
93 #ifdef PREFIX_INCLUDE_DIR
94- { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0 },
95+ { PREFIX_INCLUDE_DIRVAR, 0, 0, 1, 0, 0 },
96 #endif
97 #ifdef FIXED_INCLUDE_DIR
98 /* This is the dir for fixincludes. */
99- { FIXED_INCLUDE_DIR, "GCC", 0, 0, 0,
100+ { FIXED_INCLUDE_DIRVAR, "GCC", 0, 0, 0,
101 /* A multilib suffix needs adding if different multilibs use
102 different headers. */
103 #ifdef SYSROOT_HEADERS_SUFFIX_SPEC
104@@ -85,16 +109,16 @@ const struct default_include cpp_include_defaults[]
105 #endif
106 #ifdef CROSS_INCLUDE_DIR
107 /* One place the target system's headers might be. */
108- { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0 },
109+ { CROSS_INCLUDE_DIRVAR, "GCC", 0, 0, 0, 0 },
110 #endif
111 #ifdef TOOL_INCLUDE_DIR
112 /* Another place the target system's headers might be. */
113- { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0 },
114+ { TOOL_INCLUDE_DIRVAR, "BINUTILS", 0, 1, 0, 0 },
115 #endif
116 #ifdef NATIVE_SYSTEM_HEADER_DIR
117 /* /usr/include comes dead last. */
118- { NATIVE_SYSTEM_HEADER_DIR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 2 },
119- { NATIVE_SYSTEM_HEADER_DIR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 0 },
120+ { NATIVE_SYSTEM_HEADER_DIRVAR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 2 },
121+ { NATIVE_SYSTEM_HEADER_DIRVAR, NATIVE_SYSTEM_HEADER_COMPONENT, 0, 0, 1, 0 },
122 #endif
123 { 0, 0, 0, 0, 0, 0 }
124 };
125diff --git a/gcc/cppdefault.h b/gcc/cppdefault.h
126--- a/gcc/cppdefault.h
127+++ b/gcc/cppdefault.h
128@@ -33,7 +33,8 @@
129
130 struct default_include
131 {
132- const char *const fname; /* The name of the directory. */
133+ const char *fname; /* The name of the directory. */
134+
135 const char *const component; /* The component containing the directory
136 (see update_path in prefix.c) */
137 const char cplusplus; /* Only look here if we're compiling C++. */
138diff --git a/gcc/gcc.c b/gcc/gcc.c
139--- a/gcc/gcc.c
140+++ b/gcc/gcc.c
141@@ -120,6 +120,8 @@ static const char *target_system_root = TARGET_SYSTEM_ROOT;
142 #else
143 static const char *target_system_root = 0;
144 #endif
145+
146+static char target_relocatable_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = SYSTEMLIBS_DIR;
147
148 /* Nonzero means pass the updated target_system_root to the compiler. */
149
150@@ -390,6 +392,7 @@ or with constant text in a single argument.
151 %G process LIBGCC_SPEC as a spec.
152 %R Output the concatenation of target_system_root and
153 target_sysroot_suffix.
154+ %r Output the base path target_relocatable_prefix
155 %S process STARTFILE_SPEC as a spec. A capital S is actually used here.
156 %E process ENDFILE_SPEC as a spec. A capital E is actually used here.
157 %C process CPP_SPEC as a spec.
158@@ -1286,10 +1289,10 @@ static const char *gcc_libexec_prefix;
159 gcc_exec_prefix is set because, in that case, we know where the
160 compiler has been installed, and use paths relative to that
161 location instead. */
162-static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX;
163-static const char *const standard_libexec_prefix = STANDARD_LIBEXEC_PREFIX;
164-static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX;
165-static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
166+static char standard_exec_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_EXEC_PREFIX;
167+static char standard_libexec_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_LIBEXEC_PREFIX;
168+static char standard_bindir_prefix[4096] __attribute__ ((section (".gccrelocprefix"))) = STANDARD_BINDIR_PREFIX;
169+static char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
170
171 /* For native compilers, these are well-known paths containing
172 components that may be provided by the system. For cross
173@@ -1297,9 +1300,9 @@ static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX;
174 static const char *md_exec_prefix = MD_EXEC_PREFIX;
175 static const char *md_startfile_prefix = MD_STARTFILE_PREFIX;
176 static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1;
177-static const char *const standard_startfile_prefix_1
178+static char standard_startfile_prefix_1[4096] __attribute__ ((section (".gccrelocprefix")))
179 = STANDARD_STARTFILE_PREFIX_1;
180-static const char *const standard_startfile_prefix_2
181+static char standard_startfile_prefix_2[4096] __attribute__ ((section (".gccrelocprefix")))
182 = STANDARD_STARTFILE_PREFIX_2;
183
184 /* A relative path to be used in finding the location of tools
185@@ -5550,6 +5553,11 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
186 }
187 break;
188
189+ case 'r':
190+ obstack_grow (&obstack, target_relocatable_prefix,
191+ strlen (target_relocatable_prefix));
192+ break;
193+
194 case 'S':
195 value = do_spec_1 (startfile_spec, 0, NULL);
196 if (value != 0)