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