RISC-V: Add configure option: --with-multilib-generator to flexible config multi...
authorKito Cheng <kito.cheng@sifive.com>
Fri, 19 Jun 2020 07:36:23 +0000 (00:36 -0700)
committerKito Cheng <kito.cheng@sifive.com>
Mon, 2 Nov 2020 09:00:51 +0000 (17:00 +0800)
 - 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-generator 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-generator=rv32i-ilp32--c;rv32imafd-ilp32--

V3 Changes:

 - Rename --with-multilib-config to --with-multilib-generator
 - Check --with-multilib-generator and --with-multilib-list can't be used at
   same time.

V2 Changes:

 - Fix --with-multilib-config hanling on non riscv*-*-elf* triple.

gcc/ChangeLog:

* config.gcc (riscv*-*-*): Handle --with-multilib-generator.
* configure: Regen.
* configure.ac: Add --with-multilib-generator.
* config/riscv/multilib-generator: Exit when parsing arch string error.
* config/riscv/t-withmultilib-generator: New.
* doc/install.texi: Document --with-multilib-generator.

gcc/config.gcc
gcc/config/riscv/multilib-generator
gcc/config/riscv/t-withmultilib-generator [new file with mode: 0644]
gcc/configure
gcc/configure.ac
gcc/doc/install.texi

index b169f2fc3aadb2ae46a327f52940b7b8a3e38b33..dc6d68bd4eb464269925d5e0ac8af25c3809f5ea 100644 (file)
@@ -2438,11 +2438,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_generator}" == 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
@@ -4609,6 +4611,30 @@ case "${target}" in
                        exit 1
                        ;;
                esac
+               # Handle --with-multilib-generator.
+               if test "x${with_multilib_generator}" != xdefault; then
+                       if test "x${with_multilib_list}" != xdefault; then
+                               echo "--with-multilib-list= can't used with --with-multilib-generator= at same time" 1>&2
+                               exit 1
+                       fi
+                       case "${target}" in
+                       riscv*-*-elf*)
+                               if ${srcdir}/config/riscv/multilib-generator \
+                                       `echo ${with_multilib_generator} | sed 's/;/ /g'`\
+                                       > t-multilib-config;
+                               then
+                                       tmake_file="${tmake_file} riscv/t-withmultilib-generator"
+                               else
+                                       echo "invalid option for --with-multilib-generator" 1>&2
+                                       exit 1
+                               fi
+                               ;;
+                       *)
+                               echo "--with-multilib-generator= is not supported for ${target}, only supported for riscv*-*-elf*" 1>&2
+                               exit 1
+                               ;;
+                       esac
+               fi
 
                # Handle --with-multilib-list.
                if test "x${with_multilib_list}" != xdefault; then
index 57ee7c3a2eb4cb489ccc85cfec28845a1a5765ae..0d9ebcb321f59f75cb3957e9496c414fee5ea958 100755 (executable)
@@ -194,7 +194,14 @@ def expand_combination(ext):
   return ext
 
 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-generator b/gcc/config/riscv/t-withmultilib-generator
new file mode 100644 (file)
index 0000000..1a35cc0
--- /dev/null
@@ -0,0 +1,2 @@
+# t-multilib-config will generated in build folder by configure script.
+include t-multilib-config
index f96a89e8c37e88a216ab61ec5dbfc160303b62da..9d2fd0dc30bc33136810628e2abc58157f1c6335 100755 (executable)
@@ -972,6 +972,7 @@ with_documentation_root_url
 with_changes_root_url
 enable_languages
 with_multilib_list
+with_multilib_generator
 with_zstd
 with_zstd_include
 with_zstd_lib
@@ -1811,6 +1812,8 @@ 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-generator
+                          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 +8005,15 @@ else
 fi
 
 
+
+# Check whether --with-multilib-generator was given.
+if test "${with_multilib_generator+set}" = set; then :
+  withval=$with_multilib_generator; :
+else
+  with_multilib_generator=default
+fi
+
+
 # -------------------------
 # Checks for other programs
 # -------------------------
@@ -19018,7 +19030,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 19033 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19124,7 +19136,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 19139 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
index 9154a5475dcd47040b245ed5bbf039412f59ffba..73034bb902b9de17735d88aecf566255ab833191 100644 (file)
@@ -1102,6 +1102,11 @@ AC_ARG_WITH(multilib-list,
 :,
 with_multilib_list=default)
 
+AC_ARG_WITH(multilib-generator,
+[AS_HELP_STRING([--with-multilib-generator], [Multi-libs configuration string (RISC-V only)])],
+:,
+with_multilib_generator=default)
+
 # -------------------------
 # Checks for other programs
 # -------------------------
index 5330bf3bb293ce06bf41076f70f21ae9f7197c7f..ed737d181625042593e3bf599e256e7d3303dc51 100644 (file)
@@ -1252,6 +1252,37 @@ 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-generator=@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 meanings are given below.
+
+
+Every config is constructed 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*-*-*.