Andrew Geissler | ea144b0 | 2023-01-27 16:03:57 -0600 | [diff] [blame] | 1 | From 33a1f07a4417247dc24819d4e583ca09f56d5a7b Mon Sep 17 00:00:00 2001 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Mon, 7 Dec 2015 23:41:45 +0000 |
| 4 | Subject: [PATCH] Search target sysroot gcc version specific dirs with |
| 5 | multilib. |
| 6 | |
| 7 | We install the gcc libraries (such as crtbegin.p) into |
| 8 | <sysroot><libdir>/<target-sys>/5.2.0/ |
| 9 | which is a default search path for GCC (aka multi_suffix in the |
| 10 | code below). <target-sys> is 'machine' in gcc's terminology. We use |
| 11 | these directories so that multiple gcc versions could in theory |
| 12 | co-exist on target. |
| 13 | |
| 14 | We only want to build one gcc-cross-canadian per arch and have this work |
| 15 | for all multilibs. <target-sys> can be handled by mapping the multilib |
| 16 | <target-sys> to the one used by gcc-cross-canadian, e.g. |
| 17 | mips64-polkmllib32-linux |
| 18 | is symlinked to by mips64-poky-linux. |
| 19 | |
| 20 | The default gcc search path in the target sysroot for a "lib64" mutlilib |
| 21 | is: |
| 22 | |
| 23 | <sysroot>/lib32/mips64-poky-linux/5.2.0/ |
| 24 | <sysroot>/lib32/../lib64/ |
| 25 | <sysroot>/usr/lib32/mips64-poky-linux/5.2.0/ |
| 26 | <sysroot>/usr/lib32/../lib64/ |
| 27 | <sysroot>/lib32/ |
| 28 | <sysroot>/usr/lib32/ |
| 29 | |
| 30 | which means that the lib32 crtbegin.o will be found and the lib64 ones |
| 31 | will not which leads to compiler failures. |
| 32 | |
| 33 | This patch injects a multilib version of that path first so the lib64 |
| 34 | binaries can be found first. With this change the search path becomes: |
| 35 | |
| 36 | <sysroot>/lib32/../lib64/mips64-poky-linux/5.2.0/ |
| 37 | <sysroot>/lib32/mips64-poky-linux/5.2.0/ |
| 38 | <sysroot>/lib32/../lib64/ |
| 39 | <sysroot>/usr/lib32/../lib64/mips64-poky-linux/5.2.0/ |
| 40 | <sysroot>/usr/lib32/mips64-poky-linux/5.2.0/ |
| 41 | <sysroot>/usr/lib32/../lib64/ |
| 42 | <sysroot>/lib32/ |
| 43 | <sysroot>/usr/lib32/ |
| 44 | |
| 45 | Upstream-Status: Pending |
| 46 | RP 2015/7/31 |
| 47 | |
| 48 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 49 | --- |
Andrew Geissler | ea144b0 | 2023-01-27 16:03:57 -0600 | [diff] [blame] | 50 | gcc/gcc.cc | 29 ++++++++++++++++++++++++++++- |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 51 | 1 file changed, 28 insertions(+), 1 deletion(-) |
| 52 | |
Andrew Geissler | ea144b0 | 2023-01-27 16:03:57 -0600 | [diff] [blame] | 53 | diff --git a/gcc/gcc.cc b/gcc/gcc.cc |
| 54 | index 5569a39a14a..4598f6cd7c9 100644 |
| 55 | --- a/gcc/gcc.cc |
| 56 | +++ b/gcc/gcc.cc |
| 57 | @@ -2817,7 +2817,7 @@ for_each_path (const struct path_prefix *paths, |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 58 | if (path == NULL) |
| 59 | { |
| 60 | len = paths->max_len + extra_space + 1; |
| 61 | - len += MAX (MAX (suffix_len, multi_os_dir_len), multiarch_len); |
| 62 | + len += MAX ((suffix_len + multi_os_dir_len), multiarch_len); |
| 63 | path = XNEWVEC (char, len); |
| 64 | } |
| 65 | |
Andrew Geissler | ea144b0 | 2023-01-27 16:03:57 -0600 | [diff] [blame] | 66 | @@ -2829,6 +2829,33 @@ for_each_path (const struct path_prefix *paths, |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 67 | /* Look first in MACHINE/VERSION subdirectory. */ |
| 68 | if (!skip_multi_dir) |
| 69 | { |
| 70 | + if (!(pl->os_multilib ? skip_multi_os_dir : skip_multi_dir)) |
| 71 | + { |
| 72 | + const char *this_multi; |
| 73 | + size_t this_multi_len; |
| 74 | + |
| 75 | + if (pl->os_multilib) |
| 76 | + { |
| 77 | + this_multi = multi_os_dir; |
| 78 | + this_multi_len = multi_os_dir_len; |
| 79 | + } |
| 80 | + else |
| 81 | + { |
| 82 | + this_multi = multi_dir; |
| 83 | + this_multi_len = multi_dir_len; |
| 84 | + } |
| 85 | + |
| 86 | + /* Look in multilib MACHINE/VERSION subdirectory first */ |
| 87 | + if (this_multi_len) |
| 88 | + { |
| 89 | + memcpy (path + len, this_multi, this_multi_len + 1); |
| 90 | + memcpy (path + len + this_multi_len, multi_suffix, suffix_len + 1); |
| 91 | + ret = callback (path, callback_info); |
| 92 | + if (ret) |
| 93 | + break; |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | memcpy (path + len, multi_suffix, suffix_len + 1); |
| 98 | ret = callback (path, callback_info); |
| 99 | if (ret) |