From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by sourceware.org (Postfix) with ESMTPS id DBA1F3894E79 for ; Wed, 6 May 2020 02:55:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DBA1F3894E79 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nelson.chu@sifive.com Received: by mail-pf1-x441.google.com with SMTP id r14so289945pfg.2 for ; Tue, 05 May 2020 19:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yIdqXMCT4pxmchbLCfXGQtWVDEGuvIuywxV/xgOTC5c=; b=KurxpzbfUIO7h7zOmBtimqne3hh47zwfEjHX9JeqyDRG7HLkpaQe4uyjBy6uN0Qaha Y4z80oeJUjN6OVm4cDKic8rvyduFbHxaT3zcnAM1Tf8YGxafquvNwMlYCSnync67tepB w+G3FT7vBjwXWwfPH/b/QmfgtFheTEb5tnX81/M/KSM7np3rbwKHq/2/D46ESy+RZqIZ RxW/hKzSn3rd/1mzRgG9t0eosFERVi6NTNnvh0gvePhCJwAmOiE0f2h3oMx2ZH/+yGGM 8i8jt0CQJJzfMVwELseR3QyJfNP30cdv0qesrLNHpCjnFY7m7fpWw32VdpWT0oMN8UB0 1INg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yIdqXMCT4pxmchbLCfXGQtWVDEGuvIuywxV/xgOTC5c=; b=eaKsON37s/SfShmKr2hRQrDVh8AaW4P+NCSVyJu66w983sY+zBIYw8VTf7tHj1b67L oHUxIYLPbH9D+m6y1NoDrmAHojjJnhFFFpBcXQq4nqKlZCBqSVQbz7O+MUWoc0KT3oGx 1owHama0pcPC6Nz9ZikZD/vVl8MkQ6UO8UKj4nCnowhfmAcO2Z/Ss7iEuLzGm+0wHYLI zEXiX0lM0ILmiDBwbZwyDuktoeqNwwauPs5LNVrbDwkdzhDSO1i4CN8BfNGBxeSTO+g9 iSfguNLu5tj3yyksrtH/Y2cjrTQv0FsL50XV8xgHsD08HQ3K4LLlvhB2KDti3GvGb/4o wEzw== X-Gm-Message-State: AGi0PuatdU3We/x5JTPF8FJ5bkfbL45QnVMwfRrlVr0g6cAgEa8GNhau iwGZ7LGxs399RvvIA6lNp5JVXw== X-Google-Smtp-Source: APiQypIlTCXFILEaeSJlvu8pS72S7k9p6dKlOZZmG4zQOBvALKDpWqCf4py+gxK3mmazWmXGE5o01g== X-Received: by 2002:a65:64d7:: with SMTP id t23mr5319395pgv.275.1588733755773; Tue, 05 May 2020 19:55:55 -0700 (PDT) Received: from gamma05.internal.sifive.com ([64.62.193.194]) by smtp.gmail.com with ESMTPSA id 141sm222996pfz.171.2020.05.05.19.55.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 May 2020 19:55:55 -0700 (PDT) From: Nelson Chu To: binutils@sourceware.org, gdb-patches@sourceware.org Cc: palmer@dabbelt.com, kito.cheng@sifive.com, jimw@sifive.com, andrew@sifive.com, andrew.burgess@embecosm.com, asb@lowrisc.org, maxim.blinov@embecosm.com, nelson.chu@sifive.com Subject: [PATCH v2 4/9] RISC-V: Support configure options to set ISA versions by default. Date: Tue, 5 May 2020 19:55:42 -0700 Message-Id: <1588733747-18787-5-git-send-email-nelson.chu@sifive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1588733747-18787-1-git-send-email-nelson.chu@sifive.com> References: <1588733747-18787-1-git-send-email-nelson.chu@sifive.com> X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 May 2020 02:56:02 -0000 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 = The syntax of 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=. The syntax of 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=. The syntax of 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