Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | Search target sysroot gcc version specific dirs with multilib. |
| 2 | |
| 3 | We install the gcc libraries (such as crtbegin.p) into |
| 4 | <sysroot><libdir>/<target-sys>/5.2.0/ |
| 5 | which is a default search path for GCC (aka multi_suffix in the |
| 6 | code below). <target-sys> is 'machine' in gcc's terminology. We use |
| 7 | these directories so that multiple gcc versions could in theory |
| 8 | co-exist on target. |
| 9 | |
| 10 | We only want to build one gcc-cross-canadian per arch and have this work |
| 11 | for all multilibs. <target-sys> can be handled by mapping the multilib |
| 12 | <target-sys> to the one used by gcc-cross-canadian, e.g. mips64-polkmllib32-linux |
| 13 | is symlinked to by mips64-poky-linux. |
| 14 | |
| 15 | The default gcc search path in the target sysroot for a "lib64" mutlilib is: |
| 16 | |
| 17 | <sysroot>/lib32/mips64-poky-linux/5.2.0/ |
| 18 | <sysroot>/lib32/../lib64/ |
| 19 | <sysroot>/usr/lib32/mips64-poky-linux/5.2.0/ |
| 20 | <sysroot>/usr/lib32/../lib64/ |
| 21 | <sysroot>/lib32/ |
| 22 | <sysroot>/usr/lib32/ |
| 23 | |
| 24 | which means that the lib32 crtbegin.o will be found and the lib64 ones |
| 25 | will not which leads to compiler failures. |
| 26 | |
| 27 | This patch injects a multilib version of that path first so the lib64 |
| 28 | binaries can be found first. With this change the search path becomes: |
| 29 | |
| 30 | <sysroot>/lib32/../lib64/mips64-poky-linux/5.2.0/ |
| 31 | <sysroot>/lib32/mips64-poky-linux/5.2.0/ |
| 32 | <sysroot>/lib32/../lib64/ |
| 33 | <sysroot>/usr/lib32/../lib64/mips64-poky-linux/5.2.0/ |
| 34 | <sysroot>/usr/lib32/mips64-poky-linux/5.2.0/ |
| 35 | <sysroot>/usr/lib32/../lib64/ |
| 36 | <sysroot>/lib32/ |
| 37 | <sysroot>/usr/lib32/ |
| 38 | |
| 39 | Upstream-Status: Pending |
| 40 | RP 2015/7/31 |
| 41 | |
| 42 | Index: gcc-5.2.0/gcc/gcc.c |
| 43 | =================================================================== |
| 44 | --- gcc-5.2.0.orig/gcc/gcc.c |
| 45 | +++ gcc-5.2.0/gcc/gcc.c |
| 46 | @@ -2305,7 +2305,7 @@ for_each_path (const struct path_prefix |
| 47 | if (path == NULL) |
| 48 | { |
| 49 | len = paths->max_len + extra_space + 1; |
| 50 | - len += MAX (MAX (suffix_len, multi_os_dir_len), multiarch_len); |
| 51 | + len += MAX ((suffix_len + multi_os_dir_len), multiarch_len); |
| 52 | path = XNEWVEC (char, len); |
| 53 | } |
| 54 | |
| 55 | @@ -2317,6 +2317,33 @@ for_each_path (const struct path_prefix |
| 56 | /* Look first in MACHINE/VERSION subdirectory. */ |
| 57 | if (!skip_multi_dir) |
| 58 | { |
| 59 | + if (!(pl->os_multilib ? skip_multi_os_dir : skip_multi_dir)) |
| 60 | + { |
| 61 | + const char *this_multi; |
| 62 | + size_t this_multi_len; |
| 63 | + |
| 64 | + if (pl->os_multilib) |
| 65 | + { |
| 66 | + this_multi = multi_os_dir; |
| 67 | + this_multi_len = multi_os_dir_len; |
| 68 | + } |
| 69 | + else |
| 70 | + { |
| 71 | + this_multi = multi_dir; |
| 72 | + this_multi_len = multi_dir_len; |
| 73 | + } |
| 74 | + |
| 75 | + /* Look in multilib MACHINE/VERSION subdirectory first */ |
| 76 | + if (this_multi_len) |
| 77 | + { |
| 78 | + memcpy (path + len, this_multi, this_multi_len + 1); |
| 79 | + memcpy (path + len + this_multi_len, multi_suffix, suffix_len + 1); |
| 80 | + ret = callback (path, callback_info); |
| 81 | + if (ret) |
| 82 | + break; |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | memcpy (path + len, multi_suffix, suffix_len + 1); |
| 87 | ret = callback (path, callback_info); |
| 88 | if (ret) |