public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Kito Cheng <kito.cheng@gmail.com>
To: Palmer Dabbelt <palmer@rivosinc.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] RISC-V: Update multilib-generator to handle V
Date: Wed, 19 Apr 2023 11:57:00 +0800	[thread overview]
Message-ID: <CA+yXCZCnW789oDQanuYjHyL=5da84XNdXONOqA4hDUDV4m4Ojg@mail.gmail.com> (raw)
In-Reply-To: <CA+yXCZCECGjgDQ=CKYUpzc0E75DRO6j7g7FHh6RyBLhApmHXDQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3094 bytes --]

Write a primary version for that, did you mind giving it a try?

The basic idea is to select multilib only by ABI, so that we don't
need to bother with endless multilib reuse cases...

On Wed, Apr 19, 2023 at 9:38 AM Kito Cheng <kito.cheng@gmail.com> wrote:
>
> OK, thanks, I know what the problem is, I tried rv64 but didn't try
> rv32, I have another fix in my mind, and will post another fix soon.
>
> On Wed, Apr 19, 2023 at 9:29 AM Palmer Dabbelt <palmer@rivosinc.com> wrote:
> >
> > On Tue, 18 Apr 2023 18:26:18 PDT (-0700), Kito Cheng wrote:
> > > And which -march -mabi you used will got issue?
> > >
> > > On Wed, Apr 19, 2023 at 8:51 AM Palmer Dabbelt <palmer@rivosinc.com> wrote:
> > >>
> > >> On Tue, 18 Apr 2023 17:47:31 PDT (-0700), Kito Cheng wrote:
> > >> > Do you mind shared gcc configure and the option you tried?
> > >>
> > >> Just riscv-gnu-toolchain with "--enbale-multilib --enable-linux".
> > >>
> > >> > On Wed, Apr 19, 2023 at 4:01 AM Palmer Dabbelt <palmer@rivosinc.com> wrote:
> > >> >>
> > >> >> On Tue, 18 Apr 2023 08:44:24 PDT (-0700), gcc-patches@gcc.gnu.org wrote:
> > >> >> >> Yep, if I drop the non-canonicial strings via
> > >> >> >>
> > >> >> >>     diff --git a/gcc/config/riscv/multilib-generator b/gcc/config/riscv/multilib-generator
> > >> >> >>     index 58b7198b243..a63a4d69c18 100755
> > >> >> >>     --- a/gcc/config/riscv/multilib-generator
> > >> >> >>     +++ b/gcc/config/riscv/multilib-generator
> > >> >> >>     @@ -174,7 +174,7 @@ for cmodel in cmodels:
> > >> >> >>          ext_combs = expand_combination(ext)
> > >> >> >>          alts = sum([[x] + [x + y for y in ext_combs] for x in [arch] + extra], [])
> > >> >> >>          alts = filter(lambda x: len(x) != 0, alts)
> > >> >> >>     -    alts = alts + list(map(lambda a : arch_canonicalize(a, args.misa_spec), alts))
> > >> >> >>     +    alts = list(map(lambda a : arch_canonicalize(a, args.misa_spec), alts))
> > >> >> >>
> > >> >> >>          # Drop duplicated entry.
> > >> >> >>          alts = unique(alts)
> > >> >> >>
> > >> >> >> then I can't link `-march=rv32imafdcv`, I need
> > >> >> >> `-march=rv32imacv_zicsr_zve32f_zve32x_zve64x_zvl128b_zvl32b_zvl64b`.  That's
> > >> >> >> kind of a headache for users to type in.
> > >> >> >
> > >> >> > Yes, that's a headache for users, but arch string canonicalization is
> > >> >> > hiddened at the process,
> > >> >> > so the user could still just use rv32imafdcv at compile time and
> > >> >> > multi-lib config.
> > >> >> >
> > >> >> > And the driver and multilib-generator (with arch_canonicalize) script
> > >> >> > will handle those headache in the background.
> > >> >>
> > >> >> Sorry, I'm not exactly sure what you're trying to say.  I just rebuilt
> > >> >> GCC with this patch (and t-linux-multilib regenerated from it), it's not
> > >> >> resolving multlibs for the short names.
> >
> > `-march=rv32imafdcv` is the broken one,
> > `-march=rv32imacv_zicsr_zve32f_zve32x_zve64x_zvl128b_zvl32b_zvl64b`
> > resolves multilibs (there's a bit more above).

[-- Attachment #2: 0001-RISC-V-Handle-multi-lib-path-correclty-for-linux-DRA.patch --]
[-- Type: text/x-patch, Size: 6260 bytes --]

From a92c0cb2ce6fa58939331549bfb9e8110ec86a11 Mon Sep 17 00:00:00 2001
From: Kito Cheng <kito.cheng@sifive.com>
Date: Wed, 19 Apr 2023 11:54:42 +0800
Subject: [PATCH] RISC-V: Handle multi-lib path correclty for linux [DRAFT]

---
 gcc/common/config/riscv/riscv-common.cc | 118 ++++++++++++++++--------
 gcc/config/riscv/linux.h                |  13 ++-
 2 files changed, 90 insertions(+), 41 deletions(-)

diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc
index 2fc0f8bffc1..f40b1b617c2 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -1597,6 +1597,73 @@ riscv_check_conds (
   return match_score + ok_count * 100;
 }
 
+static const char *
+riscv_select_multilib_by_abi (
+  const std::string &riscv_current_arch_str,
+  const std::string &riscv_current_abi_str,
+  const riscv_subset_list *subset_list,
+  const struct switchstr *switches,
+  int n_switches,
+  const std::vector<riscv_multi_lib_info_t> &multilib_infos
+	)
+{
+  for (size_t i = 0; i < multilib_infos.size (); ++i)
+    if (riscv_current_abi_str == multilib_infos[i].abi_str)
+      return xstrdup (multilib_infos[i].path.c_str ());
+
+  return NULL;
+}
+
+
+static const char *
+riscv_select_multilib (
+  const std::string &riscv_current_arch_str,
+  const std::string &riscv_current_abi_str,
+  const riscv_subset_list *subset_list,
+  const struct switchstr *switches,
+  int n_switches,
+  const std::vector<riscv_multi_lib_info_t> &multilib_infos
+	)
+{
+  int match_score = 0;
+  int max_match_score = 0;
+  int best_match_multi_lib = -1;
+  /* Try to decision which set we should used.  */
+  /* We have 3 level decision tree here, ABI, check input arch/ABI must
+     be superset of multi-lib arch, and other rest option checking.  */
+  for (size_t i = 0; i < multilib_infos.size (); ++i)
+    {
+      /* Check ABI is same first.  */
+      if (riscv_current_abi_str != multilib_infos[i].abi_str)
+	continue;
+
+      /* Found a potential compatible multi-lib setting!
+	 Calculate the match score.  */
+      match_score = subset_list->match_score (multilib_infos[i].subset_list);
+
+      /* Checking other cond in the multi-lib setting.  */
+      match_score = riscv_check_conds (switches,
+				       n_switches,
+				       match_score,
+				       multilib_infos[i].conds);
+
+      /* Record highest match score multi-lib setting.  */
+      if (match_score > max_match_score)
+	{
+	  best_match_multi_lib = i;
+	  max_match_score = match_score;
+	}
+    }
+
+  if (best_match_multi_lib == -1)
+    {
+      riscv_no_matched_multi_lib = true;
+      return NULL;
+    }
+  else
+    return xstrdup (multilib_infos[best_match_multi_lib].path.c_str ());
+}
+
 /* Implement TARGET_COMPUTE_MULTILIB.  */
 static const char *
 riscv_compute_multilib (
@@ -1621,6 +1688,12 @@ riscv_compute_multilib (
   std::string option_cond;
   riscv_multi_lib_info_t multilib_info;
 
+  bool check_abi_only = false;
+
+#if TARGET_LINUX == 1
+  check_abi_only = true;
+#endif
+
   /* Already found suitable, multi-lib, just use that.  */
   if (multilib_dir != NULL)
     return multilib_dir;
@@ -1672,7 +1745,11 @@ riscv_compute_multilib (
 	}
 
       this_path_len = p - this_path;
-      multilib_info.path = std::string (this_path, this_path_len);
+      const char *multi_os_dir_pos = (const char*)memchr (this_path, ':', this_path_len);
+      if (multi_os_dir_pos)
+	multilib_info.path = std::string (this_path, multi_os_dir_pos - this_path);
+      else
+	multilib_info.path = std::string (this_path, this_path_len);
 
       option_conds.clear ();
       /* Pasrse option check list into vector<string>.
@@ -1707,43 +1784,10 @@ riscv_compute_multilib (
       p++;
     }
 
-  int match_score = 0;
-  int max_match_score = 0;
-  int best_match_multi_lib = -1;
-  /* Try to decision which set we should used.  */
-  /* We have 3 level decision tree here, ABI, check input arch/ABI must
-     be superset of multi-lib arch, and other rest option checking.  */
-  for (size_t i = 0; i < multilib_infos.size (); ++i)
-    {
-      /* Check ABI is same first.  */
-      if (riscv_current_abi_str != multilib_infos[i].abi_str)
-	continue;
-
-      /* Found a potential compatible multi-lib setting!
-	 Calculate the match score.  */
-      match_score = subset_list->match_score (multilib_infos[i].subset_list);
-
-      /* Checking other cond in the multi-lib setting.  */
-      match_score = riscv_check_conds (switches,
-				       n_switches,
-				       match_score,
-				       multilib_infos[i].conds);
-
-      /* Record highest match score multi-lib setting.  */
-      if (match_score > max_match_score)
-	{
-	  best_match_multi_lib = i;
-	  max_match_score = match_score;
-	}
-    }
-
-  if (best_match_multi_lib == -1)
-    {
-      riscv_no_matched_multi_lib = true;
-      return multilib_dir;
-    }
+  if (check_abi_only)
+    return riscv_select_multilib_by_abi (riscv_current_arch_str, riscv_current_abi_str, subset_list, switches, n_switches, multilib_infos);
   else
-    return xstrdup (multilib_infos[best_match_multi_lib].path.c_str ());
+    return riscv_select_multilib (riscv_current_arch_str, riscv_current_abi_str, subset_list, switches, n_switches, multilib_infos);
 }
 
 #undef TARGET_COMPUTE_MULTILIB
diff --git a/gcc/config/riscv/linux.h b/gcc/config/riscv/linux.h
index b9557a75dc7..46256f78e5d 100644
--- a/gcc/config/riscv/linux.h
+++ b/gcc/config/riscv/linux.h
@@ -72,7 +72,12 @@ along with GCC; see the file COPYING3.  If not see
 #define TARGET_ASM_FILE_END file_end_indicate_exec_stack
 
 #define STARTFILE_PREFIX_SPEC 			\
-   "/lib" XLEN_SPEC "/" ABI_SPEC "/ "		\
-   "/usr/lib" XLEN_SPEC "/" ABI_SPEC "/ "	\
-   "/lib/ "					\
-   "/usr/lib/ "
+  "%{mabi=lp64d: /lib64/lp64d/ /usr/lib64/lp64d/ /lib/ /usr/lib/}" \
+  "%{mabi=lp64f: /lib64/lp64f/ /usr/lib64/lp64f/ /lib/ /usr/lib/}" \
+  "%{mabi=lp64: /lib64/lp64/ /usr/lib64/lp64/ /lib/ /usr/lib/}" \
+  "%{mabi=ilp32d: /lib32/ilp32d /usr/lib32/ilp32d/ /lib/ /usr/lib/}" \
+  "%{mabi=ilp32f: /lib32/ilp32f/ /usr/lib32/ilp32f/ /lib/ /usr/lib/}" \
+  "%{mabi=ilp32: /lib32/ilp32/ /usr/lib32/ilp32/ /lib/ /usr/lib/}"
+
+#define RISCV_USE_CUSTOMISED_MULTI_LIB 1
+#define TARGET_LINUX 1
-- 
2.39.2


      reply	other threads:[~2023-04-19  3:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-13 20:52 Palmer Dabbelt
2023-04-14  1:53 ` Kito Cheng
2023-04-14  7:15 ` Kito Cheng
2023-04-17 15:24   ` Palmer Dabbelt
2023-04-17 17:57     ` Palmer Dabbelt
2023-04-18 15:44       ` Kito Cheng
2023-04-18 20:01         ` Palmer Dabbelt
2023-04-19  0:47           ` Kito Cheng
2023-04-19  0:51             ` Palmer Dabbelt
2023-04-19  1:26               ` Kito Cheng
2023-04-19  1:29                 ` Palmer Dabbelt
2023-04-19  1:38                   ` Kito Cheng
2023-04-19  3:57                     ` Kito Cheng [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CA+yXCZCnW789oDQanuYjHyL=5da84XNdXONOqA4hDUDV4m4Ojg@mail.gmail.com' \
    --to=kito.cheng@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=palmer@rivosinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).