public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Add configure option: --with-multilib-config to flexible config multi-lib settings.
@ 2020-10-16  9:08 Kito Cheng
  0 siblings, 0 replies; only message in thread
From: Kito Cheng @ 2020-10-16  9:08 UTC (permalink / raw)
  To: gcc-patches, kito.cheng, jimw, palmer, andrew; +Cc: Kito Cheng

 - Able to configure complex multi-lib rule in configure time, without modify
   any in-tree source.

 - I was consider to implmenet this into `--with-multilib-list` option,
   but I am not sure who will using that with riscv*-*-elf*, so I decide to
   using another option name for that.

 - --with-multilib-config will pass arguments to multilib-generator, and
   then using the generated multi-lib config file to build the toolchain.

  e.g. Build riscv gcc, default arch/abi is rv64gc/lp64, and build multilib
       for rv32imafd/ilp32 and rv32i/ilp32; rv32ic/ilp32 will reuse
       rv32i/ilp32.
    $ <GCC-SRC>/configure \
       --target=riscv64-elf \
       --with-arch=rv64gc --with-abi=lp64 \
       --with-multilib-config=rv32i-ilp32--c;rv32imafd-ilp32--

gcc/ChangeLog:

	* config.gcc (riscv*-*-*): Handle --with-multilib-config.
	* configure: Regen.
	* configure.ac: Add --with-multilib-config.
	* config/riscv/multilib-generator: Exit when parsing arch string error.
	* config/riscv/t-withmultilib-config: New.
	* doc/install.texi: Document --with-multilib-config.
---
 gcc/config.gcc                         | 32 ++++++++++++++++++++++----
 gcc/config/riscv/multilib-generator    |  9 +++++++-
 gcc/config/riscv/t-withmultilib-config |  2 ++
 gcc/configure                          | 15 ++++++++++--
 gcc/configure.ac                       |  5 ++++
 gcc/doc/install.texi                   | 30 ++++++++++++++++++++++++
 6 files changed, 85 insertions(+), 8 deletions(-)
 create mode 100644 gcc/config/riscv/t-withmultilib-config

diff --git a/gcc/config.gcc b/gcc/config.gcc
index b79c544c9fa4..bfd34db0a4f3 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2436,11 +2436,13 @@ riscv*-*-elf* | riscv*-*-rtems*)
 	  tmake_file="${tmake_file} riscv/t-rtems"
 	  ;;
 	*)
-	  case "x${enable_multilib}" in
-	  xno) ;;
-	  xyes) tmake_file="${tmake_file} riscv/t-elf-multilib" ;;
-	  *) echo "Unknown value for enable_multilib"; exit 1
-	  esac
+	  if test "x${with_multilib_config}" == xdefault; then
+		  case "x${enable_multilib}" in
+		  xno) ;;
+		  xyes) tmake_file="${tmake_file} riscv/t-elf-multilib" ;;
+		  *) echo "Unknown value for enable_multilib"; exit 1
+		  esac
+	  fi
 	esac
 	tmake_file="${tmake_file} riscv/t-riscv"
 	gnu_ld=yes
@@ -4575,6 +4577,26 @@ case "${target}" in
 			exit 1
 			;;
 		esac
+		# Handle --with-multilib-config.
+		case "${target}" in
+		riscv*-*-elf*)
+			if test "x${with_multilib_config}" != xdefault; then
+				if ${srcdir}/config/riscv/multilib-generator \
+					`echo ${with_multilib_config} | sed 's/;/ /g'`\
+					> t-multilib-config;
+				then
+					tmake_file="${tmake_file} riscv/t-withmultilib-config"
+				else
+					echo "invalid option for --with-multilib-config" 1>&2
+					exit 1
+				fi
+			fi
+			;;
+		*)
+			echo "--with-multilib-config= is not supported for ${target}, only supported for riscv*-*-elf*" 1>&2
+			exit 1
+			;;
+		esac
 
 		# Handle --with-multilib-list.
 		if test "x${with_multilib_list}" != xdefault; then
diff --git a/gcc/config/riscv/multilib-generator b/gcc/config/riscv/multilib-generator
index f444d0ebc746..9bc3a8fbb1f4 100755
--- a/gcc/config/riscv/multilib-generator
+++ b/gcc/config/riscv/multilib-generator
@@ -103,7 +103,14 @@ def arch_canonicalize(arch):
   return new_arch
 
 for cfg in sys.argv[1:]:
-  (arch, abi, extra, ext) = cfg.split('-')
+  try:
+    (arch, abi, extra, ext) = cfg.split('-')
+  except:
+    print ("Invalid configure string %s, <arch>-<abi>-<extra>-<extensions>\n"
+           "<extra> and <extensions> can be empty, "
+           "e.g. rv32imafd-ilp32--" % cfg)
+    sys.exit(1)
+
   arch = arch_canonicalize (arch)
   arches[arch] = 1
   abis[abi] = 1
diff --git a/gcc/config/riscv/t-withmultilib-config b/gcc/config/riscv/t-withmultilib-config
new file mode 100644
index 000000000000..1a35cc0bc655
--- /dev/null
+++ b/gcc/config/riscv/t-withmultilib-config
@@ -0,0 +1,2 @@
+# t-multilib-config will generated in build folder by configure script.
+include t-multilib-config
diff --git a/gcc/configure b/gcc/configure
index abff47d30eb9..eab70192bf46 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -972,6 +972,7 @@ with_documentation_root_url
 with_changes_root_url
 enable_languages
 with_multilib_list
+with_multilib_config
 with_zstd
 with_zstd_include
 with_zstd_lib
@@ -1811,6 +1812,7 @@ Optional Packages:
   --with-changes-root-url=URL
                           Root for GCC changes URLs
   --with-multilib-list    select multilibs (AArch64, SH and x86-64 only)
+  --with-multilib-config  Multi-libs configuration string (RISC-V only)
   --with-zstd=PATH        specify prefix directory for installed zstd library.
                           Equivalent to --with-zstd-include=PATH/include plus
                           --with-zstd-lib=PATH/lib
@@ -8002,6 +8004,15 @@ else
 fi
 
 
+
+# Check whether --with-multilib-config was given.
+if test "${with_multilib_config+set}" = set; then :
+  withval=$with_multilib_config; :
+else
+  with_multilib_config=default
+fi
+
+
 # -------------------------
 # Checks for other programs
 # -------------------------
@@ -19018,7 +19029,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19021 "configure"
+#line 19032 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19124,7 +19135,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 19127 "configure"
+#line 19138 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 26a5d8e36196..8f8231c29e36 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -1102,6 +1102,11 @@ AC_ARG_WITH(multilib-list,
 :,
 with_multilib_list=default)
 
+AC_ARG_WITH(multilib-config,
+[AS_HELP_STRING([--with-multilib-config], [Multi-libs configuration string (RISC-V only)])],
+:,
+with_multilib_config=default)
+
 # -------------------------
 # Checks for other programs
 # -------------------------
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 5330bf3bb293..2972dcad7c26 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1252,6 +1252,36 @@ If @option{--with-multilib-list} is not given, then only 32-bit and
 64-bit run-time libraries will be enabled.
 @end table
 
+@item --with-multilib-config=@var{config}
+Specify what multilibs to build.  @var{config} is a semicolon separated list of
+values, possibly consisting of a single value.  Currently only implemented
+for riscv*-*-elf*.  The accepted values and meaning is given below.
+
+Every config is construct with four components: architecture string, ABI,
+reuse rule with architecture string and reuse rule with sub-extension.
+
+Example 1: Add multi-lib suppport for rv32i with ilp32.
+@smallexample
+rv32i-ilp32--
+@end smallexample
+
+Example 2: Add multi-lib suppport for rv32i with ilp32 and rv32imafd with ilp32.
+@smallexample
+rv32i-ilp32--;rv32imafd-ilp32--
+@end smallexample
+
+Example 3: Add multi-lib suppport for rv32i with ilp32; rv32im with ilp32 and
+rv32ic with ilp32 will reuse this multi-lib set.
+@smallexample
+rv32i-ilp32-rv32im-c
+@end smallexample
+
+Example 4: Add multi-lib suppport for rv64ima with lp64; rv64imaf with lp64,
+rv64imac with lp64 and rv64imafc with lp64 will reuse this multi-lib set.
+@smallexample
+rv64ima-lp64--f,c,fc
+@end smallexample
+
 @item --with-endian=@var{endians}
 Specify what endians to use.
 Currently only implemented for sh*-*-*.
-- 
2.28.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-10-16  9:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-16  9:08 [PATCH] RISC-V: Add configure option: --with-multilib-config to flexible config multi-lib settings Kito Cheng

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).