[PATCH 2/2] RISC-V: Support ELF attribute

2019-02-12 Thread Kito Cheng
From: Kito Cheng 

This patch added a configure time option, 
--with-riscv-attribute=[yes|no|default],
run time option, -mriscv-attribute to control the output of ELF attribute.

This feature is only enabled by default for ELF/Bare mental target
configuration.

Kito Cheng 
Monk Chiang  

ChangeLog:
gcc:
* common/config/riscv/riscv-common.c: Include sstream.
(riscv_subset_list::to_string): New.
(riscv_arch_str): Likewise.
* config.gcc (riscv*-*-*): Hanlde --with-riscv-attribute=
* config.in: Regen
* config/riscv/riscv-protos.h (riscv_arch_str): New.
* config/riscv/riscv.c (INCLUDE_STRING): Defined.
(riscv_emit_attribute): New.
(riscv_file_start): Emit attribute if needed.
(riscv_option_override): Init riscv_emit_attribute_p.
* config/riscv/riscv.opt (mriscv-attribute): New option.
* configure.ac (riscv*-*-*): Check binutils is supporting ELF
attribute.
* doc/install.texi: Document --with-riscv-attribute.
* doc/invoke.texi: Document -mriscv-attribute.

gcc/testsuite:

* gcc.target/riscv/attribute-1.c: New.
* gcc.target/riscv/attribute-2.c: Likewise.
* gcc.target/riscv/attribute-3.c: Likewise.
* gcc.target/riscv/attribute-4.c: Likewise.
* gcc.target/riscv/attribute-5.c: Likewise.
* gcc.target/riscv/attribute-6.c: Likewise.
* gcc.target/riscv/attribute-7.c: Likewise.
* gcc.target/riscv/attribute-8.c: Likewise.
* gcc.target/riscv/attribute-9.c: Likewise.
---
 gcc/common/config/riscv/riscv-common.c   | 38 
 gcc/config.gcc   | 26 ++-
 gcc/config.in|  6 +
 gcc/config/riscv/riscv-protos.h  |  3 +++
 gcc/config/riscv/riscv.c | 25 ++
 gcc/config/riscv/riscv.opt   |  4 +++
 gcc/configure.ac |  7 +
 gcc/doc/install.texi |  8 ++
 gcc/doc/invoke.texi  |  7 -
 gcc/testsuite/gcc.target/riscv/attribute-1.c |  7 +
 gcc/testsuite/gcc.target/riscv/attribute-2.c |  7 +
 gcc/testsuite/gcc.target/riscv/attribute-3.c |  7 +
 gcc/testsuite/gcc.target/riscv/attribute-4.c |  7 +
 gcc/testsuite/gcc.target/riscv/attribute-5.c |  7 +
 gcc/testsuite/gcc.target/riscv/attribute-6.c |  7 +
 gcc/testsuite/gcc.target/riscv/attribute-7.c |  7 +
 gcc/testsuite/gcc.target/riscv/attribute-8.c |  7 +
 gcc/testsuite/gcc.target/riscv/attribute-9.c |  7 +
 18 files changed, 185 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-1.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-2.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-3.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-4.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-5.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-6.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-7.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-8.c
 create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-9.c

diff --git a/gcc/common/config/riscv/riscv-common.c 
b/gcc/common/config/riscv/riscv-common.c
index e412acb..3f938ba 100644
--- a/gcc/common/config/riscv/riscv-common.c
+++ b/gcc/common/config/riscv/riscv-common.c
@@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public 
License
 along with GCC; see the file COPYING3.  If not see
 .  */
 
+#include 
+
 #define INCLUDE_STRING
 #include "config.h"
 #include "system.h"
@@ -78,6 +80,8 @@ public:
  int major_version = RISCV_DONT_CARE_VERSION,
  int minor_version = RISCV_DONT_CARE_VERSION) const;
 
+  std::string to_string() const;
+
   unsigned xlen() const {return m_xlen;};
 
   static riscv_subset_list *parse (const char *, location_t);
@@ -134,6 +138,32 @@ void riscv_subset_list::add (const char *subset,
   m_tail = s;
 }
 
+/* Convert subset info to string with explicit version info.  */
+
+std::string riscv_subset_list::to_string() const
+{
+  std::ostringstream oss;
+  oss << "rv" << m_xlen;
+
+  bool first = true;
+  riscv_subset_t *subset = m_head;
+
+  while (subset != NULL)
+{
+  if (!first)
+   oss << '_';
+  first = false;
+
+  oss << subset->name
+ << subset->major_version
+ << 'p'
+ << subset->minor_version;
+  subset = subset->next;
+}
+
+  return oss.str();
+}
+
 /* Find subset in list without version checking, return NULL if not found.  */
 
 riscv_subset_t *riscv_subset_list::lookup (const char *subset,
@@ -492,6 +522,14 @@ fail:
   return NULL;
 }
 
+/* Return the current arch string.  */
+
+std::string riscv_arch_str ()
+{
+  gcc_assert (current_subset_list);
+  return current_su

Re: [PATCH 2/2] RISC-V: Support ELF attribute

2019-02-20 Thread Jim Wilson
This also looks mostly OK to me with only some minor issues that need
to be fixed.

On Tue, Feb 12, 2019 at 11:17 PM Kito Cheng  wrote:
>
> From: Kito Cheng 
>
> This patch added a configure time option, 
> --with-riscv-attribute=[yes|no|default],
> run time option, -mriscv-attribute to control the output of ELF attribute.
>
> This feature is only enabled by default for ELF/Bare mental target
> configuration.
>
> Kito Cheng 
> Monk Chiang  
>
> ChangeLog:
> gcc:
> * common/config/riscv/riscv-common.c: Include sstream.
> (riscv_subset_list::to_string): New.
> (riscv_arch_str): Likewise.
> * config.gcc (riscv*-*-*): Hanlde --with-riscv-attribute=

Hanlde -> Handle

> * config.in: Regen
> * config/riscv/riscv-protos.h (riscv_arch_str): New.
> * config/riscv/riscv.c (INCLUDE_STRING): Defined.
> (riscv_emit_attribute): New.
> (riscv_file_start): Emit attribute if needed.
> (riscv_option_override): Init riscv_emit_attribute_p.
> * config/riscv/riscv.opt (mriscv-attribute): New option.
> * configure.ac (riscv*-*-*): Check binutils is supporting ELF
> attribute.

Should be a line that says configure was regenerated.  The actual
patch wasn't included but tends not to be very useful if other people
modify configure meanwhile, but we still need the changelog entry.

> * doc/install.texi: Document --with-riscv-attribute.
> * doc/invoke.texi: Document -mriscv-attribute.
>
> gcc/testsuite:
>
> * gcc.target/riscv/attribute-1.c: New.
> * gcc.target/riscv/attribute-2.c: Likewise.
> * gcc.target/riscv/attribute-3.c: Likewise.
> * gcc.target/riscv/attribute-4.c: Likewise.
> * gcc.target/riscv/attribute-5.c: Likewise.
> * gcc.target/riscv/attribute-6.c: Likewise.
> * gcc.target/riscv/attribute-7.c: Likewise.
> * gcc.target/riscv/attribute-8.c: Likewise.
> * gcc.target/riscv/attribute-9.c: Likewise.
> ---
>  gcc/common/config/riscv/riscv-common.c   | 38 
> 
>  gcc/config.gcc   | 26 ++-
>  gcc/config.in|  6 +
>  gcc/config/riscv/riscv-protos.h  |  3 +++
>  gcc/config/riscv/riscv.c | 25 ++
>  gcc/config/riscv/riscv.opt   |  4 +++
>  gcc/configure.ac |  7 +
>  gcc/doc/install.texi |  8 ++
>  gcc/doc/invoke.texi  |  7 -
>  gcc/testsuite/gcc.target/riscv/attribute-1.c |  7 +
>  gcc/testsuite/gcc.target/riscv/attribute-2.c |  7 +
>  gcc/testsuite/gcc.target/riscv/attribute-3.c |  7 +
>  gcc/testsuite/gcc.target/riscv/attribute-4.c |  7 +
>  gcc/testsuite/gcc.target/riscv/attribute-5.c |  7 +
>  gcc/testsuite/gcc.target/riscv/attribute-6.c |  7 +
>  gcc/testsuite/gcc.target/riscv/attribute-7.c |  7 +
>  gcc/testsuite/gcc.target/riscv/attribute-8.c |  7 +
>  gcc/testsuite/gcc.target/riscv/attribute-9.c |  7 +
>  18 files changed, 185 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-1.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-2.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-3.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-4.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-5.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-6.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-7.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-8.c
>  create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-9.c
>
> diff --git a/gcc/common/config/riscv/riscv-common.c 
> b/gcc/common/config/riscv/riscv-common.c
> index e412acb..3f938ba 100644
> --- a/gcc/common/config/riscv/riscv-common.c
> +++ b/gcc/common/config/riscv/riscv-common.c
> @@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public 
> License
>  along with GCC; see the file COPYING3.  If not see
>  .  */
>
> +#include 
> +
>  #define INCLUDE_STRING
>  #include "config.h"
>  #include "system.h"
> @@ -78,6 +80,8 @@ public:
>   int major_version = RISCV_DONT_CARE_VERSION,
>   int minor_version = RISCV_DONT_CARE_VERSION) const;
>
> +  std::string to_string() const;
> +
>unsigned xlen() const {return m_xlen;};
>
>static riscv_subset_list *parse (const char *, location_t);
> @@ -134,6 +138,32 @@ void riscv_subset_list::add (const char *subset,
>m_tail = s;
>  }
>
> +/* Convert subset info to string with explicit version info.  */
> +
> +std::string riscv_subset_list::to_string() const
> +{
> +  std::ostringstream oss;
> +  oss << "rv" << m_xlen;
> +
> +  bool first = true;
> +  riscv_subset_t *subset = m_head;
> +
> +  while (subset != NULL)
> +