]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Add backend support for C-SKY
authorMao Han <han_mao@c-sky.com>
Tue, 16 Jul 2019 11:14:24 +0000 (19:14 +0800)
committerMark Wielaard <mark@klomp.org>
Wed, 17 Jul 2019 09:48:35 +0000 (11:48 +0200)
C-SKY V2 ABI manual:
https://github.com/c-sky/csky-doc/blob/master/C-SKY_V2_CPU_Applications_Binary_Interface_Standards_Manual.pdf
C-SKY architecture user guide:
https://github.com/c-sky/csky-doc/blob/master/CSKY%20Architecture%20user_guide.pdf

Signed-off-by: Mao Han <han_mao@c-sky.com>
21 files changed:
backends/ChangeLog
backends/Makefile.am
backends/csky_attrs.c [new file with mode: 0644]
backends/csky_cfi.c [new file with mode: 0644]
backends/csky_corenote.c [new file with mode: 0644]
backends/csky_init.c [new file with mode: 0644]
backends/csky_initreg.c [new file with mode: 0644]
backends/csky_regs.c [new file with mode: 0644]
backends/csky_reloc.def [new file with mode: 0644]
backends/csky_symbol.c [new file with mode: 0644]
libebl/ChangeLog
libebl/eblopenbackend.c
src/ChangeLog
src/elflint.c
src/readelf.c
tests/ChangeLog
tests/Makefile.am
tests/hello_csky.ko.bz2 [new file with mode: 0644]
tests/run-addrcfi.sh
tests/run-strip-reloc.sh
tests/testfilecsky.bz2 [new file with mode: 0644]

index af1a40e2d2cb4886bd617995c1bddd28133040ba..f1eaf14bdefdbc29226baef6b046e35516bd9bd2 100644 (file)
@@ -1,3 +1,15 @@
+2019-07-13 Mao Han <han_mao@c-sky.com>
+
+       * Makefile.am: Add C-SKY.
+       * csky_attrs.c: New file.
+       * csky_cfi.c: New file.
+       * csky_corenote.c: Likewise.
+       * csky_init.c: Likewise.
+       * csky_initreg.c: Likewise.
+       * csky_regs.c: Likewise.
+       * csky_reloc.def: Likewise.
+       * csky_symbol.c: Likewise.
+
 2019-06-28  Mark Wielaard  <mark@klomp.org>
 
        * aarch64_init.c (aarch64_init.c): Remove eh->name;
index 2126a2eca42e93171029c582c31b35edb935badd..175468f66ccfb93deaf3a6d7927a5db19fdf5b13 100644 (file)
@@ -33,12 +33,13 @@ AM_CPPFLAGS += -I$(top_srcdir)/libebl -I$(top_srcdir)/libasm \
 
 
 modules = i386 sh x86_64 ia64 alpha arm aarch64 sparc ppc ppc64 s390 \
-         tilegx m68k bpf riscv
+         tilegx m68k bpf riscv csky
 libebl_pic = libebl_i386_pic.a libebl_sh_pic.a libebl_x86_64_pic.a    \
             libebl_ia64_pic.a libebl_alpha_pic.a libebl_arm_pic.a    \
             libebl_aarch64_pic.a libebl_sparc_pic.a libebl_ppc_pic.a \
             libebl_ppc64_pic.a libebl_s390_pic.a libebl_tilegx_pic.a \
-            libebl_m68k_pic.a libebl_bpf_pic.a libebl_riscv_pic.a
+            libebl_m68k_pic.a libebl_bpf_pic.a libebl_riscv_pic.a    \
+            libebl_csky_pic.a
 noinst_LIBRARIES = $(libebl_pic)
 noinst_DATA = $(libebl_pic:_pic.a=.so)
 
@@ -136,6 +137,10 @@ riscv_SRCS = riscv_init.c riscv_symbol.c riscv_cfi.c riscv_regs.c \
 libebl_riscv_pic_a_SOURCES = $(riscv_SRCS)
 am_libebl_riscv_pic_a_OBJECTS = $(riscv_SRCS:.c=.os)
 
+csky_SRCS = csky_attrs.c csky_init.c csky_symbol.c csky_cfi.c \
+           csky_regs.c csky_initreg.c csky_corenote.c
+libebl_csky_pic_a_SOURCES = $(csky_SRCS)
+am_libebl_csky_pic_a_OBJECTS = $(csky_SRCS:.c=.os)
 
 libebl_%.so libebl_%.map: libebl_%_pic.a $(libelf) $(libdw) $(libeu)
        @rm -f $(@:.so=.map)
diff --git a/backends/csky_attrs.c b/backends/csky_attrs.c
new file mode 100644 (file)
index 0000000..177f0ba
--- /dev/null
@@ -0,0 +1,67 @@
+/* C-SKY ABI-specified defaults for DWARF CFI.
+   Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <string.h>
+#include <dwarf.h>
+
+#define BACKEND csky_
+#include "libebl_CPU.h"
+
+bool
+csky_check_object_attribute (Ebl *ebl __attribute__ ((unused)),
+                           const char *vendor, int tag,
+                           uint64_t value __attribute__ ((unused)),
+                           const char **tag_name,
+                           const char **value_name __attribute__ ((unused)))
+{
+  if (!strcmp (vendor, "csky"))
+    switch (tag)
+      {
+      case 4:
+       *tag_name = "CSKY_ARCH_NAME";
+       return true;
+
+      case 5:
+       *tag_name = "CSKY_CPU_NAME";
+       return true;
+
+      case 6:
+        *tag_name = "CSKY_ISA_FLAGS";
+        return true;
+
+      case 7:
+        *tag_name = "CSKY_ISA_EXT_FLAGS";
+        return true;
+      }
+
+  return false;
+}
diff --git a/backends/csky_cfi.c b/backends/csky_cfi.c
new file mode 100644 (file)
index 0000000..7277dbd
--- /dev/null
@@ -0,0 +1,60 @@
+/* C-SKY ABI-specified defaults for DWARF CFI.
+   Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <dwarf.h>
+
+#define BACKEND csky_
+#include "libebl_CPU.h"
+
+
+int
+csky_abi_cfi (Ebl *ebl __attribute__ ((unused)), Dwarf_CIE *abi_info)
+{
+  static const uint8_t abi_cfi[] =
+    {
+      DW_CFA_def_cfa, ULEB128_7 (14), ULEB128_7 (0),
+      DW_CFA_val_offset, ULEB128_7 (14), ULEB128_7 (0),
+
+#define SV(n) DW_CFA_same_value, ULEB128_7 (n)
+      SV(4), SV (5), SV (6), SV (7), SV (8), SV (9),
+      SV(10), SV (11), SV (15), SV (16), SV (17)
+#undef SV
+    };
+
+  abi_info->initial_instructions = abi_cfi;
+  abi_info->initial_instructions_end = &abi_cfi[sizeof abi_cfi];
+  abi_info->data_alignment_factor = -4;
+
+  abi_info->return_address_register = 15; /* lr.  */
+
+  return 0;
+}
diff --git a/backends/csky_corenote.c b/backends/csky_corenote.c
new file mode 100644 (file)
index 0000000..a1479bd
--- /dev/null
@@ -0,0 +1,61 @@
+/* C-SKY specific core note handling.
+   Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <elf.h>
+#include <inttypes.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <sys/time.h>
+
+#define BACKEND        csky_
+#include "libebl_CPU.h"
+
+#define        ULONG                   uint32_t
+#define PID_T                  int32_t
+#define        UID_T                   uint32_t
+#define        GID_T                   uint32_t
+#define ALIGN_ULONG            4
+#define ALIGN_PID_T            4
+#define ALIGN_UID_T            4
+#define ALIGN_GID_T            4
+#define TYPE_ULONG             ELF_T_WORD
+#define TYPE_PID_T             ELF_T_SWORD
+#define TYPE_UID_T             ELF_T_WORD
+#define TYPE_GID_T             ELF_T_WORD
+
+static const Ebl_Register_Location prstatus_regs[] =
+  {
+    { .offset = 0, .regno = 0, .count = 36, .bits = 32 } /* r0..r31 */
+  };
+#define PRSTATUS_REGS_SIZE     (36 * 4)
+
+#include "linux-core-note.c"
diff --git a/backends/csky_init.c b/backends/csky_init.c
new file mode 100644 (file)
index 0000000..b34a03a
--- /dev/null
@@ -0,0 +1,65 @@
+/* Initialization of C-SKY specific backend library.
+   Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#define BACKEND                csky_
+#define RELOC_PREFIX   R_CKCORE_
+#include "libebl_CPU.h"
+
+/* This defines the common reloc hooks based on csky_reloc.def.  */
+#include "common-reloc.c"
+
+const char *
+csky_init (Elf *elf __attribute__ ((unused)),
+          GElf_Half machine __attribute__ ((unused)),
+          Ebl *eh,
+          size_t ehlen)
+{
+  /* Check whether the Elf_BH object has a sufficent size.  */
+  if (ehlen < sizeof (Ebl))
+    return NULL;
+
+  /* We handle it.  */
+  csky_init_reloc (eh);
+  HOOK (eh, abi_cfi);
+  HOOK (eh, core_note);
+  HOOK (eh, check_object_attribute);
+  HOOK (eh, machine_flag_check);
+  HOOK (eh, reloc_simple_type);
+  HOOK (eh, register_info);
+  HOOK (eh, section_type_name);
+  HOOK (eh, set_initial_registers_tid);
+
+  /* gcc/config/ #define DWARF_FRAME_REGISTERS.  */
+  eh->frame_nregs = 38;
+
+  return MODVERSION;
+}
diff --git a/backends/csky_initreg.c b/backends/csky_initreg.c
new file mode 100644 (file)
index 0000000..81a0da3
--- /dev/null
@@ -0,0 +1,87 @@
+/* Fetch live process registers from TID. C-SKY version.
+   Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "system.h"
+#include <assert.h>
+#if defined __CSKY__ && defined __linux__
+# include <sys/uio.h>
+# include <sys/procfs.h>
+# include <sys/ptrace.h>
+#endif
+
+#define BACKEND csky_
+#include "libebl_CPU.h"
+
+bool
+csky_set_initial_registers_tid (pid_t tid __attribute__ ((unused)),
+                       ebl_tid_registers_t *setfunc __attribute__ ((unused)),
+                               void *arg __attribute__ ((unused)))
+{
+#if !defined __CSKY__ || !defined __linux__
+  return false;
+#else /* __CSKY__ */
+  struct pt_regs user_regs;
+  struct iovec iovec;
+  iovec.iov_base = &user_regs;
+  iovec.iov_len = sizeof (user_regs);
+  if (ptrace (PTRACE_GETREGSET, tid, NT_PRSTATUS, &iovec) != 0)
+    return false;
+
+  Dwarf_Word dwarf_regs[38];
+
+  /* lr.  */
+  dwarf_regs[15] = user_regs.lr;
+  /* sp.  */
+  dwarf_regs[14] = user_regs.usp;
+  /* r0 ~ r13.  */
+  dwarf_regs[0] = user_regs.a0;
+  dwarf_regs[1] = user_regs.a1;
+  dwarf_regs[2] = user_regs.a2;
+  dwarf_regs[3] = user_regs.a3;
+  for (int i = 4; i < 14; i++)
+    dwarf_regs[i] = user_regs.regs[i - 4];
+  /* r ~ r13.  */
+  for (int i = 16; i < 31; i++)
+    dwarf_regs[i] = user_regs.exregs[i - 16];
+  /* tls.  */
+  dwarf_regs[31] = user_regs.tls;
+  /* hi.  */
+  dwarf_regs[36] = user_regs.rhi;
+  /* lo.  */
+  dwarf_regs[37] = user_regs.rlo;
+  /* pc.  */
+  dwarf_regs[32] = user_regs.pc;
+  setfunc (-1, 1, &dwarf_regs[32], arg);
+
+  return setfunc (0, 38, dwarf_regs, arg);
+#endif
+}
diff --git a/backends/csky_regs.c b/backends/csky_regs.c
new file mode 100644 (file)
index 0000000..6d45c04
--- /dev/null
@@ -0,0 +1,101 @@
+/* Register names and numbers for C-SKY DWARF.
+   Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <string.h>
+#include <dwarf.h>
+
+#define BACKEND csky_
+#include "libebl_CPU.h"
+
+ssize_t
+csky_register_info (Ebl *ebl  __attribute__ ((unused)),
+                   int regno, char *name, size_t namelen,
+                   const char **prefix, const char **setname,
+                   int *bits, int *type)
+{
+  if (name == NULL)
+    return 38;
+
+  *prefix = "";
+  *bits = 32;
+  *type = DW_ATE_signed;
+  *setname = "integer";
+
+  switch (regno)
+    {
+    case 0 ... 9:
+      name[0] = 'r';
+      name[1] = regno + '0';
+      namelen = 2;
+      break;
+
+    case 10 ... 13:
+    case 16 ... 30:
+      name[0] = 'r';
+      name[1] = regno / 10 + '0';
+      name[2] = regno % 10 + '0';
+      namelen = 3;
+      break;
+
+    case 14:
+      stpcpy (name, "sp");
+      namelen = 2;
+      break;
+
+    case 15:
+      stpcpy (name, "lr");
+      namelen = 2;
+      break;
+
+    case 31:
+      stpcpy (name, "tls");
+      namelen = 3;
+      break;
+
+    case 36:
+      stpcpy (name, "hi");
+      namelen = 2;
+      break;
+
+    case 37:
+      stpcpy (name, "lo");
+      namelen = 2;
+      break;
+
+    default:
+      *setname = NULL;
+      return 0;
+    }
+
+  name[namelen++] = '\0';
+  return namelen;
+}
diff --git a/backends/csky_reloc.def b/backends/csky_reloc.def
new file mode 100644 (file)
index 0000000..1108f0c
--- /dev/null
@@ -0,0 +1,86 @@
+/* List the relocation types for csky.  -*- C -*-
+   Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+/*         NAME,               REL|EXEC|DYN    */
+
+
+RELOC_TYPE (NONE,              REL|EXEC|DYN)
+RELOC_TYPE (ADDR32,            REL|EXEC|DYN)
+RELOC_TYPE (PCRELIMM8BY4,      REL)
+RELOC_TYPE (PCRELIMM11BY2,     REL)
+RELOC_TYPE (PCREL32,           REL|DYN)
+RELOC_TYPE (PCRELJSR_IMM11BY2, REL)
+RELOC_TYPE (RELATIVE,          EXEC|DYN)
+RELOC_TYPE (COPY,              EXEC|DYN)
+RELOC_TYPE (GLOB_DAT,          EXEC|DYN)
+RELOC_TYPE (JUMP_SLOT,         EXEC|DYN)
+RELOC_TYPE (GOTOFF,            REL)
+RELOC_TYPE (GOTPC,             REL)
+RELOC_TYPE (GOT32,             REL)
+RELOC_TYPE (PLT32,             REL)
+RELOC_TYPE (ADDRGOT,           REL)
+RELOC_TYPE (ADDRPLT,           REL)
+RELOC_TYPE (PCREL_IMM26BY2,    REL)
+RELOC_TYPE (PCREL_IMM16BY2,    REL)
+RELOC_TYPE (PCREL_IMM16BY4,    REL)
+RELOC_TYPE (PCREL_IMM10BY2,    REL)
+RELOC_TYPE (PCREL_IMM10BY4,    REL)
+RELOC_TYPE (ADDR_HI16,         REL|DYN)
+RELOC_TYPE (ADDR_LO16,         REL|DYN)
+RELOC_TYPE (GOTPC_HI16,                REL)
+RELOC_TYPE (GOTPC_LO16,                REL)
+RELOC_TYPE (GOTOFF_HI16,       REL)
+RELOC_TYPE (GOTOFF_LO16,       REL)
+RELOC_TYPE (GOT12,             REL)
+RELOC_TYPE (GOT_HI16,          REL)
+RELOC_TYPE (GOT_LO16,          REL)
+RELOC_TYPE (PLT12,             REL)
+RELOC_TYPE (PLT_HI16,          REL)
+RELOC_TYPE (PLT_LO16,          REL)
+RELOC_TYPE (ADDRGOT_HI16,      REL)
+RELOC_TYPE (ADDRGOT_LO16,      REL)
+RELOC_TYPE (ADDRPLT_HI16,      REL)
+RELOC_TYPE (ADDRPLT_LO16,      REL)
+RELOC_TYPE (PCREL_JSR_IMM26BY2,        REL|DYN)
+RELOC_TYPE (TOFFSET_LO16,      REL)
+RELOC_TYPE (DOFFSET_LO16,      REL)
+RELOC_TYPE (PCREL_IMM18BY2,    REL)
+RELOC_TYPE (DOFFSET_IMM18,     REL)
+RELOC_TYPE (DOFFSET_IMM18BY2,  REL)
+RELOC_TYPE (DOFFSET_IMM18BY4,  REL)
+RELOC_TYPE (GOT_IMM18BY4,      REL)
+RELOC_TYPE (PLT_IMM18BY4,      REL)
+RELOC_TYPE (PCREL_IMM7BY4,     REL)
+RELOC_TYPE (TLS_LE32,          REL)
+RELOC_TYPE (TLS_IE32,          REL)
+RELOC_TYPE (TLS_GD32,          REL)
+RELOC_TYPE (TLS_LDM32,         REL)
+RELOC_TYPE (TLS_LDO32,         REL)
+RELOC_TYPE (TLS_DTPMOD32,      EXEC|DYN)
+RELOC_TYPE (TLS_DTPOFF32,      EXEC|DYN)
+RELOC_TYPE (TLS_TPOFF32,       EXEC|DYN)
diff --git a/backends/csky_symbol.c b/backends/csky_symbol.c
new file mode 100644 (file)
index 0000000..79b5bf9
--- /dev/null
@@ -0,0 +1,77 @@
+/* C-SKY specific symbolic name handling.
+   Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <assert.h>
+#include <elf.h>
+#include <stddef.h>
+#include <string.h>
+
+#define BACKEND csky_
+#include "libebl_CPU.h"
+
+/* Check for the simple reloc types.  */
+Elf_Type
+csky_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type,
+                       int *addsub __attribute__ ((unused)))
+{
+  switch (type)
+    {
+    case R_CKCORE_ADDR32:
+      return ELF_T_WORD;
+    default:
+      return ELF_T_NUM;
+    }
+}
+
+bool
+csky_machine_flag_check (GElf_Word flags)
+{
+  switch (flags & EF_CSKY_ABIMASK)
+    {
+    case EF_CSKY_ABIV2:
+      return true;
+    case EF_CSKY_ABIV1:
+    default:
+      return false;
+    }
+}
+
+const char *
+csky_section_type_name (int type,
+                      char *buf __attribute__ ((unused)),
+                      size_t len __attribute__ ((unused)))
+{
+  if (type == SHT_CSKY_ATTRIBUTES)
+    return "CSKY_ATTRIBUTES";
+
+  return NULL;
+}
index e42cd34b45199cc1a883f9190de05fc787438f7d..bb91c1528ec8bafb9fc47c4a716454a58b2e3fb7 100644 (file)
@@ -1,3 +1,7 @@
+2019-04-29 Mao Han <han_mao@c-sky.com>
+
+       * eblopenbackend.c: Add C-SKY.
+
 2019-06-28  Mark Wielaard  <mark@klomp.org>
 
        * eblopenbackend.c (try_dlopen): Remove result->name check.
index 9dd519505efbe63a052b5369bba1266a449ab5ea..01711f5e7bd48b7230e9767248ab672f932ae194 100644 (file)
@@ -135,6 +135,7 @@ static const struct
   { "bpf", "elf_bpf", "bpf", 3, EM_BPF, 0, 0 },
   { "riscv", "elf_riscv", "riscv", 5, EM_RISCV, ELFCLASS64, ELFDATA2LSB },
   { "riscv", "elf_riscv", "riscv", 5, EM_RISCV, ELFCLASS32, ELFDATA2LSB },
+  { "csky", "elf_csky", "csky", 4, EM_CSKY, ELFCLASS32, ELFDATA2LSB },
 };
 #define nmachines (sizeof (machines) / sizeof (machines[0]))
 
index 27812b05c23385edc9b072c28281c3db48e3988f..911ad26f82650ed50ea8b4e55d7f61e0684580c1 100644 (file)
@@ -1,3 +1,7 @@
+2019-07-13 Mao Han <han_mao@c-sky.com>
+
+       * elflint.c: Add C-SKY.
+
 2019-06-28  Mark Wielaard  <mark@klomp.org>
 
        * readelf.c (print_ehdr): Use dwelf_elf_e_machine_string instead of
index 810c8bd7f3372b8c1a0c63dc36ca5f540ec2ba22..edb466dd608451ed3b1aed2450d605171faf75fe 100644 (file)
@@ -330,7 +330,7 @@ static const int valid_e_machine[] =
     EM_CRIS, EM_JAVELIN, EM_FIREPATH, EM_ZSP, EM_MMIX, EM_HUANY, EM_PRISM,
     EM_AVR, EM_FR30, EM_D10V, EM_D30V, EM_V850, EM_M32R, EM_MN10300,
     EM_MN10200, EM_PJ, EM_OPENRISC, EM_ARC_A5, EM_XTENSA, EM_ALPHA,
-    EM_TILEGX, EM_TILEPRO, EM_AARCH64, EM_BPF, EM_RISCV
+    EM_TILEGX, EM_TILEPRO, EM_AARCH64, EM_BPF, EM_RISCV, EM_CSKY
   };
 #define nvalid_e_machine \
   (sizeof (valid_e_machine) / sizeof (valid_e_machine[0]))
index cda7c93a18781ac3094b0707828e7a1f87e728eb..2084fb1fedfa794ae49f69191f90310afcecc889 100644 (file)
@@ -3571,7 +3571,9 @@ print_attributes (Ebl *ebl, const GElf_Ehdr *ehdr)
 
       if (shdr == NULL || (shdr->sh_type != SHT_GNU_ATTRIBUTES
                           && (shdr->sh_type != SHT_ARM_ATTRIBUTES
-                              || ehdr->e_machine != EM_ARM)))
+                              || ehdr->e_machine != EM_ARM)
+                          && (shdr->sh_type != SHT_CSKY_ATTRIBUTES
+                              || ehdr->e_machine != EM_CSKY)))
        continue;
 
       printf (gettext ("\
index 81621851d676a0e5496a0791ec0374a040f2252e..63d6af96d7a628dca1f3d43446b9033cbcfd2847 100644 (file)
@@ -1,3 +1,12 @@
+2019-07-16  Mao Han  <han_mao@c-sky.com>
+
+       * hello_csky.ko.bz2: New testfile.
+       * run-addrcfi.sh: Add C-SKY testfile.
+       * run-strip-reloc.sh: Likewise.
+       * testfilecsky.bz2: New testfile.
+       * Makefile.am (EXTRA_DIST): Add hello_csky.ko.bz2 and
+       testfilecsky.bz2.
+
 2019-06-28  Mark Wielaard  <mark@klomp.org>
 
        * Makefile.am (check_PROGRAMS): Add dwelf_elf_e_machine_string.
index a605d0800199e872c8ce49bd195f01ba771d2650..0ac353152c3dd86f5fdbd3294662f52597801767 100644 (file)
@@ -212,7 +212,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
             testfile-nobitsalign.bz2 testfile-nobitsalign.strip.bz2 \
             run-strip-reloc.sh hello_i386.ko.bz2 hello_x86_64.ko.bz2 \
             hello_ppc64.ko.bz2 hello_s390.ko.bz2 hello_aarch64.ko.bz2 \
-            hello_m68k.ko.bz2 hello_riscv64.ko.bz2 \
+            hello_m68k.ko.bz2 hello_riscv64.ko.bz2 hello_csky.ko.bz2 \
             run-unstrip-test.sh run-unstrip-test2.sh \
             testfile-info-link.bz2 testfile-info-link.debuginfo.bz2 \
             testfile-info-link.stripped.bz2 run-unstrip-test3.sh \
@@ -229,6 +229,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
             testfile11-debugframe.bz2 testfile12-debugframe.bz2 \
             testfileaarch64-debugframe.bz2 testfilearm-debugframe.bz2 \
             testfileppc32-debugframe.bz2 testfileppc64-debugframe.bz2 \
+            testfilecsky.bz2 \
             run-varlocs-self.sh run-exprlocs-self.sh \
             run-find-prologues.sh run-allregs.sh run-native-test.sh \
             run-addrname-test.sh run-dwfl-bug-offline-rel.sh \
diff --git a/tests/hello_csky.ko.bz2 b/tests/hello_csky.ko.bz2
new file mode 100644 (file)
index 0000000..ed98c7f
Binary files /dev/null and b/tests/hello_csky.ko.bz2 differ
index fd89d025a3f64f4231b6c9c07828299a6d61be91..64fa24d7be81b4e1fc13ea42684b3ebdc4ce7c25 100755 (executable)
@@ -3747,3 +3747,46 @@ testrun_compare ${abs_builddir}/addrcfi -e testfile-x32 0x00400390 <<\EOF
        control reg66 (%fsw): undefined
 handle_cfi no CFI (.debug_frame): no error
 EOF
+
+# EM_CSKY (function bar 0x8440)
+testfiles testfilecsky
+testrun_compare ${abs_builddir}/addrcfi -e testfilecsky 0x8440 <<\EOF
+dwarf_cfi_addrframe (.eh_frame): no matching address range
+.debug_frame has 0x8440 => [0x8440, 0x844a):
+       return address in reg15
+       CFA location expression: bregx(14)
+       integer reg0 (r0): undefined
+       integer reg1 (r1): undefined
+       integer reg2 (r2): undefined
+       integer reg3 (r3): undefined
+       integer reg4 (r4): same_value
+       integer reg5 (r5): same_value
+       integer reg6 (r6): same_value
+       integer reg7 (r7): same_value
+       integer reg8 (r8): same_value
+       integer reg9 (r9): same_value
+       integer reg10 (r10): same_value
+       integer reg11 (r11): same_value
+       integer reg12 (r12): undefined
+       integer reg13 (r13): undefined
+       integer reg14 (sp): location expression: call_frame_cfa stack_value
+       integer reg15 (lr): same_value
+       integer reg16 (r16): same_value
+       integer reg17 (r17): same_value
+       integer reg18 (r18): undefined
+       integer reg19 (r19): undefined
+       integer reg20 (r20): undefined
+       integer reg21 (r21): undefined
+       integer reg22 (r22): undefined
+       integer reg23 (r23): undefined
+       integer reg24 (r24): undefined
+       integer reg25 (r25): undefined
+       integer reg26 (r26): undefined
+       integer reg27 (r27): undefined
+       integer reg28 (r28): undefined
+       integer reg29 (r29): undefined
+       integer reg30 (r30): undefined
+       integer reg31 (tls): undefined
+       integer reg36 (hi): undefined
+       integer reg37 (lo): undefined
+EOF
index 0c6b1c2cdae4872ac574aa495d1f072fb60591f9..b7ec1420328cdea0fd84f01328c5d47dd671d7b3 100755 (executable)
@@ -18,7 +18,7 @@
 . $srcdir/test-subr.sh
 
 testfiles hello_i386.ko hello_x86_64.ko hello_ppc64.ko hello_s390.ko \
-       hello_aarch64.ko hello_m68k.ko hello_riscv64.ko
+       hello_aarch64.ko hello_m68k.ko hello_riscv64.ko hello_csky.ko
 
 tempfiles readelf.out readelf.out1 readelf.out2
 tempfiles out.stripped1 out.debug1 out.stripped2 out.debug2
@@ -119,6 +119,7 @@ runtest hello_s390.ko 1
 runtest hello_aarch64.ko 1
 runtest hello_m68k.ko 1
 runtest hello_riscv64.ko 1
+runtest hello_csky.ko 1
 
 # self test, shouldn't impact non-ET_REL files at all.
 runtest ${abs_top_builddir}/src/strip 0
diff --git a/tests/testfilecsky.bz2 b/tests/testfilecsky.bz2
new file mode 100644 (file)
index 0000000..dfee449
Binary files /dev/null and b/tests/testfilecsky.bz2 differ