https://gcc.gnu.org/g:e3dcc815e3d72d6e63503e6c72a70576c5108a6a
commit e3dcc815e3d72d6e63503e6c72a70576c5108a6a Author: YunQiang Su <yunqi...@isrc.iscas.ac.cn> Date: Thu Sep 5 15:14:43 2024 +0800 RISC-V: Lookup reversely in riscv_select_multilib_by_abi When use --print-multi-os-dir or -print-multi-directory, gcc outputs different values with full -march option and the base one only. $ ./gcc/xgcc --print-multi-os-dir -mabi=lp64d -march=rv64gc lib64/lp64d $ ./gcc/xgcc --print-multi-os-dir -mabi=lp64d -march=rv64gc_zba . The reason is that in multilib.h, the fallback value of multilib is listed as the 1st one in `multilib_raw[]`. gcc * common/config/riscv/riscv-common.cc(riscv_select_multilib_by_abi): look up reversely as the fallback path is listed as the 1st one. (cherry picked from commit 3162abfb5098934e6ed9d4307a86a84d28823612) Diff: --- gcc/common/config/riscv/riscv-common.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index 62c6e1dab1f..2c1ce7fc7cb 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -2079,7 +2079,7 @@ riscv_select_multilib_by_abi ( const std::string &riscv_current_abi_str, const std::vector<riscv_multi_lib_info_t> &multilib_infos) { - for (size_t i = 0; i < multilib_infos.size (); ++i) + for (ssize_t i = multilib_infos.size (); i >= 0; --i) if (riscv_current_abi_str == multilib_infos[i].abi_str) return xstrdup (multilib_infos[i].path.c_str ());