[3/5,ARC] Update merging attributes.

Message ID 20180724142641.2678-3-claziss@gmail.com
State New
Headers show
Series
  • [1/5,ARC] Update handling AUX-registers.
Related show

Commit Message

Claudiu Zissulescu July 24, 2018, 2:26 p.m.
From: claziss <claziss@synopsys.com>


Some attributes were ignored during merging. Fix that, and add some
errors. Tests provided.

Ok to apply?
Claudiu

bfd/
2017-09-19  Claudiu Zissulescu <claziss@synopsys.com>

	* elf32-arc.c (arc_elf_merge_attributes): Fix merge attributes.

ld/
2017-09-19  Claudiu Zissulescu <claziss@synopsys.com>

	* testsuite/ld-arc/attr-merge-6.d: New file.
	* testsuite/ld-arc/attr-merge-6a.s: Likewise.
	* testsuite/ld-arc/attr-merge-6b.s: Likewise.
	* testsuite/ld-arc/attr-merge-6bis.d: Likewise.
---
 bfd/elf32-arc.c                       | 11 ++++++++---
 ld/testsuite/ld-arc/attr-merge-6.d    | 16 ++++++++++++++++
 ld/testsuite/ld-arc/attr-merge-6a.s   |  9 +++++++++
 ld/testsuite/ld-arc/attr-merge-6b.s   |  8 ++++++++
 ld/testsuite/ld-arc/attr-merge-6bis.d | 16 ++++++++++++++++
 5 files changed, 57 insertions(+), 3 deletions(-)
 create mode 100644 ld/testsuite/ld-arc/attr-merge-6.d
 create mode 100644 ld/testsuite/ld-arc/attr-merge-6a.s
 create mode 100644 ld/testsuite/ld-arc/attr-merge-6b.s
 create mode 100644 ld/testsuite/ld-arc/attr-merge-6bis.d

-- 
2.17.1

Comments

Nick Clifton July 31, 2018, 4:05 p.m. | #1
Hi Claudiu,

> bfd/

> 2017-09-19  Claudiu Zissulescu <claziss@synopsys.com>

> 

> 	* elf32-arc.c (arc_elf_merge_attributes): Fix merge attributes.

> 

> ld/

> 2017-09-19  Claudiu Zissulescu <claziss@synopsys.com>

> 

> 	* testsuite/ld-arc/attr-merge-6.d: New file.

> 	* testsuite/ld-arc/attr-merge-6a.s: Likewise.

> 	* testsuite/ld-arc/attr-merge-6b.s: Likewise.

> 	* testsuite/ld-arc/attr-merge-6bis.d: Likewise.



>  	case Tag_ARC_CPU_name:

> +	  if (!out_attr[i].s && in_attr[i].s)

> +	    out_attr[i].s = _bfd_elf_attr_strdup (obfd, in_attr[i].s);

>  	  break;


What should happen if out_attr[i].s and in_attr[i].s are both defined, and different ?

Cheers
  Nick
Claudiu Zissulescu Aug. 2, 2018, 1:02 p.m. | #2
Hi Nick,

The name can be arbitrary. This attribute is used by various customers to pretty print their specific CPU. What really counts is the CPU_base, and CPU_variation.

When the CPU_name conflicts, then we should choose one of them.

Please let me know if you have extra questions,
Claudiu

> -----Original Message-----

> From: Nick Clifton [mailto:nickc@redhat.com]

> Sent: Tuesday, July 31, 2018 6:05 PM

> To: Claudiu Zissulescu <claziss@gmail.com>; binutils@sourceware.org

> Cc: Francois.Bedard@synopsys.com; Claudiu Zissulescu

> <claziss@synopsys.com>

> Subject: Re: [PATCH 3/5] [ARC] Update merging attributes.

> 

> Hi Claudiu,

> 

> > bfd/

> > 2017-09-19  Claudiu Zissulescu <claziss@synopsys.com>

> >

> > 	* elf32-arc.c (arc_elf_merge_attributes): Fix merge attributes.

> >

> > ld/

> > 2017-09-19  Claudiu Zissulescu <claziss@synopsys.com>

> >

> > 	* testsuite/ld-arc/attr-merge-6.d: New file.

> > 	* testsuite/ld-arc/attr-merge-6a.s: Likewise.

> > 	* testsuite/ld-arc/attr-merge-6b.s: Likewise.

> > 	* testsuite/ld-arc/attr-merge-6bis.d: Likewise.

> 

> 

> >  	case Tag_ARC_CPU_name:

> > +	  if (!out_attr[i].s && in_attr[i].s)

> > +	    out_attr[i].s = _bfd_elf_attr_strdup (obfd, in_attr[i].s);

> >  	  break;

> 

> What should happen if out_attr[i].s and in_attr[i].s are both defined, and

> different ?

> 

> Cheers

>   Nick
Nick Clifton Aug. 2, 2018, 3:39 p.m. | #3
Hi Claudiu,

> The name can be arbitrary. This attribute is used by various customers to pretty print their specific CPU. What really counts is the CPU_base, and CPU_variation.

> 

> When the CPU_name conflicts, then we should choose one of them.


OK - in which case the patch is approved, but please could you
add a comment in explaining to the reader why it does not matter
if the name attributes conflict.

Cheers
  Nick
Nick Clifton Aug. 2, 2018, 3:42 p.m. | #4
Hi Claudiu,

  With regards to your becoming a maintainer for the ARC port,
  I would be happy for this to happen.  So if you are interested
  please add your name to the binutils/MAINTAINERS list and then
  let fly with the ARC patches! :-)

Cheers
  Nick
Claudiu Zissulescu Aug. 2, 2018, 5:01 p.m. | #5
Hi Nick

Thank you for the trust,
Claudiu

> -----Original Message-----

> From: Nick Clifton [mailto:nickc@redhat.com]

> Sent: Thursday, August 02, 2018 5:43 PM

> To: Claudiu Zissulescu <claziss@synopsys.com>; Claudiu Zissulescu

> <claziss@gmail.com>; binutils@sourceware.org

> Cc: Francois.Bedard@synopsys.com

> Subject: Re: [PATCH 3/5] [ARC] Update merging attributes.

> 

> Hi Claudiu,

> 

>   With regards to your becoming a maintainer for the ARC port,

>   I would be happy for this to happen.  So if you are interested

>   please add your name to the binutils/MAINTAINERS list and then

>   let fly with the ARC patches! :-)

> 

> Cheers

>   Nick

Patch

diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
index aaa2c3b990..25a1faaaaf 100644
--- a/bfd/elf32-arc.c
+++ b/bfd/elf32-arc.c
@@ -578,7 +578,6 @@  arc_elf_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
   bfd_boolean result = TRUE;
   const char *sec_name = get_elf_backend_data (ibfd)->obj_attrs_section;
   char *tagname = NULL;
-  int offset = 0;
 
   /* Skip the linker stubs file.  This preserves previous behavior
      of accepting unknown attributes in the first input file - but
@@ -733,6 +732,8 @@  arc_elf_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
 	  break;
 
 	case Tag_ARC_CPU_name:
+	  if (!out_attr[i].s && in_attr[i].s)
+	    out_attr[i].s = _bfd_elf_attr_strdup (obfd, in_attr[i].s);
 	  break;
 
 	case Tag_ARC_ABI_rf16:
@@ -764,7 +765,9 @@  arc_elf_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
 
 	    BFD_ASSERT (in_attr[i].i < 3);
 	    BFD_ASSERT (out_attr[i].i < 3);
-	    if (out_attr[i].i != 0 && in_attr[i].i != 0
+	    if (out_attr[i].i == 0)
+	      out_attr[i].i = in_attr[i].i;
+	    else if (out_attr[i].i != 0 && in_attr[i].i != 0
 		&& out_attr[i].i != in_attr[i].i)
 	      {
 		_bfd_error_handler
@@ -789,7 +792,9 @@  arc_elf_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
 	  if (!tagname)
 	    tagname = "ABI exceptions";
 
-	  if (out_attr[i].i != 0 && in_attr[i].i != 0
+	  if (out_attr[i].i == 0)
+	    out_attr[i].i = in_attr[i].i;
+	  else if (out_attr[i].i != 0 && in_attr[i].i != 0
 	      && out_attr[i].i != in_attr[i].i)
 	    {
 	      _bfd_error_handler
diff --git a/ld/testsuite/ld-arc/attr-merge-6.d b/ld/testsuite/ld-arc/attr-merge-6.d
new file mode 100644
index 0000000000..c90a5033bb
--- /dev/null
+++ b/ld/testsuite/ld-arc/attr-merge-6.d
@@ -0,0 +1,16 @@ 
+# source: attr-merge-6a.s
+# source: attr-merge-6b.s
+# as:
+# ld: -r
+# readelf: -A
+
+Attribute Section: ARC
+File Attributes
+  Tag_ARC_PCS_config: Bare metal/newlib
+  Tag_ARC_CPU_base: ARCEM
+  Tag_ARC_CPU_variation: Core2
+  Tag_ARC_CPU_name: "arcem"
+  Tag_ARC_ABI_osver: v4
+  Tag_ARC_ABI_sda: MWDT
+  Tag_ARC_ISA_config: "CD"
+  Tag_ARC_ATR_version: 1
diff --git a/ld/testsuite/ld-arc/attr-merge-6a.s b/ld/testsuite/ld-arc/attr-merge-6a.s
new file mode 100644
index 0000000000..cbd4fb4c9d
--- /dev/null
+++ b/ld/testsuite/ld-arc/attr-merge-6a.s
@@ -0,0 +1,9 @@ 
+# MWDT like attribute structure
+	.cpu EM
+	.arc_attribute	Tag_ARC_ATR_version, 1
+	.arc_attribute  Tag_ARC_ABI_sda, 1
+	.arc_attribute  Tag_ARC_ABI_enumsize, 0
+	.arc_attribute  Tag_ARC_CPU_variation, 1
+	.arc_attribute  Tag_ARC_ISA_mpy_option, 0
+	.arc_attribute	Tag_ARC_ABI_osver, 0
+	.arc_attribute	Tag_ARC_CPU_name, ""
diff --git a/ld/testsuite/ld-arc/attr-merge-6b.s b/ld/testsuite/ld-arc/attr-merge-6b.s
new file mode 100644
index 0000000000..1e1392c01e
--- /dev/null
+++ b/ld/testsuite/ld-arc/attr-merge-6b.s
@@ -0,0 +1,8 @@ 
+#GCC like attribute structure
+	.cpu EM
+	.arc_attribute  Tag_ARC_PCS_config, 2
+	.arc_attribute  Tag_ARC_CPU_variation, 2
+	.arc_attribute	Tag_ARC_CPU_name, "arcem"
+	.arc_attribute  Tag_ARC_ABI_osver, 4
+	.arc_attribute  Tag_ARC_ISA_config, "CD"
+	.arc_attribute  Tag_ARC_ATR_version, 1
diff --git a/ld/testsuite/ld-arc/attr-merge-6bis.d b/ld/testsuite/ld-arc/attr-merge-6bis.d
new file mode 100644
index 0000000000..795ac0d512
--- /dev/null
+++ b/ld/testsuite/ld-arc/attr-merge-6bis.d
@@ -0,0 +1,16 @@ 
+# source: attr-merge-6b.s
+# source: attr-merge-6a.s
+# as:
+# ld: -r
+# readelf: -A
+
+Attribute Section: ARC
+File Attributes
+  Tag_ARC_PCS_config: Bare metal/newlib
+  Tag_ARC_CPU_base: ARCEM
+  Tag_ARC_CPU_variation: Core2
+  Tag_ARC_CPU_name: "arcem"
+  Tag_ARC_ABI_osver: v4
+  Tag_ARC_ABI_sda: MWDT
+  Tag_ARC_ISA_config: "CD"
+  Tag_ARC_ATR_version: 1