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