[PATCH v2 4/9] RISC-V: Support configure options to set ISA versions by default.
Nelson Chu
nelson.chu@sifive.com
Tue May 19 09:07:56 GMT 2020
PING :)
On Wed, May 6, 2020 at 10:55 AM Nelson Chu <nelson.chu@sifive.com> wrote:
>
> Support new configure options --with-arch and --with-isa-spec to set
> ISA versions if we do not set the -march and -misa-spec options.
>
> * --with-arch = <ISA-string>
> The syntax of <ISA-string> is same as -march option. Assembler will
> check this if -march option and ELF arch attributes are not set.
>
> * --with-isa-spec = [2.2|20190608|20191213]
> The syntax is same as -misa-spec option. Assembler will check this if
> -misa-spec option is not set.
>
> The Priority of these options,
>
> * ELF arch attributes > Assembler options > Default configure options
> * For GAS options, -march > -misa-spec
> * For configure options, --with-arch > --with-isa-spec
>
> gas/
> * config/tc-riscv.c (DEFAULT_RISCV_ARCH_WITH_EXT,
> DEFAULT_RISCV_ISA_SPEC): Default configure option settings.
> You can set them by configure options --with-arch and
> --with-isa-spec, respectively.
> (riscv_set_default_isa_spec): New function used to set the
> default ISA spec.
> (md_parse_option): Call riscv_set_default_isa_spec rather than
> call riscv_get_isa_spec_class directly.
> (riscv_after_parse_args): If the -isa-spec is not set, then we
> set the default ISA spec according to DEFAULT_RISCV_ISA_SPEC by
> calling riscv_set_default_isa_spec.
>
> * testsuite/gas/riscv/attribute-01.d: Add -misa-spec=2.2, since
> the --with-isa-spec may be set to different ISA spec.
> * testsuite/gas/riscv/attribute-02.d: Likewise.
> * testsuite/gas/riscv/attribute-03.d: Likewise.
> * testsuite/gas/riscv/attribute-04.d: Likewise.
> * testsuite/gas/riscv/attribute-05.d: Likewise.
> * testsuite/gas/riscv/attribute-06.d: Likewise.
> * testsuite/gas/riscv/attribute-07.d: Likewise.
>
> * configure.ac: Add configure options, --with-arch and
> --with-isa-spec.
> * configure: Regenerated.
> * config.in: Regenerated.
> ---
> gas/config.in | 6 ++++
> gas/config/tc-riscv.c | 58 ++++++++++++++++++++++++++--------
> gas/configure | 39 ++++++++++++++++++++++-
> gas/configure.ac | 25 ++++++++++++++-
> gas/testsuite/gas/riscv/attribute-01.d | 2 +-
> gas/testsuite/gas/riscv/attribute-02.d | 2 +-
> gas/testsuite/gas/riscv/attribute-03.d | 2 +-
> gas/testsuite/gas/riscv/attribute-04.d | 2 +-
> gas/testsuite/gas/riscv/attribute-05.d | 2 +-
> gas/testsuite/gas/riscv/attribute-06.d | 2 +-
> gas/testsuite/gas/riscv/attribute-07.d | 2 +-
> 11 files changed, 119 insertions(+), 23 deletions(-)
>
> diff --git a/gas/config.in b/gas/config.in
> index 8724eb1..e20d3c3 100644
> --- a/gas/config.in
> +++ b/gas/config.in
> @@ -53,9 +53,15 @@
> /* Define to 1 if you want to fix Loongson3 LLSC Errata by default. */
> #undef DEFAULT_MIPS_FIX_LOONGSON3_LLSC
>
> +/* Define default value for RISC-V -march. */
> +#undef DEFAULT_RISCV_ARCH_WITH_EXT
> +
> /* Define to 1 if you want to generate RISC-V arch attribute by default. */
> #undef DEFAULT_RISCV_ATTR
>
> +/* Define default value for RISC-V -misa-spec. */
> +#undef DEFAULT_RISCV_ISA_SPEC
> +
> /* Define to 1 if you want to generate GNU x86 used ISA and feature properties
> by default. */
> #undef DEFAULT_X86_USED_NOTE
> diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
> index 5ef257e..3b6c429 100644
> --- a/gas/config/tc-riscv.c
> +++ b/gas/config/tc-riscv.c
> @@ -63,8 +63,24 @@ struct riscv_cl_insn
> #define DEFAULT_RISCV_ATTR 0
> #endif
>
> +/* Let riscv_after_parse_args set the default value according to xlen. */
> +
> +#ifndef DEFAULT_RISCV_ARCH_WITH_EXT
> +#define DEFAULT_RISCV_ARCH_WITH_EXT NULL
> +#endif
> +
> +/* The default ISA spec is set to 2.2 rather than the lastest version.
> + The reason is that compiler generates the ISA string with fixed 2p0
> + verisons only for the RISCV ELF architecture attributes, but not for
> + the -march option. Therefore, we should update the compiler or linker
> + to resolve this problem. */
> +
> +#ifndef DEFAULT_RISCV_ISA_SPEC
> +#define DEFAULT_RISCV_ISA_SPEC "2.2"
> +#endif
> +
> static const char default_arch[] = DEFAULT_ARCH;
> -static const char *default_arch_with_ext = NULL;
> +static const char *default_arch_with_ext = DEFAULT_RISCV_ARCH_WITH_EXT;
> static enum riscv_isa_spec_class default_isa_spec = ISA_SPEC_CLASS_NONE;
>
> static unsigned xlen = 0; /* width of an x-register */
> @@ -76,6 +92,24 @@ static bfd_boolean rve_abi = FALSE;
>
> static unsigned elf_flags = 0;
>
> +/* Set the default_isa_spec. Return 0 if the input spec string isn't
> + supported. Otherwise, return 1. */
> +
> +static int
> +riscv_set_default_isa_spec (const char *s)
> +{
> + enum riscv_isa_spec_class class;
> + if (!riscv_get_isa_spec_class (s, &class))
> + {
> + as_bad ("Unknown default ISA spec `%s' set by "
> + "-misa-spec or --with-isa-spec", s);
> + return 0;
> + }
> + else
> + default_isa_spec = class;
> + return 1;
> +}
> +
> /* This is the set of options which the .option pseudo-op may modify. */
>
> struct riscv_set_options
> @@ -2522,12 +2556,7 @@ md_parse_option (int c, const char *arg)
> break;
>
> case OPTION_MISA_SPEC:
> - if (!riscv_get_isa_spec_class (arg, &default_isa_spec))
> - {
> - as_bad ("Unknown default ISA spec `%s' set by -misa-spec", arg);
> - return 0;
> - }
> - break;
> + return riscv_set_default_isa_spec (arg);
>
> default:
> return 0;
> @@ -2539,6 +2568,10 @@ md_parse_option (int c, const char *arg)
> void
> riscv_after_parse_args (void)
> {
> + /* The --with-arch is optional for now, so we have to set the xlen
> + according to the default_arch, which is set by the --targte, first.
> + Then, we use the xlen to set the default_arch_with_ext if the
> + -march and --with-arch are not set. */
> if (xlen == 0)
> {
> if (strcmp (default_arch, "riscv32") == 0)
> @@ -2554,15 +2587,12 @@ riscv_after_parse_args (void)
> /* Initialize the hash table for extensions with default version. */
> ext_version_hash = init_ext_version_hash (riscv_ext_version_table);
>
> - /* The default ISA spec is set to 2.2 rather than the lastest version.
> - The reason is that compiler generates the ISA string with fixed 2p0
> - verisons only for the RISCV ELF architecture attributes, but not for
> - the -march option. Therefore, we should update the compiler or linker
> - to resolve this problem. */
> + /* If the -misa-spec isn't set, then we set the default ISA spec according
> + to DEFAULT_RISCV_ISA_SPEC. */
> if (default_isa_spec == ISA_SPEC_CLASS_NONE)
> - default_isa_spec = ISA_SPEC_CLASS_2P2;
> + riscv_set_default_isa_spec (DEFAULT_RISCV_ISA_SPEC);
>
> - /* Set the architecture according to -march. */
> + /* Set the architecture according to -march or or --with-arch. */
> riscv_set_arch (default_arch_with_ext);
>
> /* Add the RVC extension, regardless of -march, to support .option rvc. */
> diff --git a/gas/configure b/gas/configure
> index 1515787..cc21e0a 100755
> --- a/gas/configure
> +++ b/gas/configure
> @@ -13009,7 +13009,7 @@ $as_echo "#define NDS32_DEFAULT_ZOL_EXT 1" >>confdefs.h
> $as_echo "$enable_zol_ext" >&6; }
> ;;
>
> - aarch64 | i386 | riscv | s390 | sparc)
> + aarch64 | i386 | s390 | sparc)
> if test $this_target = $target ; then
>
> cat >>confdefs.h <<_ACEOF
> @@ -13019,6 +13019,43 @@ _ACEOF
> fi
> ;;
>
> + riscv)
> + # --target=riscv[32|64]-*-*. */
> + if test $this_target = $target ; then
> +
> +cat >>confdefs.h <<_ACEOF
> +#define DEFAULT_ARCH "${arch}"
> +_ACEOF
> +
> + fi
> +
> + # --with-arch=<value>. The syntax of <value> is same as Gas option -march.
> + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for default configuration of --with-arch" >&5
> +$as_echo_n "checking for default configuration of --with-arch... " >&6; }
> + if test "x${with_arch}" != x; then
> +
> +cat >>confdefs.h <<_ACEOF
> +#define DEFAULT_RISCV_ARCH_WITH_EXT "$with_arch"
> +_ACEOF
> +
> + fi
> + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_arch" >&5
> +$as_echo "$with_arch" >&6; }
> +
> + # --with-isa-spec=[2.2|20190608|20191213].
> + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for default configuration of --with-isa-spec" >&5
> +$as_echo_n "checking for default configuration of --with-isa-spec... " >&6; }
> + if test "x${with_isa_spec}" != x; then
> +
> +cat >>confdefs.h <<_ACEOF
> +#define DEFAULT_RISCV_ISA_SPEC "$with_isa_spec"
> +_ACEOF
> +
> + fi
> + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_isa_spec" >&5
> +$as_echo "$with_isa_spec" >&6; }
> + ;;
> +
> rl78)
> f=rl78-parse.o
> case " $extra_objects " in
> diff --git a/gas/configure.ac b/gas/configure.ac
> index 6f32e55..8a5f5c5 100644
> --- a/gas/configure.ac
> +++ b/gas/configure.ac
> @@ -569,12 +569,35 @@ changequote([,])dnl
> AC_MSG_RESULT($enable_zol_ext)
> ;;
>
> - aarch64 | i386 | riscv | s390 | sparc)
> + aarch64 | i386 | s390 | sparc)
> if test $this_target = $target ; then
> AC_DEFINE_UNQUOTED(DEFAULT_ARCH, "${arch}", [Default architecture.])
> fi
> ;;
>
> + riscv)
> + # --target=riscv[32|64]-*-*. */
> + if test $this_target = $target ; then
> + AC_DEFINE_UNQUOTED(DEFAULT_ARCH, "${arch}", [Default architecture.])
> + fi
> +
> + # --with-arch=<value>. The syntax of <value> is same as Gas option -march.
> + AC_MSG_CHECKING(for default configuration of --with-arch)
> + if test "x${with_arch}" != x; then
> + AC_DEFINE_UNQUOTED(DEFAULT_RISCV_ARCH_WITH_EXT, "$with_arch",
> + [Define default value for RISC-V -march.])
> + fi
> + AC_MSG_RESULT($with_arch)
> +
> + # --with-isa-spec=[2.2|20190608|20191213].
> + AC_MSG_CHECKING(for default configuration of --with-isa-spec)
> + if test "x${with_isa_spec}" != x; then
> + AC_DEFINE_UNQUOTED(DEFAULT_RISCV_ISA_SPEC, "$with_isa_spec",
> + [Define default value for RISC-V -misa-spec.])
> + fi
> + AC_MSG_RESULT($with_isa_spec)
> + ;;
> +
> rl78)
> f=rl78-parse.o
> case " $extra_objects " in
> diff --git a/gas/testsuite/gas/riscv/attribute-01.d b/gas/testsuite/gas/riscv/attribute-01.d
> index e22773e..2e19e09 100644
> --- a/gas/testsuite/gas/riscv/attribute-01.d
> +++ b/gas/testsuite/gas/riscv/attribute-01.d
> @@ -1,4 +1,4 @@
> -#as: -march=rv32g -march-attr
> +#as: -march=rv32g -march-attr -misa-spec=2.2
> #readelf: -A
> #source: empty.s
> Attribute Section: riscv
> diff --git a/gas/testsuite/gas/riscv/attribute-02.d b/gas/testsuite/gas/riscv/attribute-02.d
> index e1e8ce3..ae0195e 100644
> --- a/gas/testsuite/gas/riscv/attribute-02.d
> +++ b/gas/testsuite/gas/riscv/attribute-02.d
> @@ -1,4 +1,4 @@
> -#as: -march=rv32gxargle -march-attr
> +#as: -march=rv32gxargle -march-attr -misa-spec=2.2
> #readelf: -A
> #source: empty.s
> Attribute Section: riscv
> diff --git a/gas/testsuite/gas/riscv/attribute-03.d b/gas/testsuite/gas/riscv/attribute-03.d
> index fa38bf3..9916ff6 100644
> --- a/gas/testsuite/gas/riscv/attribute-03.d
> +++ b/gas/testsuite/gas/riscv/attribute-03.d
> @@ -1,4 +1,4 @@
> -#as: -march=rv32gxargle_xfoo -march-attr
> +#as: -march=rv32gxargle_xfoo -march-attr -misa-spec=2.2
> #readelf: -A
> #source: empty.s
> Attribute Section: riscv
> diff --git a/gas/testsuite/gas/riscv/attribute-04.d b/gas/testsuite/gas/riscv/attribute-04.d
> index c97bf03..408464d 100644
> --- a/gas/testsuite/gas/riscv/attribute-04.d
> +++ b/gas/testsuite/gas/riscv/attribute-04.d
> @@ -1,4 +1,4 @@
> -#as: -march-attr
> +#as: -march-attr -misa-spec=2.2
> #readelf: -A
> #source: attribute-04.s
> Attribute Section: riscv
> diff --git a/gas/testsuite/gas/riscv/attribute-05.d b/gas/testsuite/gas/riscv/attribute-05.d
> index f9b65f2..ad24834 100644
> --- a/gas/testsuite/gas/riscv/attribute-05.d
> +++ b/gas/testsuite/gas/riscv/attribute-05.d
> @@ -1,4 +1,4 @@
> -#as: -march-attr
> +#as: -march-attr -misa-spec=2.2
> #readelf: -A
> #source: attribute-05.s
> Attribute Section: riscv
> diff --git a/gas/testsuite/gas/riscv/attribute-06.d b/gas/testsuite/gas/riscv/attribute-06.d
> index 1abeb47..a2dd9fb 100644
> --- a/gas/testsuite/gas/riscv/attribute-06.d
> +++ b/gas/testsuite/gas/riscv/attribute-06.d
> @@ -1,4 +1,4 @@
> -#as: -march=rv32g2p0 -march-attr
> +#as: -march=rv32g2p0 -march-attr -misa-spec=2.2
> #readelf: -A
> #source: attribute-06.s
> Attribute Section: riscv
> diff --git a/gas/testsuite/gas/riscv/attribute-07.d b/gas/testsuite/gas/riscv/attribute-07.d
> index dfd7e6b..342a537 100644
> --- a/gas/testsuite/gas/riscv/attribute-07.d
> +++ b/gas/testsuite/gas/riscv/attribute-07.d
> @@ -1,4 +1,4 @@
> -#as: -march=rv64g2p0 -march-attr
> +#as: -march=rv64g2p0 -march-attr -misa-spec=2.2
> #readelf: -A
> #source: attribute-07.s
> Attribute Section: riscv
> --
> 2.7.4
>
More information about the Gdb-patches
mailing list