public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [[RESEND & PING]PATCH V3 0/1] Add C-SKY support
@ 2019-06-03  8:17 Mao Han
  2019-06-03  8:19 ` [[RESEND & PING]PATCH V3 1/1] Add backend support for C-SKY Mao Han
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Mao Han @ 2019-06-03  8:17 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mao Han, Mark Wielaard

CC: Mark Wielaard <mark@klomp.org>

This patch add backend support for C-SKY architecture.

FAIL cases on csky:
1. run-backtrace-*
discussed in this thread before, seems can't support with current
core_set_initial_registers.
https://sourceware.org/ml/elfutils-devel/2019-q2/msg00021.html
test binary:
https://github.com/c-sky/test-result/blob/master/elfutils/divzero
https://github.com/c-sky/test-result/blob/master/elfutils/core

2. run-native-test.sh
ssh script problem, can pass if it is ran directly.

3. run-dwarf-getmacros.sh
ssh script problem, the empty string argument is lose,
can pass if it is ran directly.

4. run-deleted.sh
ssh script problem, can pass if it is ran directly.

5. run-reverse-sections-self.sh
elfcopy --reverse-offs dose not work properly on C-SKY object file,
seems not related to arch specific code.
size.o before copy:
https://github.com/c-sky/test-result/blob/master/elfutils/size.o
size.o.rev after copy:
https://github.com/c-sky/test-result/blob/master/elfutils/size.o.rev

Tested on x86:
============================================================================
Testsuite summary for elfutils 0.176
============================================================================
# TOTAL: 207
# PASS:  203
# SKIP:  4
# XFAIL: 0
# FAIL:  0
# XPASS: 0
# ERROR: 0
============================================================================

Tested with ssh on C-SKY:
==========================================
   elfutils 0.176: tests/test-suite.log
==========================================

# TOTAL: 207
# PASS:  198
# SKIP:  5
# XFAIL: 0
# FAIL:  4
# XPASS: 0
# ERROR: 0

.. contents:: :depth: 2

SKIP: run-readelf-compressed.sh
===============================

elfutils built without bzip2 support
SKIP run-readelf-compressed.sh (exit status: 77)

FAIL: run-native-test.sh
========================

allregs: 11615: No such file or directory
FAIL run-native-test.sh (exit status: 1)

FAIL: run-dwarf-getmacros.sh
============================

--- dwarf-getmacros.out	2019-05-29 18:10:03.896561841 +0800
+++ /tmp/123	2019-05-29 18:10:02.364561841 +0800
@@ -1 +1,4 @@
-invalid opcode
+opcode 255 with 0 arguments
+file /home/petr/proj/elfutils/master/elfutils/x.c
+ FOO 0
+/file
FAIL run-dwarf-getmacros.sh (exit status: 1)

SKIP: run-backtrace-data.sh
===========================

/home/vmh/workspace/elfutils/tests/backtrace-data: x86_64 linux only test
SKIP run-backtrace-data.sh (exit status: 77)

SKIP: run-backtrace-native-biarch.sh
====================================

biarch testing disabled
SKIP run-backtrace-native-biarch.sh (exit status: 77)

SKIP: run-backtrace-native-core.sh
==================================

Aborted
No core.4784 file generated
SKIP run-backtrace-native-core.sh (exit status: 77)

SKIP: run-backtrace-native-core-biarch.sh
=========================================

biarch testing disabled
SKIP run-backtrace-native-core-biarch.sh (exit status: 77)

FAIL: run-deleted.sh
====================

PID 5007 - process
TID 5007:
#0  0x2ab71846 __nanosleep
#1  0x2ab716e8 sleep
#2  0x2aacc6b0
/home/vmh/workspace/elfutils/src/stack: dwfl_thread_getframes tid 5007 at 0x2aacc6af in /home/vmh/workspace/elfutils/tests/test-13671/deleted-lib.so: Callback returned failure
./run-deleted.sh: line 38: kill: (5007) - No such process
FAIL run-deleted.sh (exit status: 1)

FAIL: run-reverse-sections-self.sh
==================================


copy_elf: /home/vmh/workspace/elfutils/src/addr2line -> addr2line.rev (read,reverse)
setshstrndx: 35
Swapping offsets of section 24 and 25
Swapping offsets of section 28 and 29
Swapping offsets of section 32 and 33
Swapping offsets of section 34 and 35
No errors
elfrdwrdnop addr2line.rev
No errors

copy_elf: /home/vmh/workspace/elfutils/src/elfcmp -> elfcmp.rev (read,reverse)
setshstrndx: 36
Swapping offsets of section 25 and 26
Swapping offsets of section 29 and 30
Swapping offsets of section 33 and 34
Swapping offsets of section 35 and 36
No errors
elfrdwrdnop elfcmp.rev
No errors

copy_elf: /home/vmh/workspace/elfutils/src/objdump -> objdump.rev (read,reverse)
setshstrndx: 36
Swapping offsets of section 25 and 26
Swapping offsets of section 29 and 30
Swapping offsets of section 33 and 34
Swapping offsets of section 35 and 36
No errors
elfrdwrdnop objdump.rev
No errors

copy_elf: /home/vmh/workspace/elfutils/src/readelf -> readelf.rev (read,reverse)
setshstrndx: 36
Swapping offsets of section 25 and 26
Swapping offsets of section 29 and 30
Swapping offsets of section 33 and 34
Swapping offsets of section 35 and 36
No errors
elfrdwrdnop readelf.rev
No errors

copy_elf: /home/vmh/workspace/elfutils/libelf/libelf.so -> libelf.so.rev (read,reverse)
setshstrndx: 36
Swapping offsets of section 25 and 26
Swapping offsets of section 28 and 29
Swapping offsets of section 30 and 31
Swapping offsets of section 33 and 34
Swapping offsets of section 35 and 36
No errors
elfrdwrdnop libelf.so.rev
No errors

copy_elf: /home/vmh/workspace/elfutils/libdw/libdw.so -> libdw.so.rev (read,reverse)
setshstrndx: 36
Swapping offsets of section 25 and 26
Swapping offsets of section 28 and 29
Swapping offsets of section 30 and 31
Swapping offsets of section 33 and 34
Swapping offsets of section 35 and 36
No errors
elfrdwrdnop libdw.so.rev
No errors

copy_elf: /home/vmh/workspace/elfutils/backends/libebl_i386.so -> libebl_i386.so.rev (read,reverse)
setshstrndx: 34
Swapping offsets of section 23 and 24
Swapping offsets of section 26 and 27
Swapping offsets of section 28 and 29
Swapping offsets of section 31 and 32
Swapping offsets of section 33 and 34
No errors
elfrdwrdnop libebl_i386.so.rev
No errors

copy_elf: /home/vmh/workspace/elfutils/backends/libebl_x86_64.so -> libebl_x86_64.so.rev (read,reverse)
setshstrndx: 34
Swapping offsets of section 23 and 24
Swapping offsets of section 26 and 27
Swapping offsets of section 28 and 29
Swapping offsets of section 31 and 32
Swapping offsets of section 33 and 34
No errors
elfrdwrdnop libebl_x86_64.so.rev
No errors

copy_elf: /home/vmh/workspace/elfutils/src/size.o -> size.o.rev (read,reverse)
setshstrndx: 29
Swapping offsets of section 13 and 14
Swapping offsets of section 22 and 23
Swapping offsets of section 28 and 29
/home/vmh/workspace/elfutils/src/elfcmp: /home/vmh/workspace/elfutils/src/size.o size.o.rev differ: section [1], [1] name
FAIL run-reverse-sections-self.sh (exit status: 1)

Changes since v1:
  - Add the Signed-off-by line and the copyright

Changes since v2:
  - move changelog to corresponding entries
  - correct core dump registers size
  - remove unused fpu DWARF register

Mao Han (1):
  Add backend support for C-SKY

 backends/ChangeLog       |  11 ++++++
 backends/Makefile.am     |   9 ++++-
 backends/csky_cfi.c      |  60 ++++++++++++++++++++++++++++
 backends/csky_corenote.c |  61 ++++++++++++++++++++++++++++
 backends/csky_init.c     |  65 ++++++++++++++++++++++++++++++
 backends/csky_initreg.c  |  87 ++++++++++++++++++++++++++++++++++++++++
 backends/csky_regs.c     | 101 +++++++++++++++++++++++++++++++++++++++++++++++
 backends/csky_reloc.def  |  86 ++++++++++++++++++++++++++++++++++++++++
 backends/csky_symbol.c   |  77 ++++++++++++++++++++++++++++++++++++
 libebl/ChangeLog         |   4 ++
 libebl/eblopenbackend.c  |   1 +
 src/ChangeLog            |   4 ++
 src/elflint.c            |   2 +-
 13 files changed, 565 insertions(+), 3 deletions(-)
 create mode 100644 backends/csky_cfi.c
 create mode 100644 backends/csky_corenote.c
 create mode 100644 backends/csky_init.c
 create mode 100644 backends/csky_initreg.c
 create mode 100644 backends/csky_regs.c
 create mode 100644 backends/csky_reloc.def
 create mode 100644 backends/csky_symbol.c

-- 
2.7.4

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [[RESEND & PING]PATCH V3 1/1] Add backend support for C-SKY
  2019-06-03  8:17 [[RESEND & PING]PATCH V3 0/1] Add C-SKY support Mao Han
@ 2019-06-03  8:19 ` Mao Han
  2019-07-10 22:11   ` Mark Wielaard
  2019-07-12 22:10   ` Mark Wielaard
  2019-07-10 21:33 ` [[RESEND & PING]PATCH V3 0/1] Add C-SKY support Mark Wielaard
  2019-07-12 21:49 ` Mark Wielaard
  2 siblings, 2 replies; 12+ messages in thread
From: Mao Han @ 2019-06-03  8:19 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mao Han

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>
---
 backends/ChangeLog       |  11 ++++++
 backends/Makefile.am     |   9 ++++-
 backends/csky_cfi.c      |  60 ++++++++++++++++++++++++++++
 backends/csky_corenote.c |  61 ++++++++++++++++++++++++++++
 backends/csky_init.c     |  65 ++++++++++++++++++++++++++++++
 backends/csky_initreg.c  |  87 ++++++++++++++++++++++++++++++++++++++++
 backends/csky_regs.c     | 101 +++++++++++++++++++++++++++++++++++++++++++++++
 backends/csky_reloc.def  |  86 ++++++++++++++++++++++++++++++++++++++++
 backends/csky_symbol.c   |  77 ++++++++++++++++++++++++++++++++++++
 libebl/ChangeLog         |   4 ++
 libebl/eblopenbackend.c  |   1 +
 src/ChangeLog            |   4 ++
 src/elflint.c            |   2 +-
 13 files changed, 565 insertions(+), 3 deletions(-)
 create mode 100644 backends/csky_cfi.c
 create mode 100644 backends/csky_corenote.c
 create mode 100644 backends/csky_init.c
 create mode 100644 backends/csky_initreg.c
 create mode 100644 backends/csky_regs.c
 create mode 100644 backends/csky_reloc.def
 create mode 100644 backends/csky_symbol.c

diff --git a/backends/ChangeLog b/backends/ChangeLog
index 6c2b47a..9271f9c 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,14 @@
+2019-04-29 Mao Han <han_mao@c-sky.com>
+
+	* Makefile.am: Add C-SKY.
+	* 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-04-14  Mark Wielaard  <mark@klomp.org>
 
 	* riscv_cfi.c: Fix BACKEND define.
diff --git a/backends/Makefile.am b/backends/Makefile.am
index 2126a2e..f221997 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -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_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_cfi.c b/backends/csky_cfi.c
new file mode 100644
index 0000000..7277dbd
--- /dev/null
+++ b/backends/csky_cfi.c
@@ -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
index 0000000..a1479bd
--- /dev/null
+++ b/backends/csky_corenote.c
@@ -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
index 0000000..f0f93d4
--- /dev/null
+++ b/backends/csky_init.c
@@ -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.  */
+  eh->name = "C-SKY";
+  csky_init_reloc (eh);
+  HOOK (eh, reloc_simple_type);
+  HOOK (eh, register_info);
+  HOOK (eh, abi_cfi);
+  HOOK (eh, core_note);
+  HOOK (eh, set_initial_registers_tid);
+  HOOK (eh, machine_flag_check);
+  HOOK (eh, section_type_name);
+
+  /* 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
index 0000000..81a0da3
--- /dev/null
+++ b/backends/csky_initreg.c
@@ -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
index 0000000..7e41381
--- /dev/null
+++ b/backends/csky_regs.c
@@ -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 = 2;
+      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
index 0000000..1108f0c
--- /dev/null
+++ b/backends/csky_reloc.def
@@ -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
index 0000000..79b5bf9
--- /dev/null
+++ b/backends/csky_symbol.c
@@ -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;
+}
diff --git a/libebl/ChangeLog b/libebl/ChangeLog
index e050bfc..aaec22a 100644
--- a/libebl/ChangeLog
+++ b/libebl/ChangeLog
@@ -1,3 +1,7 @@
+2019-04-29 Mao Han <han_mao@c-sky.com>
+
+	* eblopenbackend.c: Add C-SKY.
+
 2019-04-28  Mark Wielaard  <mark@klomp.org>
 
 	* eblsymbolbindingname.c (ebl_symbol_binding_name): Check ebl is
diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
index d54b720..e229dbd 100644
--- a/libebl/eblopenbackend.c
+++ b/libebl/eblopenbackend.c
@@ -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]))
 
diff --git a/src/ChangeLog b/src/ChangeLog
index 580eea9..092067f 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2019-04-29 Mao Han <han_mao@c-sky.com>
+
+	* elflint.c: Add C-SKY.
+
 2019-05-10  Mark Wielaard  <mark@klomp.org>
 
 	* readelf.c (struct attrcb_args): Rename die to dies.
diff --git a/src/elflint.c b/src/elflint.c
index 810c8bd..edb466d 100644
--- a/src/elflint.c
+++ b/src/elflint.c
@@ -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]))
-- 
2.7.4

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [[RESEND & PING]PATCH V3 0/1] Add C-SKY support
  2019-06-03  8:17 [[RESEND & PING]PATCH V3 0/1] Add C-SKY support Mao Han
  2019-06-03  8:19 ` [[RESEND & PING]PATCH V3 1/1] Add backend support for C-SKY Mao Han
@ 2019-07-10 21:33 ` Mark Wielaard
  2019-07-11  3:13   ` Mao Han
  2019-07-12 21:49 ` Mark Wielaard
  2 siblings, 1 reply; 12+ messages in thread
From: Mark Wielaard @ 2019-07-10 21:33 UTC (permalink / raw)
  To: Mao Han, elfutils-devel

Hi Mao Han,

On Mon, 2019-06-03 at 16:16 +0800, Mao Han wrote:
> test binary:
> https://github.com/c-sky/test-result/blob/master/elfutils/divzero
> https://github.com/c-sky/test-result/blob/master/elfutils/core

I was looking at these, but they seem to have a wrong e_machine value
of EM_RCE, not EM_CSKY? Is that deliberate?

Thanks,

Mark

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [[RESEND & PING]PATCH V3 1/1] Add backend support for C-SKY
  2019-06-03  8:19 ` [[RESEND & PING]PATCH V3 1/1] Add backend support for C-SKY Mao Han
@ 2019-07-10 22:11   ` Mark Wielaard
  2019-07-11  3:20     ` Mao Han
  2019-07-12 22:10   ` Mark Wielaard
  1 sibling, 1 reply; 12+ messages in thread
From: Mark Wielaard @ 2019-07-10 22:11 UTC (permalink / raw)
  To: Mao Han, elfutils-devel

Hi Mao Han,

On Mon, 2019-06-03 at 16:16 +0800, Mao Han wrote:
> +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;
> +}

As far as I can see this is like a SHT_GNU_ATTRIBUTES or
SHT_ARM_ATTRIBUTES section. If so, you will also want something like:

diff --git a/src/readelf.c b/src/readelf.c
index cda7c93..8017dc4 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -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 ("\

And then hook check_object_attribute to display any CSKY specific
attribute names/values.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [[RESEND & PING]PATCH V3 0/1] Add C-SKY support
  2019-07-10 21:33 ` [[RESEND & PING]PATCH V3 0/1] Add C-SKY support Mark Wielaard
@ 2019-07-11  3:13   ` Mao Han
  2019-07-11 13:36     ` Mark Wielaard
  0 siblings, 1 reply; 12+ messages in thread
From: Mao Han @ 2019-07-11  3:13 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

On Wed, Jul 10, 2019 at 11:33:23PM +0200, Mark Wielaard wrote:
> Hi Mao Han,
> 
> On Mon, 2019-06-03 at 16:16 +0800, Mao Han wrote:
> > test binary:
> > https://github.com/c-sky/test-result/blob/master/elfutils/divzero
> > https://github.com/c-sky/test-result/blob/master/elfutils/core
> 
> I was looking at these, but they seem to have a wrong e_machine value
> of EM_RCE, not EM_CSKY? Is that deliberate?
>

I used an no upstream toolchain to verify coredump backtrace, which use
the EM_CSKY_OLD equals to 39. We have changed the EM number to 252 in
our newly released toolchain with compatibility to EM_CSKY_OLD.
See binutils/include/elf/common.h:
/* C-SKY historically used 39, the same value as MCORE, from which the
   architecture was derived.  */
#define EM_CSKY_OLD             EM_MCORE

Thanks,
Mao Han 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [[RESEND & PING]PATCH V3 1/1] Add backend support for C-SKY
  2019-07-10 22:11   ` Mark Wielaard
@ 2019-07-11  3:20     ` Mao Han
  2019-07-14 21:03       ` Mark Wielaard
  0 siblings, 1 reply; 12+ messages in thread
From: Mao Han @ 2019-07-11  3:20 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

Hi, Mark

On Thu, Jul 11, 2019 at 12:11:17AM +0200, Mark Wielaard wrote:
> As far as I can see this is like a SHT_GNU_ATTRIBUTES or
> SHT_ARM_ATTRIBUTES section. If so, you will also want something like:
> 
> diff --git a/src/readelf.c b/src/readelf.c
> index cda7c93..8017dc4 100644
> --- a/src/readelf.c
> +++ b/src/readelf.c
> @@ -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 ("\
> 
> And then hook check_object_attribute to display any CSKY specific
> attribute names/values.

Ok, I'll add check for C-SKY here.

Thanks,
Mao Han

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [[RESEND & PING]PATCH V3 0/1] Add C-SKY support
  2019-07-11  3:13   ` Mao Han
@ 2019-07-11 13:36     ` Mark Wielaard
  2019-07-12 11:24       ` Mao Han
  0 siblings, 1 reply; 12+ messages in thread
From: Mark Wielaard @ 2019-07-11 13:36 UTC (permalink / raw)
  To: Mao Han; +Cc: elfutils-devel

On Thu, 2019-07-11 at 11:11 +0800, Mao Han wrote:
> On Wed, Jul 10, 2019 at 11:33:23PM +0200, Mark Wielaard wrote:
> > On Mon, 2019-06-03 at 16:16 +0800, Mao Han wrote:
> > > test binary:
> > > https://github.com/c-sky/test-result/blob/master/elfutils/divzero
> > > https://github.com/c-sky/test-result/blob/master/elfutils/core
> > 
> > I was looking at these, but they seem to have a wrong e_machine
> > value
> > of EM_RCE, not EM_CSKY? Is that deliberate?
> > 
> 
> I used an no upstream toolchain to verify coredump backtrace, which
> use
> the EM_CSKY_OLD equals to 39. We have changed the EM number to 252 in
> our newly released toolchain with compatibility to EM_CSKY_OLD.
> See binutils/include/elf/common.h:
> /* C-SKY historically used 39, the same value as MCORE, from which
> the
>    architecture was derived.  */
> #define EM_CSKY_OLD             EM_MCORE

Aha. But that is unfortunate on 2 levels. First EM_MCORE isn't an
official e_machine name. The value 39 is associated with EM_RCE for the
Morotola RCE. I assume those are the same thing?

Second, it makes it hard to check the elfutils backend since you'll
have to comment out all EM_RCE usage, and change the EM_CSKY to the old
value.

Do you have any binaries/core files generated by an upstream toolchain
that uses the assigned ELF values? That would be really helpful running
some tests.

Thanks,

Mark

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [[RESEND & PING]PATCH V3 0/1] Add C-SKY support
  2019-07-11 13:36     ` Mark Wielaard
@ 2019-07-12 11:24       ` Mao Han
  2019-07-12 21:20         ` Mark Wielaard
  0 siblings, 1 reply; 12+ messages in thread
From: Mao Han @ 2019-07-12 11:24 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

On Thu, Jul 11, 2019 at 03:36:03PM +0200, Mark Wielaard wrote:
> > the EM_CSKY_OLD equals to 39. We have changed the EM number to 252 in
> > our newly released toolchain with compatibility to EM_CSKY_OLD.
> > See binutils/include/elf/common.h:
> > /* C-SKY historically used 39, the same value as MCORE, from which
> > the
> >    architecture was derived.  */
> > #define EM_CSKY_OLD             EM_MCORE
> 
> Aha. But that is unfortunate on 2 levels. First EM_MCORE isn't an
> official e_machine name. The value 39 is associated with EM_RCE for the
> Morotola RCE. I assume those are the same thing?
> 
Yes, they are the same thing.

#define EM_MCORE         39     /* Motorola M*Core */ /* May also be taken by Fujitsu MMA */
#define EM_RCE           39     /* Old name for MCore */

> Second, it makes it hard to check the elfutils backend since you'll
> have to comment out all EM_RCE usage, and change the EM_CSKY to the old
> value.
> 
> Do you have any binaries/core files generated by an upstream toolchain
> that uses the assigned ELF values? That would be really helpful running
> some tests.
>

I've generated binaries/core with an upstream toolchain, however the
divzero testcase doesn't cause any coredump, so I used a zeroptr
testcase instead.
https://github.com/c-sky/test-result/blob/master/elfutils/zeroptr
https://github.com/c-sky/test-result/raw/master/elfutils/core.zeroptr

Thanks,
Mao Han 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [[RESEND & PING]PATCH V3 0/1] Add C-SKY support
  2019-07-12 11:24       ` Mao Han
@ 2019-07-12 21:20         ` Mark Wielaard
  0 siblings, 0 replies; 12+ messages in thread
From: Mark Wielaard @ 2019-07-12 21:20 UTC (permalink / raw)
  To: Mao Han; +Cc: elfutils-devel

On Fri, 2019-07-12 at 19:22 +0800, Mao Han wrote:
> I've generated binaries/core with an upstream toolchain, however the
> divzero testcase doesn't cause any coredump, so I used a zeroptr
> testcase instead.
> https://github.com/c-sky/test-result/blob/master/elfutils/zeroptr
> https://github.com/c-sky/test-result/raw/master/elfutils/core.zeroptr

The zeroptr binary does seem to be a real EM_CSKY one now.
But the core.zeroptr still seems to be a core file for EM_RCE (or
EM_MCORE).

I assume the kernel generated the core file and it doesn't yet produce
real EM_CSKY ELF core files?

If you have any other way to generate a core file (maybe gdb/gcore can
do it?) that would be really helpful.

Thanks,

Mark

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [[RESEND & PING]PATCH V3 0/1] Add C-SKY support
  2019-06-03  8:17 [[RESEND & PING]PATCH V3 0/1] Add C-SKY support Mao Han
  2019-06-03  8:19 ` [[RESEND & PING]PATCH V3 1/1] Add backend support for C-SKY Mao Han
  2019-07-10 21:33 ` [[RESEND & PING]PATCH V3 0/1] Add C-SKY support Mark Wielaard
@ 2019-07-12 21:49 ` Mark Wielaard
  2 siblings, 0 replies; 12+ messages in thread
From: Mark Wielaard @ 2019-07-12 21:49 UTC (permalink / raw)
  To: Mao Han, elfutils-devel

On Mon, 2019-06-03 at 16:16 +0800, Mao Han wrote:
> 5. run-reverse-sections-self.sh
> elfcopy --reverse-offs dose not work properly on C-SKY object file,
> seems not related to arch specific code.
> size.o before copy:
> https://github.com/c-sky/test-result/blob/master/elfutils/size.o
> size.o.rev after copy:
> https://github.com/c-sky/test-result/blob/master/elfutils/size.o.rev

This might be because these files are also EM_RCE instead of EM_CSKY.
But most likely it was because there was a bug in the testcase.
Make sure you have commit d08c68 tests: elfcopy --reverse-offs should
only swap sections next to each other.

It looks like in the original the .csky.attributes and .shstrtab are
not really next to each other (they have consecutive section numbers,
but the file offsets are far apart). And that could have fooled the
original test case.

Please make sure you have the above commit/fix in your tree and see if
it passes then.

Thanks,

Mark

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [[RESEND & PING]PATCH V3 1/1] Add backend support for C-SKY
  2019-06-03  8:19 ` [[RESEND & PING]PATCH V3 1/1] Add backend support for C-SKY Mao Han
  2019-07-10 22:11   ` Mark Wielaard
@ 2019-07-12 22:10   ` Mark Wielaard
  1 sibling, 0 replies; 12+ messages in thread
From: Mark Wielaard @ 2019-07-12 22:10 UTC (permalink / raw)
  To: Mao Han, elfutils-devel

On Mon, 2019-06-03 at 16:16 +0800, Mao Han wrote:
> diff --git a/backends/csky_reloc.def b/backends/csky_reloc.def
> new file mode 100644
> index 0000000..1108f0c
> --- /dev/null
> +++ b/backends/csky_reloc.def
> @@ -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)

OK.

> +RELOC_TYPE (PCRELIMM8BY4,      REL)
> +RELOC_TYPE (PCRELIMM11BY2,     REL)

Do we want these two? They seem to be v1 only.

> +RELOC_TYPE (PCREL32,           REL|DYN)

This is probably wanted, but the CPU ABI document has it listed as ??.

> +RELOC_TYPE (PCRELJSR_IMM11BY2, REL)

Also v1 only?

> +RELOC_TYPE (RELATIVE,          EXEC|DYN)
> +RELOC_TYPE (COPY,              EXEC|DYN)
> +RELOC_TYPE (GLOB_DAT,          EXEC|DYN)
> +RELOC_TYPE (JUMP_SLOT,         EXEC|DYN)

OK.

> +RELOC_TYPE (GOTOFF,            REL)
> +RELOC_TYPE (GOTPC,             REL)
> +RELOC_TYPE (GOT32,             REL)
> +RELOC_TYPE (PLT32,             REL)
> +RELOC_TYPE (ADDRGOT,           REL)
> +RELOC_TYPE (ADDRPLT,           REL)

v1 only?

> +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)

R_CKCORE_GOTOFF_IMM18 is missing, but it is also missing in elf.h.

> +RELOC_TYPE (GOT_IMM18BY4,      REL)
> +RELOC_TYPE (PLT_IMM18BY4,      REL)

R_CKCORE_PCREL_IMM7BY4 missing?

> +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)

The TLS variants aren't yet listed in the CPU ABI doc, but are in
elf.h, so I assume they are OK.

We can list the v1 variants also, their numbers don't overlap.
Just checking it is done deliberately. If they can never occur in v2
ELF binaries I would leave them out.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [[RESEND & PING]PATCH V3 1/1] Add backend support for C-SKY
  2019-07-11  3:20     ` Mao Han
@ 2019-07-14 21:03       ` Mark Wielaard
  0 siblings, 0 replies; 12+ messages in thread
From: Mark Wielaard @ 2019-07-14 21:03 UTC (permalink / raw)
  To: Mao Han; +Cc: elfutils-devel

On Thu, 2019-07-11 at 11:19 +0800, Mao Han wrote:
> On Thu, Jul 11, 2019 at 12:11:17AM +0200, Mark Wielaard wrote:
> > As far as I can see this is like a SHT_GNU_ATTRIBUTES or
> > SHT_ARM_ATTRIBUTES section. If so, you will also want something
> > like:
> > 
> > diff --git a/src/readelf.c b/src/readelf.c
> > index cda7c93..8017dc4 100644
> > --- a/src/readelf.c
> > +++ b/src/readelf.c
> > @@ -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 ("\
> > 
> > And then hook check_object_attribute to display any CSKY specific
> > attribute names/values.
> 
> Ok, I'll add check for C-SKY here.

BTW. I couldn't find what generates the SHT_CSKY_ATTRIBUTES or what the
defined attribute constants are. Are they documented somewhere?

Thanks,

Mark

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-07-14 21:03 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-03  8:17 [[RESEND & PING]PATCH V3 0/1] Add C-SKY support Mao Han
2019-06-03  8:19 ` [[RESEND & PING]PATCH V3 1/1] Add backend support for C-SKY Mao Han
2019-07-10 22:11   ` Mark Wielaard
2019-07-11  3:20     ` Mao Han
2019-07-14 21:03       ` Mark Wielaard
2019-07-12 22:10   ` Mark Wielaard
2019-07-10 21:33 ` [[RESEND & PING]PATCH V3 0/1] Add C-SKY support Mark Wielaard
2019-07-11  3:13   ` Mao Han
2019-07-11 13:36     ` Mark Wielaard
2019-07-12 11:24       ` Mao Han
2019-07-12 21:20         ` Mark Wielaard
2019-07-12 21:49 ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).