From 2fd43d7870803bf0713f76118cc0fcb89407e873 Mon Sep 17 00:00:00 2001 From: claziss Date: Mon, 6 Aug 2018 16:41:32 +0300 Subject: [PATCH] [ARC] Update merging attributes. Some attributes were ignored during merging. Fix that, and add some errors. bfd/ 2017-09-19 Claudiu Zissulescu * elf32-arc.c (arc_elf_merge_attributes): Fix merge attributes. ld/ 2017-09-19 Claudiu Zissulescu * 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/ChangeLog | 4 ++++ bfd/elf32-arc.c | 14 +++++++++++--- ld/ChangeLog | 7 +++++++ 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 ++++++++++++++++ 7 files changed, 71 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 diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 6b5481c2d4..98f0f17016 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,7 @@ +2018-08-06 Claudiu Zissulescu + + * elf32-arc.c (arc_elf_merge_attributes): Fix merge attributes. + 2018-08-06 Claudiu Zissulescu * elf32-arc.c (arc_elf_merge_attributes): Handle diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c index aaa2c3b990..25c9666363 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 @@ -732,7 +731,12 @@ arc_elf_merge_attributes (bfd *ibfd, struct bfd_link_info *info) out_attr[i].i = in_attr[i].i; break; + /* The CPU name is given by the vendor, just choose an + existing one if missing or different. There are no fail + criteria if they different or both missing. */ 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 +768,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 +795,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/ChangeLog b/ld/ChangeLog index 04f19ce082..90efdd7f7c 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,10 @@ +2018-08-06 Claudiu Zissulescu + + * 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. + 2018-08-06 Claudiu Zissulescu * testsuite/ld-arc/attr-merge-0.d: Update test. 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