CSKY: Support attribute section.
authorCooper Qu <cooper.qu@linux.alibaba.com>
Wed, 26 Aug 2020 03:21:14 +0000 (11:21 +0800)
committerLifang Xia <lifang_xia@c-sky.com>
Fri, 28 Aug 2020 09:23:24 +0000 (17:23 +0800)
bfd
        * elf32-csky.c (csky_archs): Fix arch names.
        (csky_find_arch_with_name): New.
        (elf32_csky_merge_attributes): New.
        (csky_elf_merge_private_bfd_data): Add process of merge
        attribute section.
        (elf32_csky_obj_attrs_arg_type): New.
        (elf32_csky_obj_attrs_handle_unknown): New.
        (elf_backend_obj_attrs_vendor): Define.
        (elf_backend_obj_attrs_section): Define.
        (elf_backend_obj_attrs_arg_type): Define.
        (elf_backend_obj_attrs_section_type): Define.

binutils/
        * readelf.c (get_csky_section_type_name): New.
        (get_section_type_name): Add handler for CSKY.
        (display_csky_attribute): New.
        (process_arch_specific): Add handler for CSKY.
        * testsuite/binutils-all/strip-3.d: Remove .csky.attributes
        section.

elfcpp/
        * elfcpp.h (enum SHT): New enum SHT_CSKY_ATTRIBUTES.

gas/
        * gas/config/tc-csky.c (md_begin): Set attributes.
        (isa_flag): Change type to unsigned 64 bits.
        (struct csky_cpu_info): Likewise.
        (struct csky_macro_info): Likewise.
        (set_csky_attribute): New.
        * testsuite/gas/csky/802j.d: Ignore .csky.attributes section.
        * testsuite/gas/csky/all.d: Likewise.
        * testsuite/gas/csky/bsr1.d: Likewise.
        * testsuite/gas/csky/csky_vdsp.d: Likewise.
        * testsuite/gas/csky/cskyv2_all.d: Likewise.
        * testsuite/gas/csky/cskyv2_ck803r2.d: Likewise.
        * testsuite/gas/csky/cskyv2_ck860.d: Likewise.
        * testsuite/gas/csky/cskyv2_dsp.d: Likewise.
        * testsuite/gas/csky/cskyv2_elrw.d: Likewise.
        * testsuite/gas/csky/cskyv2_float.d: Likewise.
        * testsuite/gas/csky/enhance_dsp.d: Likewise.
        * testsuite/gas/csky/java.d: Likewise.
        * testsuite/gas/csky/v1_float.d: Likewise.
        * testsuite/gas/csky/v2_float_part1.d: Likewise.
        * testsuite/gas/csky/v2_float_part2.d: Likewise.
        * testsuite/gas/csky/v2_tls_gd.d: Likewise.
        * testsuite/gas/csky/v2_tls_ie.d: Likewise.
        * testsuite/gas/csky/v2_tls_ld.d: Likewise.
        * testsuite/gas/csky/v2_tls_le.d: Likewise.
        * testsuite/gas/elf/elf.exp: Add handler for CSKY.
        * testsuite/gas/elf/section2.e-csky: New.

include/
        * elf/csky.h (SHT_CSKY_ATTRIBUTES): Define.
        (Tag_CSKY_ARCH_NAME): New enum constant.
        (Tag_CSKY_CPU_NAME): Likewise.
        (Tag_CSKY_ISA_FLAGS): Likewise.
        (Tag_CSKY_DSP_VERSION): Likewise.
        (Tag_CSKY_VDSP_VERSION): Likewise.
        (Tag_CSKY_FPU_VERSION): Likewise.
        (Tag_CSKY_FPU_ABI): Likewise.
        (Tag_CSKY_FPU_ROUNDING): Likewise.
        (Tag_CSKY_FPU_DENORMAL): Likewise.
        (Tag_CSKY_FPU_Exception): Likewise.
        (Tag_CSKY_FPU_NUMBER_MODULE): Likewise.
        (Tag_CSKY_FPU_HARDFP): Likewise.
        (Tag_CSKY_MAX): Likewise.
        (VAL_CSKY_DSP_VERSION_EXTENSION): Likewise.
        (VAL_CSKY_DSP_VERSION_2): Likewise.
        (VAL_CSKY_VDSP_VERSION_1): Likewise.
        (VAL_CSKY_VDSP_VERSION_2): Likewise.
        (VAL_CSKY_FPU_ABI_SOFT): Likewise.
        (VAL_CSKY_FPU_ABI_SOFTFP): Likewise.
        (VAL_CSKY_FPU_ABI_HARD): Likewise.
        (VAL_CSKY_FPU_HARDFP_HALF): Likewise.
        (VAL_CSKY_FPU_HARDFP_SINGLE): Likewise.
        (VAL_CSKY_FPU_HARDFP_DOUBLE): Likewise.
        * opcode/csky.h (CSKY_ISA_VDSP_V2): Define.
        CSKYV1_ISA_E1: Change to long constant type.
        CSKYV2_ISA_E1: Likewise.
        CSKYV2_ISA_1E2: Likewise.
        CSKYV2_ISA_2E3: Likewise.
        CSKYV2_ISA_3E7: Likewise.
        CSKYV2_ISA_7E10: Likewise.
        CSKYV2_ISA_3E3R1: Likewise.
        CSKYV2_ISA_3E3R2: Likewise.
        CSKYV2_ISA_10E60: Likewise.
        CSKY_ISA_TRUST: Likewise.
        CSKY_ISA_CACHE: Likewise.
        CSKY_ISA_NVIC: Likewise.
        CSKY_ISA_CP: Likewise.
        CSKY_ISA_MP: Likewise.
        CSKY_ISA_MP_1E2: Likewise.
        CSKY_ISA_JAVA: Likewise.
        CSKY_ISA_MAC: Likewise.
        CSKY_ISA_MAC_DSP: Likewise.
        CSKY_ISA_DSP: Likewise.
        CSKY_ISA_DSP_1E2: Likewise.
        CSKY_ISA_DSP_ENHANCE: Likewise.
        CSKY_ISA_FLOAT_E1: Likewise.
        CSKY_ISA_FLOAT_1E2: Likewise.
        CSKY_ISA_FLOAT_1E3: Likewise.
        CSKY_ISA_FLOAT_3E4: Likewise.
        CSKY_ISA_VDSP: Likewise.

ld/
        * emulparams/cskyelf.sh: Support attribute section.
        * testsuite/ld-csky/tls-le-v1.d: Match .csky.attributes section.
        * ld/testsuite/ld-csky/tls-le.d: Likewise.
        * testsuite/ld-elf/non-contiguous.ld: Ignore .csky.attributes
        section.

opcodes/
        * csky-dis.c (CSKY_DEFAULT_ISA): Define.
        (csky_dis_info): Add member isa.
        (csky_find_inst_info): Skip instructions that do not belong to
        current CPU.
        (csky_get_disassembler): Get infomation from attribute section.
        (print_insn_csky): Set defualt ISA flag.
        * csky.h (CSKY_ISA_VDSP_2): Rename from CSKY_ISA_VDSP_V2.
        * csky-opc.h (struct csky_opcode): Change isa_flag16 and
        isa_flag32'type to unsigned 64 bits.

41 files changed:
bfd/ChangeLog
bfd/elf32-csky.c
binutils/ChangeLog
binutils/readelf.c
binutils/testsuite/binutils-all/strip-3.d
elfcpp/ChangeLog
elfcpp/elfcpp.h
gas/ChangeLog
gas/config/tc-csky.c
gas/testsuite/gas/csky/802j.d
gas/testsuite/gas/csky/all.d
gas/testsuite/gas/csky/bsr1.d
gas/testsuite/gas/csky/csky_vdsp.d
gas/testsuite/gas/csky/cskyv2_all.d
gas/testsuite/gas/csky/cskyv2_ck803r2.d
gas/testsuite/gas/csky/cskyv2_ck860.d
gas/testsuite/gas/csky/cskyv2_dsp.d
gas/testsuite/gas/csky/cskyv2_elrw.d
gas/testsuite/gas/csky/cskyv2_float.d
gas/testsuite/gas/csky/enhance_dsp.d
gas/testsuite/gas/csky/java.d
gas/testsuite/gas/csky/v1_float.d
gas/testsuite/gas/csky/v2_float_part1.d
gas/testsuite/gas/csky/v2_float_part2.d
gas/testsuite/gas/csky/v2_tls_gd.d
gas/testsuite/gas/csky/v2_tls_ie.d
gas/testsuite/gas/csky/v2_tls_ld.d
gas/testsuite/gas/csky/v2_tls_le.d
gas/testsuite/gas/elf/elf.exp
gas/testsuite/gas/elf/section2.e-csky [new file with mode: 0644]
include/ChangeLog
include/elf/csky.h
include/opcode/csky.h
ld/ChangeLog
ld/emulparams/cskyelf.sh
ld/testsuite/ld-csky/tls-le-v1.d
ld/testsuite/ld-csky/tls-le.d
ld/testsuite/ld-elf/non-contiguous.ld
opcodes/ChangeLog
opcodes/csky-dis.c
opcodes/csky-opc.h

index 51bfbda55d06d48a1ad361bfd923d1bff4076fcb..6fa6ee0f316b9f83b09bd3c12184fd18377b0e40 100644 (file)
@@ -1,3 +1,17 @@
+2020-08-28  Cooper Qu  <cooper.qu@linux.alibaba.com>
+
+       * elf32-csky.c (csky_archs): Fix arch names.
+       (csky_find_arch_with_name): New.
+       (elf32_csky_merge_attributes): New.
+       (csky_elf_merge_private_bfd_data): Add process of merge
+       attribute section.
+       (elf32_csky_obj_attrs_arg_type): New.
+       (elf32_csky_obj_attrs_handle_unknown): New.
+       (elf_backend_obj_attrs_vendor): Define.
+       (elf_backend_obj_attrs_section): Define.
+       (elf_backend_obj_attrs_arg_type): Define.
+       (elf_backend_obj_attrs_section_type): Define.
+
 2020-08-28  Nick Clifton  <nickc@redhat.com>
 
        PR19011
index 7806ec7417ad1ec06b304581ed2e53ffaf86470c..80155cd556eb239973a5c6f8344e2b14b0394c96 100644 (file)
@@ -56,14 +56,15 @@ typedef struct csky_arch_for_merge
 static struct csky_arch_for_merge csky_archs[] =
 {
   /* 510 and 610 merge to 610 without warning.  */
-  { "510",  CSKY_ARCH_510,  CSKY_V1,  0, 0},
-  { "610",  CSKY_ARCH_610,  CSKY_V1,  1, 0},
+  { "ck510",  CSKY_ARCH_510,  CSKY_V1,  0, 0},
+  { "ck610",  CSKY_ARCH_610,  CSKY_V1,  1, 0},
   /* 801, 802, 803, 807, 810 merge to largest one.  */
-  { "801",  CSKY_ARCH_801,  CSKY_V2,  0, 1},
-  { "802",  CSKY_ARCH_802,  CSKY_V2,  1, 1},
-  { "803",  CSKY_ARCH_803,  CSKY_V2,  2, 1},
-  { "807",  CSKY_ARCH_807,  CSKY_V2,  3, 1},
-  { "810",  CSKY_ARCH_810,  CSKY_V2,  4, 1},
+  { "ck801",  CSKY_ARCH_801,  CSKY_V2,  0, 1},
+  { "ck802",  CSKY_ARCH_802,  CSKY_V2,  1, 1},
+  { "ck803",  CSKY_ARCH_803,  CSKY_V2,  2, 1},
+  { "ck807",  CSKY_ARCH_807,  CSKY_V2,  3, 1},
+  { "ck810",  CSKY_ARCH_810,  CSKY_V2,  4, 1},
+  { "ck860",  CSKY_ARCH_860,  CSKY_V2,  5, 1},
   { NULL, 0, 0, 0, 0}
 };
 
@@ -2802,6 +2803,199 @@ csky_find_arch_with_eflag (const unsigned long arch_eflag)
   return csky_arch;
 }
 
+static csky_arch_for_merge *
+csky_find_arch_with_name (const char *name)
+{
+  csky_arch_for_merge *csky_arch = NULL;
+  const char *msg;
+
+  if (name == NULL)
+    return NULL;
+
+  for (csky_arch = csky_archs; csky_arch->name != NULL; csky_arch++)
+    {
+      if (strncmp (csky_arch->name, name, strlen (csky_arch->name)) == 0)
+       break;
+    }
+  if (csky_arch == NULL)
+    {
+      msg = _("warning: unrecognised arch name '%#x'");
+      (*_bfd_error_handler) (msg, name);
+      bfd_set_error (bfd_error_wrong_format);
+    }
+  return csky_arch;
+}
+
+static bfd_boolean
+elf32_csky_merge_attributes (bfd *ibfd, struct bfd_link_info *info)
+{
+  bfd *obfd = info->output_bfd;
+  obj_attribute *in_attr;
+  obj_attribute *out_attr;
+  obj_attribute tattr;
+  csky_arch_for_merge *old_arch = NULL;
+  csky_arch_for_merge *new_arch = NULL;
+  int i;
+  bfd_boolean result = TRUE;
+  const char *msg = NULL;
+
+  const char *sec_name = get_elf_backend_data (ibfd)->obj_attrs_section;
+
+  /* Skip the linker stubs file.  This preserves previous behavior
+     of accepting unknown attributes in the first input file - but
+     is that a bug?  */
+  if (ibfd->flags & BFD_LINKER_CREATED)
+    return TRUE;
+
+  /* Skip any input that hasn't attribute section.
+     This enables to link object files without attribute section with
+     any others.  */
+  if (bfd_get_section_by_name (ibfd, sec_name) == NULL)
+    {
+      return TRUE;
+    }
+
+  if (!elf_known_obj_attributes_proc (obfd)[0].i)
+    {
+      /* This is the first object.  Copy the attributes.  */
+      out_attr = elf_known_obj_attributes_proc (obfd);
+
+      /* If Tag_CSKY_CPU_NAME is already set, save it.  */
+      memcpy (&tattr, &out_attr[Tag_CSKY_ARCH_NAME], sizeof (tattr));
+
+      _bfd_elf_copy_obj_attributes (ibfd, obfd);
+
+      out_attr = elf_known_obj_attributes_proc (obfd);
+
+      /* Restore Tag_CSKY_CPU_NAME.  */
+      memcpy (&out_attr[Tag_CSKY_ARCH_NAME], &tattr, sizeof (tattr));
+
+      /* Use the Tag_null value to indicate the attributes have been
+        initialized.  */
+      out_attr[0].i = 1;
+    }
+
+  in_attr = elf_known_obj_attributes_proc (ibfd);
+  out_attr = elf_known_obj_attributes_proc (obfd);
+
+  for (i = LEAST_KNOWN_OBJ_ATTRIBUTE; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
+    {
+      /* Merge this attribute with existing attributes.  */
+      switch (i)
+        {
+       case Tag_CSKY_CPU_NAME:
+       case Tag_CSKY_ARCH_NAME:
+         /* Do arch merge.  */
+         new_arch = csky_find_arch_with_name (in_attr[Tag_CSKY_ARCH_NAME].s);
+         old_arch = csky_find_arch_with_name (out_attr[Tag_CSKY_ARCH_NAME].s);
+
+         if (new_arch != NULL && old_arch != NULL)
+           {
+             if (new_arch->class != old_arch->class)
+               {
+                 msg = _("%pB: machine flag conflict with target");
+                 (*_bfd_error_handler) (msg, ibfd);
+                 bfd_set_error (bfd_error_wrong_format);
+                 return FALSE;
+               }
+             else if (new_arch->class_level != old_arch->class_level)
+               {
+                 csky_arch_for_merge *newest_arch =
+                   ((new_arch->class_level > old_arch->class_level) ?
+                 new_arch : old_arch);
+
+                 if (new_arch->do_warning || old_arch->do_warning)
+                   {
+                     msg = _("warning: file %pB's arch flag %s conflict "
+                             "with target %s,set target arch flag to %s");
+                     (*_bfd_error_handler) (msg, ibfd,  new_arch->name,
+                                            old_arch->name,
+                                            (newest_arch->name));
+                     bfd_set_error (bfd_error_wrong_format);
+                    }
+
+                 if (out_attr[Tag_CSKY_ARCH_NAME].s != NULL)
+                   bfd_release (obfd, out_attr[Tag_CSKY_ARCH_NAME].s);
+
+                 out_attr[Tag_CSKY_ARCH_NAME].s =
+                   _bfd_elf_attr_strdup (obfd, newest_arch->name);
+               }
+           }
+
+         break;
+
+       case Tag_CSKY_ISA_FLAGS:
+       case Tag_CSKY_ISA_EXT_FLAGS:
+         /* Do ISA merge.  */
+         break;
+
+       case Tag_CSKY_VDSP_VERSION:
+         if (out_attr[i].i == 0)
+           out_attr[i].i = in_attr[i].i;
+         else if (out_attr[i].i != in_attr[i].i)
+           {
+             _bfd_error_handler
+               (_("Error: %pB and %pB has different VDSP version"), ibfd, obfd);
+             result = FALSE;
+           }
+         break;
+
+       case Tag_CSKY_FPU_VERSION:
+         if (out_attr[i].i <= in_attr[i].i
+             && out_attr[i].i == 0)
+           out_attr[i].i = in_attr[i].i;
+         break;
+
+       case Tag_CSKY_DSP_VERSION:
+         if (out_attr[i].i == 0)
+           out_attr[i].i = in_attr[i].i;
+         else if (out_attr[i].i != in_attr[i].i)
+           {
+             _bfd_error_handler
+               (_("Error: %pB and %pB has different DSP version"), ibfd, obfd);
+             result = FALSE;
+           }
+         break;
+
+       case Tag_CSKY_FPU_ABI:
+         if (out_attr[i].i != in_attr[i].i
+             && (out_attr[i].i == 0
+                 || (out_attr[i].i == VAL_CSKY_FPU_ABI_SOFT
+                     && in_attr[i].i == VAL_CSKY_FPU_ABI_SOFTFP)))
+           {
+             out_attr[i].i = in_attr[i].i;
+           }
+         else if (out_attr[i].i == VAL_CSKY_FPU_ABI_HARD
+                  && (out_attr[i].i != in_attr[i].i
+                      && in_attr[i].i != 0))
+           {
+             _bfd_error_handler
+              (_("Error: %pB and %pB has different FPU ABI"), ibfd, obfd);
+              result = FALSE;
+           }
+         break;
+
+       default:
+         result =
+           result && _bfd_elf_merge_unknown_attribute_low (ibfd, obfd, i);
+         break;
+       }
+
+      /* If out_attr was copied from in_attr then it won't have a type yet.  */
+      if (in_attr[i].type && !out_attr[i].type)
+       out_attr[i].type = in_attr[i].type;
+    }
+
+  /* Merge Tag_compatibility attributes and any common GNU ones.  */
+  if (!_bfd_elf_merge_object_attributes (ibfd, info))
+    return FALSE;
+
+  /* Check for any attributes not known on CSKY.  */
+  result &= _bfd_elf_merge_unknown_attribute_list (ibfd, obfd);
+
+  return result;
+}
+
 /* Merge backend specific data from an object file to the output
    object file when linking.  */
 
@@ -2813,6 +3007,9 @@ csky_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   flagword new_flags;
   csky_arch_for_merge *old_arch = NULL;
   csky_arch_for_merge *new_arch = NULL;
+  flagword newest_flag = 0;
+  const char *sec_name;
+  obj_attribute *out_attr;
 
   /* Check if we have the same endianness.  */
   if (! _bfd_generic_verify_endian_match (ibfd, info))
@@ -2822,76 +3019,79 @@ csky_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
     return TRUE;
 
-  new_flags = elf_elfheader (ibfd)->e_flags;
-  old_flags = elf_elfheader (obfd)->e_flags;
+  /* Merge ".csky.attribute" section.  */
+  if (!elf32_csky_merge_attributes (ibfd, info))
+    return FALSE;
 
   if (! elf_flags_init (obfd))
     {
       /* First call, no flags set.  */
       elf_flags_init (obfd) = TRUE;
-      elf_elfheader (obfd)->e_flags = new_flags;
     }
-  else if (new_flags == old_flags)
-    /* Do nothing.  */
-    ;
-  else if (new_flags == 0 || old_flags == 0)
-    /* When one flag is 0, assign the other one's flag.  */
-      elf_elfheader (obfd)->e_flags = new_flags | old_flags;
-  else
+
+  /* Try to merge e_flag.  */
+  new_flags = elf_elfheader (ibfd)->e_flags;
+  old_flags = elf_elfheader (obfd)->e_flags;
+  out_attr = elf_known_obj_attributes_proc (obfd);
+
+  /* the flags like"e , f ,g ..." , we take collection.  */
+  newest_flag = (old_flags & (~CSKY_ARCH_MASK))
+   | (new_flags & (~CSKY_ARCH_MASK));
+
+  sec_name = get_elf_backend_data (ibfd)->obj_attrs_section;
+  if (bfd_get_section_by_name (ibfd, sec_name) == NULL)
     {
-      flagword newest_flag = 0;
+      /* Input BFDs have no ".csky.attribute" section.  */
+      new_arch = csky_find_arch_with_eflag (new_flags & CSKY_ARCH_MASK);
+      old_arch = csky_find_arch_with_name (out_attr[Tag_CSKY_ARCH_NAME].s);
 
-      if ((new_flags & CSKY_ARCH_MASK) != 0
-         && (old_flags & CSKY_ARCH_MASK) != 0)
+      if (new_arch != NULL && old_arch != NULL)
        {
-         new_arch = csky_find_arch_with_eflag (new_flags & CSKY_ARCH_MASK);
-         old_arch = csky_find_arch_with_eflag (old_flags & CSKY_ARCH_MASK);
-         /* Collect flags like e, f, g.  */
-         newest_flag = (old_flags & (~CSKY_ARCH_MASK))
-                        | (new_flags & (~CSKY_ARCH_MASK));
-         if (new_arch != NULL && old_arch != NULL)
+         if (new_arch->class != old_arch->class)
            {
-             if (new_arch->class != old_arch->class)
+             _bfd_error_handler
+               /* xgettext:c-format */
+               (_("%pB: machine flag conflict with target"), ibfd);
+             bfd_set_error (bfd_error_wrong_format);
+             return FALSE;
+           }
+         else if (new_arch->class_level != old_arch->class_level)
+           {
+             csky_arch_for_merge *newest_arch =
+               (new_arch->class_level > old_arch->class_level
+                ? new_arch : old_arch);
+
+             if (new_arch->do_warning || old_arch->do_warning)
                {
                  _bfd_error_handler
                    /* xgettext:c-format */
-                   (_("%pB: machine flag conflict with target"), ibfd);
+                   (_("warning: file %pB's arch flag %s conflicts with "
+                      "target ck%s, using %s"),
+                    ibfd, new_arch->name, old_arch->name,
+                    newest_arch->name);
                  bfd_set_error (bfd_error_wrong_format);
-                 return FALSE;
                }
-             else if (new_arch->class_level != old_arch->class_level)
-               {
-                 csky_arch_for_merge *newest_arch
-                   = (new_arch->class_level > old_arch->class_level
-                      ? new_arch : old_arch);
-                 if (new_arch->do_warning || old_arch->do_warning)
-                   {
-                     _bfd_error_handler
-                       /* xgettext:c-format */
-                       (_("warning: file %pB's arch flag ck%s conflicts with "
-                          "target ck%s, using ck%s"),
-                        ibfd, new_arch->name, old_arch->name,
-                        newest_arch->name);
-                      bfd_set_error (bfd_error_wrong_format);
-                   }
 
-                 newest_flag |= newest_arch->arch_eflag;
-               }
-             else
-               newest_flag |= ((new_flags & (CSKY_ARCH_MASK | CSKY_ABI_MASK))
-                               | (old_flags
-                                  & (CSKY_ARCH_MASK | CSKY_ABI_MASK)));
+             if (out_attr[Tag_CSKY_ARCH_NAME].s != NULL)
+               bfd_release (obfd, out_attr[Tag_CSKY_ARCH_NAME].s);
+
+             out_attr[Tag_CSKY_ARCH_NAME].s =
+               _bfd_elf_attr_strdup (obfd, newest_arch->name);
            }
          else
            newest_flag |= ((new_flags & (CSKY_ARCH_MASK | CSKY_ABI_MASK))
                            | (old_flags & (CSKY_ARCH_MASK | CSKY_ABI_MASK)));
        }
       else
-       newest_flag |= ((new_flags & (CSKY_ARCH_MASK | CSKY_ABI_MASK))
-                       | (old_flags & (CSKY_ARCH_MASK | CSKY_ABI_MASK)));
-
-      elf_elfheader (obfd)->e_flags = newest_flag;
+       {
+         if (new_arch && new_arch->name != NULL)
+           out_attr[Tag_CSKY_ARCH_NAME].s =
+         _bfd_elf_attr_strdup (obfd, new_arch->name);
+       }
     }
+
+  elf_elfheader (obfd)->e_flags = newest_flag;
+
   return TRUE;
 }
 
@@ -5035,6 +5235,47 @@ csky_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
   return TRUE;
 }
 
+/* Determine whether an object attribute tag takes an integer, a
+   string or both.  */
+
+static int
+elf32_csky_obj_attrs_arg_type (int tag)
+{
+  switch (tag)
+    {
+    case Tag_compatibility:
+      return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL;
+    case Tag_CSKY_ARCH_NAME:
+    case Tag_CSKY_CPU_NAME:
+    case Tag_CSKY_FPU_NUMBER_MODULE:
+      return ATTR_TYPE_FLAG_STR_VAL;
+    case Tag_CSKY_ISA_FLAGS:
+    case Tag_CSKY_ISA_EXT_FLAGS:
+    case Tag_CSKY_DSP_VERSION:
+    case Tag_CSKY_VDSP_VERSION:
+    case Tag_CSKY_FPU_VERSION:
+    case Tag_CSKY_FPU_ABI:
+    case Tag_CSKY_FPU_ROUNDING:
+    case Tag_CSKY_FPU_HARDFP:
+    case Tag_CSKY_FPU_Exception:
+    case Tag_CSKY_FPU_DENORMAL:
+      return ATTR_TYPE_FLAG_INT_VAL;
+    default:
+      break;
+    }
+
+  return (tag & 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL : ATTR_TYPE_FLAG_INT_VAL;
+}
+
+/* Attribute numbers >=64 (mod 128) can be safely ignored.  */
+
+static bfd_boolean
+elf32_csky_obj_attrs_handle_unknown (bfd *abfd ATTRIBUTE_UNUSED,
+                                    int tag ATTRIBUTE_UNUSED)
+{
+  return TRUE;
+}
+
 /* End of external entry points for sizing and building linker stubs.  */
 
 /* CPU-related basic API.  */
@@ -5088,4 +5329,15 @@ csky_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
 #define elf_backend_grok_prstatus             csky_elf_grok_prstatus
 #define elf_backend_grok_psinfo               csky_elf_grok_psinfo
 
+/* Attribute sections.  */
+#undef  elf_backend_obj_attrs_vendor
+#define elf_backend_obj_attrs_vendor          "csky"
+#undef  elf_backend_obj_attrs_section
+#define elf_backend_obj_attrs_section         ".csky.attributes"
+#undef  elf_backend_obj_attrs_arg_type
+#define elf_backend_obj_attrs_arg_type        elf32_csky_obj_attrs_arg_type
+#undef  elf_backend_obj_attrs_section_type
+#define elf_backend_obj_attrs_section_type    SHT_CSKY_ATTRIBUTES
+#define elf_backend_obj_attrs_handle_unknown  elf32_csky_obj_attrs_handle_unknown
+
 #include "elf32-target.h"
index 22d95e2b725ba568119236914cebcb38883a6509..8a6cadcc1c0975527105e1a4b5db969ab21d5a46 100644 (file)
@@ -1,3 +1,12 @@
+2020-08-28  Cooper Qu  <cooper.qu@linux.alibaba.com>
+
+       * readelf.c (get_csky_section_type_name): New.
+       (get_section_type_name): Add handler for CSKY.
+       (display_csky_attribute): New.
+       (process_arch_specific): Add handler for CSKY.
+       * testsuite/binutils-all/strip-3.d: Remove .csky.attributes
+       section.
+
 2020-08-27  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
 
        * readelf.c (get_msp430x_section_type_name): Rename to ...
index 3758ff14bfd388ebc649dfc7da81e3a28881268a..f02848e4681707c4a1fee5fbc19070487ed5c7a9 100644 (file)
@@ -4314,6 +4314,16 @@ get_riscv_section_type_name (unsigned int sh_type)
     }
 }
 
+static const char *
+get_csky_section_type_name (unsigned int sh_type)
+{
+  switch (sh_type)
+    {
+    case SHT_CSKY_ATTRIBUTES:  return "CSKY_ATTRIBUTES";
+    default:  return NULL;
+    }
+}
+
 static const char *
 get_section_type_name (Filedata * filedata, unsigned int sh_type)
 {
@@ -4397,6 +4407,9 @@ get_section_type_name (Filedata * filedata, unsigned int sh_type)
            case EM_RISCV:
              result = get_riscv_section_type_name (sh_type);
              break;
+           case EM_CSKY:
+             result = get_csky_section_type_name (sh_type);
+             break;
            default:
              result = NULL;
              break;
@@ -16358,6 +16371,110 @@ display_riscv_attribute (unsigned char *p,
   return p;
 }
 
+static unsigned char *
+display_csky_attribute (unsigned char * p,
+                       const unsigned char * const end)
+{
+  unsigned int tag;
+  unsigned int val;
+  READ_ULEB (tag, p, end);
+
+  if (tag >= Tag_CSKY_MAX)
+    {
+      return display_tag_value (-1, p, end);
+    }
+
+  switch (tag)
+    {
+    case Tag_CSKY_ARCH_NAME:
+      printf ("  Tag_CSKY_ARCH_NAME:\t\t");
+      return display_tag_value (-1, p, end);
+    case Tag_CSKY_CPU_NAME:
+      printf ("  Tag_CSKY_CPU_NAME:\t\t");
+      return display_tag_value (-1, p, end);
+
+    case Tag_CSKY_ISA_FLAGS:
+      printf ("  Tag_CSKY_ISA_FLAGS:\t\t");
+      return display_tag_value (0, p, end);
+    case Tag_CSKY_ISA_EXT_FLAGS:
+      printf ("  Tag_CSKY_ISA_EXT_FLAGS:\t");
+      return display_tag_value (0, p, end);
+
+    case Tag_CSKY_DSP_VERSION:
+      printf ("  Tag_CSKY_DSP_VERSION:\t\t");
+      READ_ULEB (val, p, end);
+      if (val == VAL_CSKY_DSP_VERSION_EXTENSION)
+       printf ("DSP Extension\n");
+      else if (val == VAL_CSKY_DSP_VERSION_2)
+       printf ("DSP 2.0\n");
+      break;
+
+    case Tag_CSKY_VDSP_VERSION:
+      printf ("  Tag_CSKY_VDSP_VERSION:\t");
+      READ_ULEB (val, p, end);
+      printf ("VDSP Version %d\n", val);
+      break;
+
+    case Tag_CSKY_FPU_VERSION:
+      printf ("  Tag_CSKY_FPU_VERSION:\t\t");
+      READ_ULEB (val, p, end);
+      if (val == VAL_CSKY_FPU_VERSION_1)
+       printf ("ABIV1 FPU Version 1\n");
+      else if (val == VAL_CSKY_FPU_VERSION_2)
+       printf ("FPU Version 2\n");
+      break;
+
+    case Tag_CSKY_FPU_ABI:
+      printf ("  Tag_CSKY_FPU_ABI:\t\t");
+      READ_ULEB (val, p, end);
+      if (val == VAL_CSKY_FPU_ABI_HARD)
+       printf ("Hard\n");
+      else if (val == VAL_CSKY_FPU_ABI_SOFTFP)
+       printf ("SoftFP\n");
+      else if (val == VAL_CSKY_FPU_ABI_SOFT)
+       printf ("Soft\n");
+      break;
+    case Tag_CSKY_FPU_ROUNDING:
+      READ_ULEB (val, p, end);
+      if (val == 1) {
+       printf ("  Tag_CSKY_FPU_ROUNDING:\t");
+       printf ("Needed\n");
+      }
+      break;
+    case Tag_CSKY_FPU_DENORMAL:
+      READ_ULEB (val, p, end);
+      if (val == 1) {
+       printf ("  Tag_CSKY_FPU_DENORMAL:\t");
+       printf ("Needed\n");
+      }
+      break;
+    case Tag_CSKY_FPU_Exception:
+      READ_ULEB (val, p, end);
+      if (val == 1) {
+       printf ("  Tag_CSKY_FPU_Exception:\t");
+       printf ("Needed\n");
+      }
+      break;
+    case Tag_CSKY_FPU_NUMBER_MODULE:
+      printf ("  Tag_CSKY_FPU_NUMBER_MODULE:\t");
+      return display_tag_value (-1, p, end);
+    case Tag_CSKY_FPU_HARDFP:
+      printf ("  Tag_CSKY_FPU_HARDFP:\t\t");
+      READ_ULEB (val, p, end);
+      if (val & VAL_CSKY_FPU_HARDFP_HALF)
+       printf (" Half");
+      if (val & VAL_CSKY_FPU_HARDFP_SINGLE)
+       printf (" Single");
+      if (val & VAL_CSKY_FPU_HARDFP_DOUBLE)
+       printf (" Double");
+      printf ("\n");
+      break;
+    default:
+      return display_tag_value (tag, p, end);
+     }
+  return p;
+}
+
 static bfd_boolean
 process_attributes (Filedata * filedata,
                    const char * public_name,
@@ -20146,6 +20263,10 @@ process_arch_specific (Filedata * filedata)
                                 display_tic6x_attribute,
                                 display_generic_attribute);
 
+    case EM_CSKY:
+      return process_attributes (filedata, "csky", SHT_CSKY_ATTRIBUTES,
+                                display_csky_attribute, NULL);
+
     default:
       return process_attributes (filedata, "gnu", SHT_GNU_ATTRIBUTES,
                                 display_public_gnu_attributes,
index 2a886d2dcc6f7c27eef9acdd4e7b0e705c044cc6..cb2f78eef5cf93c8588ccddb712f98663f2f57a4 100644 (file)
@@ -1,6 +1,6 @@
 #PROG: strip
 #source: empty.s
-#strip: -R .text -R .data -R .bss -R .ARM.attributes -R .reginfo -R .gnu.attributes -R .MIPS.abiflags -R .pdr -R .xtensa.info -R .ARC.attributes -R .note.gnu.property -R .riscv.attributes
+#strip: -R .text -R .data -R .bss -R .ARM.attributes -R .reginfo -R .gnu.attributes -R .MIPS.abiflags -R .pdr -R .xtensa.info -R .ARC.attributes -R .note.gnu.property -R .riscv.attributes -R .csky.attributes
 #readelf: -S --wide
 #name: strip empty file
 #target: *-*-linux* *-*-gnu* arm*-*-uclinuxfdpiceabi
index efb82c5770396a941e0302e732f84cdd604d9b44..e65f69b776a40f585b50bbd1c11f30bf681f675f 100644 (file)
@@ -1,3 +1,7 @@
+2020-08-26  Cooper Qu  <cooper.qu@linux.alibaba.com>
+
+        * elfcpp.h (enum SHT): New enum SHT_CSKY_ATTRIBUTES.
+
 2020-07-04  Nick Clifton  <nickc@redhat.com>
 
        Binutils 2.35 branch created.
index 9c7c6294e424e032e9a449f101ae17b194fa0f4c..65d803c00e270327bfa992b0abe1e163c6765bb4 100644 (file)
@@ -413,6 +413,10 @@ enum SHT
   // AARCH64-specific section type.
   SHT_AARCH64_ATTRIBUTES = 0x70000003,
 
+  // CSKY-specific section types.
+  // Object file compatibility attributes.
+  SHT_CSKY_ATTRIBUTES = 0x70000001,
+
   // Link editor is to sort the entries in this section based on the
   // address specified in the associated symbol table entry.
   SHT_ORDERED = 0x7fffffff
index 92dd9784d2a7200bd5a04f080ca626705efe7b57..8d3a92f11386731537cb79593685ca7cf38db1ee 100644 (file)
@@ -1,3 +1,32 @@
+2020-08-28  Cooper Qu  <cooper.qu@linux.alibaba.com>
+
+       * gas/config/tc-csky.c (md_begin): Set attributes.
+       (isa_flag): Change type to unsigned 64 bits.
+       (struct csky_cpu_info): Likewise.
+       (struct csky_macro_info): Likewise.
+       (set_csky_attribute): New.
+       * testsuite/gas/csky/802j.d: Ignore .csky.attributes section.
+       * testsuite/gas/csky/all.d: Likewise.
+       * testsuite/gas/csky/bsr1.d: Likewise.
+       * testsuite/gas/csky/csky_vdsp.d: Likewise.
+       * testsuite/gas/csky/cskyv2_all.d: Likewise.
+       * testsuite/gas/csky/cskyv2_ck803r2.d: Likewise.
+       * testsuite/gas/csky/cskyv2_ck860.d: Likewise.
+       * testsuite/gas/csky/cskyv2_dsp.d: Likewise.
+       * testsuite/gas/csky/cskyv2_elrw.d: Likewise.
+       * testsuite/gas/csky/cskyv2_float.d: Likewise.
+       * testsuite/gas/csky/enhance_dsp.d: Likewise.
+       * testsuite/gas/csky/java.d: Likewise.
+       * testsuite/gas/csky/v1_float.d: Likewise.
+       * testsuite/gas/csky/v2_float_part1.d: Likewise.
+       * testsuite/gas/csky/v2_float_part2.d: Likewise.
+       * testsuite/gas/csky/v2_tls_gd.d: Likewise.
+       * testsuite/gas/csky/v2_tls_ie.d: Likewise.
+       * testsuite/gas/csky/v2_tls_ld.d: Likewise.
+       * testsuite/gas/csky/v2_tls_le.d: Likewise.
+       * testsuite/gas/elf/elf.exp: Add handler for CSKY.
+       * testsuite/gas/elf/section2.e-csky: New.
+
 2020-08-27  Alan Modra  <amodra@gmail.com>
 
        PR 26467
index f621fa9824b2f4ed6a70148b187af843648c365d..9f2975e5f685e718930fdcc924535c714f4d05a0 100644 (file)
@@ -212,7 +212,7 @@ enum
 unsigned int mach_flag = 0;
 unsigned int arch_flag = 0;
 unsigned int other_flag = 0;
-unsigned int isa_flag = 0;
+BFD_HOST_U_64_BIT isa_flag = 0;
 unsigned int dsp_flag = 0;
 
 typedef struct stack_size_entry
@@ -233,7 +233,7 @@ struct csky_cpu_info
 {
   const char *name;
   unsigned int mach_flag;
-  unsigned int isa_flag;
+  BFD_HOST_U_64_BIT isa_flag;
 };
 
 typedef enum
@@ -249,7 +249,7 @@ struct csky_macro_info
   const char *name;
   /* How many operands : if operands == 5, all of 1,2,3,4 are ok.  */
   long oprnd_num;
-  int isa_flag;
+  BFD_HOST_U_64_BIT isa_flag;
   /* Do the work.  */
   void (*handle_func)(void);
 };
@@ -1186,6 +1186,78 @@ md_show_usage (FILE *fp)
   -mvdsp                       enable vector DSP instructions\n"));
 }
 
+static void set_csky_attribute (void)
+{
+  if (mach_flag & CSKY_ARCH_DSP)
+    {
+      if (dsp_flag & CSKY_DSP_FLAG_V2)
+       {
+         /* Set DSPV2.  */
+         bfd_elf_add_obj_attr_int (stdoutput, OBJ_ATTR_PROC,
+                                   Tag_CSKY_DSP_VERSION,
+                                   VAL_CSKY_DSP_VERSION_2);
+       }
+      else if (isa_flag & CSKY_ISA_DSP)
+       {
+         /* Set DSP extension.  */
+         bfd_elf_add_obj_attr_int (stdoutput, OBJ_ATTR_PROC,
+                                   Tag_CSKY_DSP_VERSION,
+                                   VAL_CSKY_DSP_VERSION_EXTENSION);
+       }
+      /* Set VDSP attribute.  */
+      if (isa_flag & CSKY_ISA_VDSP)
+       bfd_elf_add_obj_attr_int (stdoutput, OBJ_ATTR_PROC,
+                                 Tag_CSKY_VDSP_VERSION,
+                                 VAL_CSKY_VDSP_VERSION_1);
+
+      else if (isa_flag & CSKY_ISA_VDSP_2)
+       bfd_elf_add_obj_attr_int (stdoutput, OBJ_ATTR_PROC,
+                                 Tag_CSKY_VDSP_VERSION,
+                                 VAL_CSKY_VDSP_VERSION_2);
+
+    }
+
+  if (mach_flag & CSKY_ARCH_FLOAT)
+    {
+      unsigned int val = VAL_CSKY_FPU_HARDFP_SINGLE;
+      if (IS_CSKY_ARCH_V1 (mach_flag)) {
+       bfd_elf_add_obj_attr_int (stdoutput, OBJ_ATTR_PROC,
+                                 Tag_CSKY_FPU_VERSION,
+                                 VAL_CSKY_FPU_VERSION_1);
+      }
+      else
+       {
+         if (isa_flag & CSKY_ISA_FLOAT_3E4)
+           {
+             bfd_elf_add_obj_attr_int (stdoutput, OBJ_ATTR_PROC,
+                                       Tag_CSKY_FPU_VERSION,
+                                       VAL_CSKY_FPU_VERSION_2);
+             val |= VAL_CSKY_FPU_HARDFP_DOUBLE;
+           }
+         else
+           {
+             bfd_elf_add_obj_attr_int (stdoutput, OBJ_ATTR_PROC,
+                                       Tag_CSKY_FPU_VERSION,
+                                       VAL_CSKY_FPU_VERSION_2);
+           }
+
+         bfd_elf_add_obj_attr_int (stdoutput, OBJ_ATTR_PROC,
+                                   Tag_CSKY_FPU_HARDFP,
+                                   val);
+         bfd_elf_add_obj_attr_string (stdoutput, OBJ_ATTR_PROC,
+                                   Tag_CSKY_FPU_NUMBER_MODULE,
+                                   "IEEE 754");
+       }
+    }
+
+
+  bfd_elf_add_obj_attr_int (stdoutput, OBJ_ATTR_PROC,
+                           Tag_CSKY_ISA_FLAGS, isa_flag);
+
+  bfd_elf_add_obj_attr_int (stdoutput, OBJ_ATTR_PROC,
+                           Tag_CSKY_ISA_EXT_FLAGS, (isa_flag >> 32));
+}
+
 /* Target-specific initialization and option handling.  */
 
 void
@@ -1263,6 +1335,8 @@ md_begin (void)
   for (p_arch = csky_archs; p_arch->arch_flag != 0; p_arch++)
     if ((mach_flag & CSKY_ARCH_MASK) == (p_arch->arch_flag & CSKY_ARCH_MASK))
       {
+       bfd_elf_add_obj_attr_string (stdoutput, OBJ_ATTR_PROC,
+                                    Tag_CSKY_ARCH_NAME, p_arch->name);
        bfd_mach_flag =  p_arch->bfd_mach_flag;
        break;
       }
@@ -1271,6 +1345,8 @@ md_begin (void)
   for (p_cpu = csky_cpus; p_cpu->mach_flag != 0; p_cpu++)
     if ((mach_flag & CPU_ARCH_MASK) == p_cpu->mach_flag)
       {
+       bfd_elf_add_obj_attr_string (stdoutput, OBJ_ATTR_PROC,
+                                    Tag_CSKY_CPU_NAME, p_cpu->name);
        isa_flag |= p_cpu->isa_flag;
        break;
       }
@@ -1298,6 +1374,7 @@ md_begin (void)
            {
              /* In 803, dspv1 is conflict with dspv2. We keep dspv2.  */
              as_warn ("option -mdsp conflicts with -medsp, only enabling -medsp");
+        dsp_flag &= ~CSKY_DSP_FLAG_V1;
              isa_flag &= ~(CSKY_ISA_MAC_DSP | CSKY_ISA_DSP);
              isa_flag |= CSKY_ISA_DSP_ENHANCE;
            }
@@ -1306,6 +1383,7 @@ md_begin (void)
        {
          if (dsp_flag & CSKY_DSP_FLAG_V2)
            {
+             dsp_flag &= ~CSKY_DSP_FLAG_V2;
              isa_flag &= ~CSKY_ISA_DSP_ENHANCE;
              as_warn ("-medsp option is only supported by ck803s, ignoring -medsp");
            }
@@ -1370,7 +1448,7 @@ md_begin (void)
       else
        do_intr_stack = 1;
     }
-  /* TODO: add isa_flag(SIMP/CACHE/APS).  */
+  /* Add isa_flag(SIMP/CACHE/APS).  */
   isa_flag |= (mach_flag & CSKY_ARCH_MAC) ? CSKY_ISA_MAC : 0;
   isa_flag |= (mach_flag & CSKY_ARCH_MP) ? CSKY_ISA_MP : 0;
   isa_flag |= (mach_flag & CSKY_ARCH_CP) ? CSKY_ISA_CP : 0;
@@ -1418,9 +1496,11 @@ md_begin (void)
     str_hash_insert (csky_macros_hash,
                     v2_lrw_macro_opcode.name, &v2_lrw_macro_opcode, 0);
   /* Set e_flag to ELF Head.  */
-  bfd_set_private_flags (stdoutput, mach_flag);
+  bfd_set_private_flags (stdoutput, mach_flag & ~(0xffff));
   /* Set bfd_mach to bfd backend data.  */
   bfd_set_arch_mach (stdoutput, bfd_arch_csky, bfd_mach_flag);
+
+  set_csky_attribute ();
 }
 
 /* The C-SKY assembler emits mapping symbols $t and $d to mark the
index af7c8577590bfb17e762503752f6ffa169fa6a9e..c75666b20cdbef4d1bbae7e4eb6c3f571705cd6b 100644 (file)
@@ -11,3 +11,4 @@ Disassembly of section \.text:
 \s*[0-9a-f]*:\s*1460\s*nie
 \s*[0-9a-f]*:\s*1461\s*nir
 \s*[0-9a-f]*:\s*3ae0\s*jmpix\s*r2,\s*16.*
+#...
index c5da5b0cfd0aa4f0d7b3ea3e25582743cd291037..606bcc0d3c6a4d64429b4dd75206961114fd0c8d 100644 (file)
@@ -148,3 +148,4 @@ Disassembly of section \.text:
 \s*[0-9a-f]*:\s*1e37\s*or\s*r7, r7, r3
 \s*[0-9a-f]*:\s*1715\s*xor\s*r5, r5, r1
 \s*[0-9a-f]*:\s*1726\s*xor\s*r6, r6, r2
+#...
index 91ba60df164cb542cd4d09dcd6eade3f5060c726..69bef8868793584e16bdb1c4eb5d2a39e39ff274 100644 (file)
@@ -10,3 +10,4 @@ Disassembly of section \.text:
 \s*[0-9a-f]:\s*f7fe\s*br\s*0x0\s*\/\/\s*0\s*\<lable*\>
 \s*[0-9a-f]:\s*e7fd\s*bt\s*0x0\s*\/\/\s*0\s*\<lable*\>
 \s*[0-9a-f]:\s*effc\s*bf\s*0x0\s*\/\/\s*0\s*\<lable*\>
+#...
index 0e2eaa2c0d1aa2dc0c436e4cc30868caa935a37f..3af441315b93706dd0ef052f5a835bc8ebd5906f 100644 (file)
@@ -362,3 +362,4 @@ Disassembly of section \.text:
 \s*[0-9a-f]*:\s*f8830fa2\s*vicl\.8\s*vr2,\s*vr3,\s*vr4
 \s*[0-9a-f]*:\s*f8930fa2\s*vicl\.16\s*vr2,\s*vr3,\s*vr4
 \s*[0-9a-f]*:\s*fa830fa2\s*vicl\.32\s*vr2,\s*vr3,\s*vr4
+#...
index 5092690aa3f515707f10c6432c5fa185a3a1cde1..bb688ec97d4ca20ac63c832b2a21d8b374142303 100644 (file)
@@ -323,3 +323,4 @@ Disassembly of section \.text:
 \s*[0-9a-f]*:\s*cc480000\s*lrs\.w\s*r2,\s*\[0x0\].*
 \s*[0-9a-f]*:\s*ec430002\s*ori\s*r2,\s*r3,\s*2
 \s*[0-9a-f]*:\s*ec43000a\s*ori\s*r2,\s*r3,\s*10
+#...
index 298022aefdb7131f52846cbc39869bf8965cde51..8ef9e905c093d3a8159a9fe6603098beff8abc3f 100644 (file)
@@ -10,3 +10,4 @@ Disassembly of section \.text:
 #...
 \s*[0-9a-f]*:\s*6c03\s*mov\s*r0,\s*r0
 \s*[0-9a-f]*:\s*e820fffd\s*bnezad\s*r0,\s*0.*
+#...
index 2beb8845b7be9f05cd7067f1d49812e2a2273a5b..639bdbf8cd934ae191723261fd04f811aba3fa50 100644 (file)
@@ -38,4 +38,5 @@ Disassembly of section \.text:
 \s*[0-9a-f]*:\s*c2000420\s*sync.s
 \s*[0-9a-f]*:\s*c0000420\s*sync
 \s*[0-9a-f]*:\s*d8437000\s*ldex.w\s*r2,\s*\(r3,\s*0x0\)
-\s*[0-9a-f]*:\s*dc437000\s*stex.w\s*r2,\s*\(r3,\s*0x0\)
\ No newline at end of file
+\s*[0-9a-f]*:\s*dc437000\s*stex.w\s*r2,\s*\(r3,\s*0x0\)
+#...
index f2e3d33c3091c2458dacbb618f10da5545d901b1..3bc52fee8c3355c73d557db17754391f6146b87f 100644 (file)
@@ -1,4 +1,4 @@
-# name: csky - all
+# name: csky - dsp
 #as: -mcpu=ck810e -W
 #objdump: -D
 
@@ -16,3 +16,4 @@ Disassembly of section \.text:
 \s*[0-9a-f]*:\s*c4319080\s*mulshs\s*r17,\s*r1
 \s*[0-9a-f]*:\s*c6ec9440\s*mulswa\s*r12,\s*r23
 \s*[0-9a-f]*:\s*c4a39480\s*mulsws\s*r3,\s*r5
+#...
index 5a52d5ac57fbd54ee61c3bc3c274e5d6642e5849..d0acefbfce49a025ced6cb32bf4f67950e486aba 100644 (file)
@@ -8,3 +8,4 @@
 #...
 \s*[0-9a-f]*:\s*c0004020\s*rte
 \s*[0-9a-f]*:\s*00001234\s*\.long\s*0x00001234
+#...
index f1039c9e68a938db9273190fce5f7fdfeeeeb568..b1ed9cb72e37b0134c9f524dfb9966802c93c1ed 100644 (file)
@@ -57,3 +57,4 @@ Disassembly of section \.text:
 \s*[0-9a-f]*:\s*f4041aab\s*fuitod\s*fr11,\s*fr4
 \s*[0-9a-f]*:\s*f4081ac2\s*fdtos\s*fr2,\s*fr8
 \s*[0-9a-f]*:\s*f40b1ae5\s*fstod\s*fr5,\s*fr11
+#...
index 96d26ab6c50fd2f75c9abaa8f884eaba77067a64..17b33eaecb01c72ea63b73708403ac90d3a25f47 100644 (file)
@@ -216,3 +216,4 @@ Disassembly of section \.text:
 \s*[0-9a-f]*:\s*f8838ce2\s*mulsca\.s16\.e\s*r2,\s*r3,\s*r4
 \s*[0-9a-f]*:\s*f8838ce2\s*mulsca\.s16\.e\s*r2,\s*r3,\s*r4
 \s*[0-9a-f]*:\s*f8838442\s*mula\.32\.l\s*r2,\s*r3,\s*r4
+#...
index f433d5290895d472c3abe58a92ceac12e4c13147..c0791bff037fb5418025d3fc52c4806db8c3a700 100644 (file)
@@ -10,3 +10,4 @@ Disassembly of section \.text:
 \s*[0-9a-f]:\s*14ae\s*bpop\.w\s*r3
 \s*[0-9a-f]:\s*14ec\s*bpush\.h\s*r3
 \s*[0-9a-f]:\s*14ee\s*bpush\.w\s*r3
+#...
index 995a77d3826f5542f8e73d9706737913deaa8941..4c08897706b838601113a0467e95e924a2e7bb83 100644 (file)
@@ -220,3 +220,4 @@ Disassembly of section \.text:
 \s*[0-9a-f]*:\s*ffe08002\s*\.long\s*0xffe08002
 \s*[0-9a-f]*:\s*ffe20002\s*\.long\s*0xffe20002
 \s*[0-9a-f]*:\s*ffe18002\s*\.long\s*0xffe18002
+#...
index aa0b0a4495d0dd3d38aa87e944a52459fa24f4cc..c3f5d56e7b6a86aa046cb2a438e4cf0a8c82cc32 100644 (file)
@@ -52,3 +52,4 @@ Disassembly of section \.text:
 \s*[0-9a-f]*:\s*f4830202\s*fmuls\s*fr2,\s*fr3,\s*fr4
 \s*[0-9a-f]*:\s*f4830022\s*fsubs\s*fr2,\s*fr3,\s*fr4
 \s*[0-9a-f]*:\s*f4830002\s*fadds\s*fr2,\s*fr3,\s*fr4
+#...
index 94b04e06e3bbe8c0044d81cbe9cb475f07f48fb9..78fa37bc0389868dc61b766e2284dcb0e7b0ac24 100644 (file)
@@ -18,3 +18,4 @@ Disassembly of section \.text:
 \s*[0-9a-f]*:\s*4048f5c3\s*\.long\s*0x4048f5c3
 \s*[0-9a-f]*:\s*51eb851f\s*\.long\s*0x51eb851f
 \s*[0-9a-f]*:\s*40091eb8\s*\.long\s*0x40091eb8
+#...
index 226beaa5c7fa7493e68131339455e3ab80aa551f..6680d6e0321c165b6e4d87d1de63d7522d08afed 100644 (file)
@@ -8,3 +8,4 @@ Disassembly of section \.text:
 #...
 \s*[0-9a-f]*:\s*R_CKCORE_TLS_GD32\s*xxx.*
 \s*[0-9a-f]*:\s*R_CKCORE_PLT32\s*__tls_get_addr
+#...
index db77387875a60858eb0a75b09c991456308b9e6f..d55d1cebffc5d57f700dc55a03a905288e2c15c8 100644 (file)
@@ -7,3 +7,4 @@
 Disassembly of section \.text:
 #...
 \s*[0-9a-f]*:\s*R_CKCORE_TLS_IE32\s*xxx.*
+#...
index 9f12ace4dcc91704dbb477c467ba532a5fe5b55c..4843a4198b4fb1ebc581216306ea4fa7acbc591a 100644 (file)
@@ -9,3 +9,4 @@ Disassembly of section \.text:
 \s*[0-9a-f]*:\s*R_CKCORE_TLS_LDM32\s*xxx.*
 \s*[0-9a-f]*:\s*R_CKCORE_PLT32\s*__tls_get_addr
 \s*[0-9a-f]*:\s*R_CKCORE_TLS_LDO32\s*xxx
+#...
index c34d6d7047118b75b131fa106df950776429068a..e4ab53637fe1b22eb3be950acb176de23ac1a483 100644 (file)
@@ -1,4 +1,4 @@
-# name: csky - v2 TLS IE
+# name: csky - v2 TLS LE
 #as: -mcpu=ck810 -W
 #objdump: -Dr
 
@@ -7,3 +7,4 @@
 Disassembly of section \.text:
 #...
 \s*[0-9a-f]*:\s*R_CKCORE_TLS_LE32\s*xxx
+#...
index 2f9893b3d2b23c1ed76d1cb39caa3d6683f26585..8520421ba308ad0838bd45fd064a643b904c5e6f 100644 (file)
@@ -65,6 +65,9 @@ if { [is_elf_format] } then {
     if {[istarget "avr*-*-*"]} {
        set dump_opts {{as -mno-link-relax}}
     }
+    if {[istarget "csky*-*-*"]} {
+       set target_machine -csky
+    }
     if {[istarget "m32r*-*-*"]} then {
        set target_machine -m32r
     }
diff --git a/gas/testsuite/gas/elf/section2.e-csky b/gas/testsuite/gas/elf/section2.e-csky
new file mode 100644 (file)
index 0000000..115bae2
--- /dev/null
@@ -0,0 +1,9 @@
+
+Symbol table '.symtab' contains 6 entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+ +0: 0+0 +0 +NOTYPE +LOCAL +DEFAULT +UND 
+ +1: 0+0 +0 +SECTION +LOCAL +DEFAULT +1 
+ +2: 0+0 +0 +SECTION +LOCAL +DEFAULT +2 
+ +3: 0+0 +0 +SECTION +LOCAL +DEFAULT +3 
+ +4: 0+0 +0 +SECTION +LOCAL +DEFAULT +4 
+ +5: 0+0 +0 +SECTION +LOCAL +DEFAULT +5 
index c53e4058c2fc665368ff1e201e55ac68f3b546d5..4da03f8cd9bbe76e4529b32f48c82bc46ae597ab 100644 (file)
@@ -1,3 +1,57 @@
+2020-08-28  Cooper Qu  <cooper.qu@linux.alibaba.com>
+
+       * elf/csky.h (SHT_CSKY_ATTRIBUTES): Define.
+       (Tag_CSKY_ARCH_NAME): New enum constant.
+       (Tag_CSKY_CPU_NAME): Likewise.
+       (Tag_CSKY_ISA_FLAGS): Likewise.
+       (Tag_CSKY_DSP_VERSION): Likewise.
+       (Tag_CSKY_VDSP_VERSION): Likewise.
+       (Tag_CSKY_FPU_VERSION): Likewise.
+       (Tag_CSKY_FPU_ABI): Likewise.
+       (Tag_CSKY_FPU_ROUNDING): Likewise.
+       (Tag_CSKY_FPU_DENORMAL): Likewise.
+       (Tag_CSKY_FPU_Exception): Likewise.
+       (Tag_CSKY_FPU_NUMBER_MODULE): Likewise.
+       (Tag_CSKY_FPU_HARDFP): Likewise.
+       (Tag_CSKY_MAX): Likewise.
+       (VAL_CSKY_DSP_VERSION_EXTENSION): Likewise.
+       (VAL_CSKY_DSP_VERSION_2): Likewise.
+       (VAL_CSKY_VDSP_VERSION_1): Likewise.
+       (VAL_CSKY_VDSP_VERSION_2): Likewise.
+       (VAL_CSKY_FPU_ABI_SOFT): Likewise.
+       (VAL_CSKY_FPU_ABI_SOFTFP): Likewise.
+       (VAL_CSKY_FPU_ABI_HARD): Likewise.
+       (VAL_CSKY_FPU_HARDFP_HALF): Likewise.
+       (VAL_CSKY_FPU_HARDFP_SINGLE): Likewise.
+       (VAL_CSKY_FPU_HARDFP_DOUBLE): Likewise.
+       * opcode/csky.h (CSKY_ISA_VDSP_V2): Define.
+       CSKYV1_ISA_E1: Change to long constant type.
+       CSKYV2_ISA_E1: Likewise.
+       CSKYV2_ISA_1E2: Likewise.
+       CSKYV2_ISA_2E3: Likewise.
+       CSKYV2_ISA_3E7: Likewise.
+       CSKYV2_ISA_7E10: Likewise.
+       CSKYV2_ISA_3E3R1: Likewise.
+       CSKYV2_ISA_3E3R2: Likewise.
+       CSKYV2_ISA_10E60: Likewise.
+       CSKY_ISA_TRUST: Likewise.
+       CSKY_ISA_CACHE: Likewise.
+       CSKY_ISA_NVIC: Likewise.
+       CSKY_ISA_CP: Likewise.
+       CSKY_ISA_MP: Likewise.
+       CSKY_ISA_MP_1E2: Likewise.
+       CSKY_ISA_JAVA: Likewise.
+       CSKY_ISA_MAC: Likewise.
+       CSKY_ISA_MAC_DSP: Likewise.
+       CSKY_ISA_DSP: Likewise.
+       CSKY_ISA_DSP_1E2: Likewise.
+       CSKY_ISA_DSP_ENHANCE: Likewise.
+       CSKY_ISA_FLOAT_E1: Likewise.
+       CSKY_ISA_FLOAT_1E2: Likewise.
+       CSKY_ISA_FLOAT_1E3: Likewise.
+       CSKY_ISA_FLOAT_3E4: Likewise.
+       CSKY_ISA_VDSP: Likewise.
+
 2020-08-27  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-api.h (ctf_errwarning_next): New err parameter.
index a0571392af0ea4c3dff4f656f18b3f845d6b1e13..cbce6c0173ed7ebb90308f6a94251fa04dfdd7aa 100644 (file)
@@ -94,4 +94,79 @@ START_RELOC_NUMBERS (elf_csky_reloc_type)
     RELOC_NUMBER (R_CKCORE_PCREL_BLOOP_IMM12BY4, 64)
 END_RELOC_NUMBERS (R_CKCORE_MAX)
 
+/* Additional section types.  */
+#define SHT_CSKY_ATTRIBUTES       0x70000001 /* Section holds attributes.  */
+
+/* Object attribute tags.  */
+enum
+{
+  /* 0-3 are generic. */
+  /* Arch name for this object file.  */
+  Tag_CSKY_ARCH_NAME = 4,
+  Tag_CSKY_CPU_NAME = 5,
+
+  /* ISA flags for this object file.  */
+  Tag_CSKY_ISA_FLAGS,
+  Tag_CSKY_ISA_EXT_FLAGS,
+
+  /* CSKY DSP version used by this object file.  */
+  Tag_CSKY_DSP_VERSION,
+
+  /* CSKY VDSP version used by this object file.  */
+  Tag_CSKY_VDSP_VERSION,
+
+  /* CSKY FPU version used by this object file.  */
+  Tag_CSKY_FPU_VERSION = 0x10,
+  /* FPU ABI.  params: Soft GR/Hard GR/Hard FR. */
+  Tag_CSKY_FPU_ABI,
+  /* Rounding Support.  */
+  Tag_CSKY_FPU_ROUNDING,
+  /* Denormal Support.  */
+  Tag_CSKY_FPU_DENORMAL,
+  /* Exeception Support.  */
+  Tag_CSKY_FPU_Exception,
+  /* Number Module Support("IEEE 754").  */
+  Tag_CSKY_FPU_NUMBER_MODULE,
+  /* Half/Single/Double.  */
+  Tag_CSKY_FPU_HARDFP,
+
+  Tag_CSKY_MAX,
+};
+
+/* Object attribute values.  */
+enum
+{
+  /* Values defined for Tag_CSKY_DSP_VERSION.  */
+  VAL_CSKY_DSP_VERSION_EXTENSION = 1,  /* hi-lo DSP extension.  */
+  VAL_CSKY_DSP_VERSION_2 = 2,          /* CK803s EDSP.  */
+};
+
+enum
+{
+  /* Values defined for Tag_CSKY_VDSP_VERSION.  */
+  VAL_CSKY_VDSP_VERSION_1 = 1, /* VDSP version 1.  */
+  VAL_CSKY_VDSP_VERSION_2      /* VDSP version 1.  */
+};
+
+enum
+{
+  /* Values defined for Tag_CSKY_FPU_VERSION.  */
+  VAL_CSKY_FPU_VERSION_1 = 1,  /* ABIV1 FPU.  */
+  VAL_CSKY_FPU_VERSION_2,      /* ABIV2 FPU.  */
+};
+
+enum
+{
+  VAL_CSKY_FPU_ABI_SOFT = 1,
+  VAL_CSKY_FPU_ABI_SOFTFP,
+  VAL_CSKY_FPU_ABI_HARD,
+};
+
+enum
+{
+  VAL_CSKY_FPU_HARDFP_HALF = 1,
+  VAL_CSKY_FPU_HARDFP_SINGLE = 2,
+  VAL_CSKY_FPU_HARDFP_DOUBLE = 4,
+};
+
 #endif /* _ELF_CSKY_H  */
index 098bdc9ba651abcaf52d9e9e266c1c3b04658846..493e822a5a30cae26cd8f6ec49b67990b38cfe6b 100644 (file)
 #include "dis-asm.h"
 
 /* The following bitmasks control instruction set architecture.  */
-#define CSKYV1_ISA_E1       (1 << 0)
-#define CSKYV2_ISA_E1       (1 << 1)
-#define CSKYV2_ISA_1E2      (1 << 2)
-#define CSKYV2_ISA_2E3      (1 << 3)
-#define CSKYV2_ISA_3E7      (1 << 4)
-#define CSKYV2_ISA_7E10     (1 << 5)
-#define CSKYV2_ISA_3E3R1    (1 << 6)
-#define CSKYV2_ISA_3E3R2    (1 << 7)
-#define CSKYV2_ISA_10E60    (1 << 8)
-
-#define CSKY_ISA_TRUST      (1 << 11)
-#define CSKY_ISA_CACHE      (1 << 12)
-#define CSKY_ISA_NVIC       (1 << 13)
-#define CSKY_ISA_CP         (1 << 14)
-#define CSKY_ISA_MP         (1 << 15)
-#define CSKY_ISA_MP_1E2     (1 << 16)
-#define CSKY_ISA_JAVA       (1 << 17)
-#define CSKY_ISA_MAC        (1 << 18)
-#define CSKY_ISA_MAC_DSP    (1 << 19)
+#define CSKYV1_ISA_E1       (1L << 0)
+#define CSKYV2_ISA_E1       (1L << 1)
+#define CSKYV2_ISA_1E2      (1L << 2)
+#define CSKYV2_ISA_2E3      (1L << 3)
+#define CSKYV2_ISA_3E7      (1L << 4)
+#define CSKYV2_ISA_7E10     (1L << 5)
+#define CSKYV2_ISA_3E3R1    (1L << 6)
+#define CSKYV2_ISA_3E3R2    (1L << 7)
+#define CSKYV2_ISA_10E60    (1L << 8)
+
+#define CSKY_ISA_TRUST      (1L << 11)
+#define CSKY_ISA_CACHE      (1L << 12)
+#define CSKY_ISA_NVIC       (1L << 13)
+#define CSKY_ISA_CP         (1L << 14)
+#define CSKY_ISA_MP         (1L << 15)
+#define CSKY_ISA_MP_1E2     (1L << 16)
+#define CSKY_ISA_JAVA       (1L << 17)
+#define CSKY_ISA_MAC        (1L << 18)
+#define CSKY_ISA_MAC_DSP    (1L << 19)
 
 /* Base ISA for csky v1 and v2.  */
-#define CSKY_ISA_DSP        (1 << 20)
-#define CSKY_ISA_DSP_1E2    (1 << 21)
-#define CSKY_ISA_DSP_ENHANCE (1 << 22)
+#define CSKY_ISA_DSP        (1L << 20)
+#define CSKY_ISA_DSP_1E2    (1L << 21)
+#define CSKY_ISA_DSP_ENHANCE (1L << 22)
 
 /* Base float instruction (803f & 810f).  */
-#define CSKY_ISA_FLOAT_E1   (1 << 25)
+#define CSKY_ISA_FLOAT_E1   (1L << 25)
 /* M_FLOAT support (810f).  */
-#define CSKY_ISA_FLOAT_1E2  (1 << 26)
+#define CSKY_ISA_FLOAT_1E2  (1L << 26)
 /* 803 support (803f).  */
-#define CSKY_ISA_FLOAT_1E3  (1 << 27)
+#define CSKY_ISA_FLOAT_1E3  (1L << 27)
 /* 807 support (803f & 807f).  */
-#define CSKY_ISA_FLOAT_3E4  (1 << 28)
+#define CSKY_ISA_FLOAT_3E4  (1L << 28)
 /* Vector DSP support.  */
-#define CSKY_ISA_VDSP       (1 << 29)
+#define CSKY_ISA_VDSP       (1L << 29)
+#define CSKY_ISA_VDSP_2     (1L << 30)
 
 /* The following bitmasks control cpu architecture for CSKY.  */
 #define CSKY_ABI_V1         (1 << 28)
index 568e2217a62cc24778230fcb0f355b038167d69e..16274e8327eba70386f536239687bfbebe92dd69 100644 (file)
@@ -1,3 +1,11 @@
+2020-08-28  Cooper Qu  <cooper.qu@linux.alibaba.com>
+
+       * emulparams/cskyelf.sh: Support attribute section.
+       * testsuite/ld-csky/tls-le-v1.d: Match .csky.attributes section.
+       * ld/testsuite/ld-csky/tls-le.d: Likewise.
+       * testsuite/ld-elf/non-contiguous.ld: Ignore .csky.attributes
+       section.
+
 2020-08-28  Nick Clifton  <nickc@redhat.com>
 
        PR 19011
index d572ac8b6486c6015d09f0b5d43250c3722c4f5c..b940c6c29783d06bd6a9bccf06f2146e806936d3 100644 (file)
@@ -10,6 +10,7 @@ MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
 TEXT_START_ADDR=0x8000
 CHECK_RELOCS_AFTER_OPEN_INPUT=yes
 NONPAGED_TEXT_START_ADDR=0
+ATTRS_SECTIONS='.csky.attributes 0 : { KEEP (*(.csky.attributes)) KEEP (*(.csky.attributes)) }'
 ARCH=csky
 EMBEDDED=yes
 EXTRA_EM_FILE=cskyelf
index 034d5d95d9a73b5b022b748f0b8f9644bfaa53d8..d13c403819d125d8382bdac8105bef5fb2f877d3 100644 (file)
@@ -12,3 +12,5 @@ Idx Name          Size      VMA       LMA       File off  Algn
                   .*
   1 .tbss         .*
                   .*
+  2 .csky.attributes .*
+                  .*
index 8a0d90f03f4a270451eaa9c7f6bab0520146a01e..0a241b3b46718d3829f2804dabcd9895f12e38fc 100644 (file)
@@ -11,3 +11,5 @@ Idx Name          Size      VMA       LMA       File off  Algn
                   .*
   1 .tbss         .*
                   .*
+  2 .csky.attributes .*
+                  .*
index fc72253bfaa47d21b393641280d40b9bd3854ccc..cfd3f248476b58eb0cb0b4b35ac91148e49516ef 100644 (file)
@@ -23,6 +23,7 @@ SECTIONS
             *(.note.renesas)
             *(.MIPS.abiflags)
             *(.MSP430.attributes)
+            *(.csky.attributes)
             *(.gnu.attributes)
    }
 
index 9bf85620eb8dee2bd3f3a896a9d024658dcf86d3..71826bdaea3e2237b12c61a8529766c27926f4f3 100644 (file)
@@ -1,3 +1,15 @@
+2020-08-28  Cooper Qu  <cooper.qu@linux.alibaba.com>
+
+       * csky-dis.c (CSKY_DEFAULT_ISA): Define.
+       (csky_dis_info): Add member isa.
+       (csky_find_inst_info): Skip instructions that do not belong to
+       current CPU.
+       (csky_get_disassembler): Get infomation from attribute section.
+       (print_insn_csky): Set defualt ISA flag.
+       * csky.h (CSKY_ISA_VDSP_2): Rename from CSKY_ISA_VDSP_V2.
+       * csky-opc.h (struct csky_opcode): Change isa_flag16 and
+       isa_flag32'type to unsigned 64 bits.
+
 2020-08-26  Jose E. Marchesi  <jemarch@gnu.org>
 
        * disassemble.c (enum epbf_isa_attr): Add ISA_XBPFBE, ISA_EBPFMAX.
index 537725baa405ff906632b65eb835c12df157b102..6becad0130195453d1b39d2a3507f909978d54a0 100644 (file)
@@ -23,6 +23,7 @@
 #include "config.h"
 #include <stdio.h>
 #include "bfd_stdint.h"
+#include <elf/csky.h>
 #include "disassemble.h"
 #include "elf-bfd.h"
 #include "opcode/csky.h"
@@ -32,6 +33,7 @@
 
 #define CSKY_INST_TYPE unsigned long
 #define HAS_SUB_OPERAND (unsigned int)0xffffffff
+#define CSKY_DEFAULT_ISA 0xffffffff
 
 enum sym_type
 {
@@ -47,6 +49,7 @@ struct csky_dis_info
   disassemble_info *info;
   /* Opcode information.  */
   struct csky_opcode_info const *opinfo;
+  BFD_HOST_U_64_BIT isa;
   /* The value of operand to show.  */
   int value;
   /* Whether to look up/print a symbol name.  */
@@ -159,10 +162,8 @@ csky_find_inst_info (struct csky_opcode_info const **pinfo,
   p = g_opcodeP;
   while (p->mnemonic)
     {
-      /* FIXME: Skip 860's instruction in other CPUs. It is not suitable.
-        These codes need to be optimized.  */
-      if (((CSKY_ARCH_MASK & mach_flag) != CSKY_ARCH_860)
-         && (p->isa_flag32 & CSKYV2_ISA_10E60))
+       if (!(p->isa_flag16 & dis_info.isa)
+             && !(p->isa_flag32 & dis_info.isa))
        {
          p++;
          continue;
@@ -235,9 +236,28 @@ csky_symbol_is_valid (asymbol *sym,
 disassembler_ftype
 csky_get_disassembler (bfd *abfd)
 {
-  if (abfd != NULL)
-    mach_flag = elf_elfheader (abfd)->e_flags;
-  return print_insn_csky;
+  obj_attribute *attr;
+  const char *sec_name = NULL;
+  if (!abfd)
+    return NULL;
+
+  mach_flag = elf_elfheader (abfd)->e_flags;
+
+  sec_name = get_elf_backend_data (abfd)->obj_attrs_section;
+  /* Skip any input that hasn't attribute section.
+     This enables to link object files without attribute section with
+     any others.  */
+  if (bfd_get_section_by_name (abfd, sec_name) != NULL)
+    {
+      attr = elf_known_obj_attributes_proc (abfd);
+      dis_info.isa = attr[Tag_CSKY_ISA_EXT_FLAGS].i;
+      dis_info.isa <<= 32;
+      dis_info.isa |= attr[Tag_CSKY_ISA_FLAGS].i;
+    }
+  else
+    dis_info.isa = CSKY_DEFAULT_ISA;
+
+   return print_insn_csky;
 }
 
 static int
@@ -937,10 +957,16 @@ print_insn_csky (bfd_vma memaddr, struct disassemble_info *info)
   if (mach_flag != INIT_MACH_FLAG && mach_flag != BINARY_MACH_FLAG)
     info->mach = mach_flag;
   else if (mach_flag == INIT_MACH_FLAG)
-    mach_flag = info->mach;
+    {
+      mach_flag = info->mach;
+      dis_info.isa = CSKY_DEFAULT_ISA;
+    }
 
   if (mach_flag == BINARY_MACH_FLAG && info->endian == BFD_ENDIAN_UNKNOWN)
-    info->endian = BFD_ENDIAN_LITTLE;
+    {
+      info->endian = BFD_ENDIAN_LITTLE;
+      dis_info.isa = CSKY_DEFAULT_ISA;
+    }
 
   /* First check the full symtab for a mapping symbol, even if there
      are no usable non-mapping symbols for this address.  */
index 796d3757024a13e0eb6bfcabd6dabdbbc551fb6f..95df44dad389d0268711118cbb105a8f8f9528cc 100644 (file)
@@ -262,8 +262,8 @@ struct csky_opcode
   /* Encodings for 32-bit opcodes.  */
   struct csky_opcode_info op32[OP_TABLE_NUM];
   /* Instruction set flag.  */
-  unsigned int isa_flag16;
-  unsigned int isa_flag32;
+  BFD_HOST_U_64_BIT isa_flag16;
+  BFD_HOST_U_64_BIT isa_flag32;
   /* Whether this insn needs relocation, 0: no, !=0: yes.  */
   signed int reloc16;
   signed int reloc32;