public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH V2 0/2] Add C-SKY support
@ 2019-04-10  7:59 Mao Han
  2019-04-10  8:00 ` [PATCH V2 2/2] Add backend support for C-SKY Mao Han
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Mao Han @ 2019-04-10  7:59 UTC (permalink / raw)
  To: elfutils-devel; +Cc: ren_guo, Mao Han

I'v check some of the failed testcase.
> > FAIL: run-native-test.sh
> > ========================
> > 
> > allregs: 23064: No such file or directory
> > FAIL run-native-test.sh (exit status: 1)
> 
> This is probably because of the script modifications. The test cannot
> find the running process.
> 
The script pass the pid of shell script to ssh which is not exist on target.

FAIL: run-deleted.sh
> > FAIL: run-dwarf-getmacros.sh
> > ============================
> > 
> > --- dwarf-getmacros.out 2019-02-19 19:28:29.405840052 +0800
> > +++ /tmp/123 2019-02-19 19:28:27.789032052 +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)
> 
> This is again surprising.  I think something went wrong invoking the
> test.  If you look at tests/run-dwarf-getmacros.sh you'll see that it
> runs the last testcase twice. Once with 2 and once with 3
> arguments. The third argument is the empty string (but could really be
> anything). Maybe the empty string was lost somehow?

Yes, the empty string is lost. It can pass if I ran the command directly.

> I haven't looked at the code yet, so maybe none of the backtrace tests
> would work even if you could run in "full system mode". If you do have
> a way to generate a C-SKY core file it would be interesting to see if
> you can get a backtrace from it using eu-stack.

I'v tried that and not able to get a backtrace, seems something wrong
with the csky_corenote.c?
# eu-stack --core=./core 
PID 142 - core
eu-stack: Couldn't show any frames.

> > FAIL: run-deleted.sh
> > ====================
> > 
> > PID 12587 - process
> > TID 12587:
> > #0 0x2ab79648 sleep
> > #1 0x2ab79648 sleep
> > #2 0x2aace6a4
> > /home/vmh/elfutilswk/src/stack: dwfl_thread_getframes tid 12587 at 0x2aace6a3 in /home/vmh/elfutilswk/tests/test-25076/deleted-lib.so: Callback returned failure
> > ./run-deleted.sh: line 38: kill: (12587) - No such process
> > FAIL run-deleted.sh (exit status: 1)
> 
> This is again most likely because of script changes.
> The test cannot find the running process.
This case can pass if I ran the command directly.

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

Mao Han (2):
  libelf: Sync elf.h from glibc
  Add backend support for C-SKY

 backends/ChangeLog       |  13 +++++
 backends/Makefile.am     |   9 +++-
 backends/csky_cfi.c      |  60 +++++++++++++++++++++++
 backends/csky_corenote.c |  61 ++++++++++++++++++++++++
 backends/csky_init.c     |  65 +++++++++++++++++++++++++
 backends/csky_initreg.c  |  86 +++++++++++++++++++++++++++++++++
 backends/csky_regs.c     | 122 +++++++++++++++++++++++++++++++++++++++++++++++
 backends/csky_reloc.def  |  86 +++++++++++++++++++++++++++++++++
 backends/csky_symbol.c   |  77 ++++++++++++++++++++++++++++++
 libebl/eblopenbackend.c  |   1 +
 libelf/ChangeLog         |   4 ++
 libelf/elf.h             |  96 ++++++++++++++++++++++++++++++++++++-
 src/elflint.c            |   2 +-
 13 files changed, 677 insertions(+), 5 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] 10+ messages in thread

* [PATCH V2 1/2] libelf: Sync elf.h from glibc
  2019-04-10  7:59 [PATCH V2 0/2] Add C-SKY support Mao Han
  2019-04-10  8:00 ` [PATCH V2 2/2] Add backend support for C-SKY Mao Han
@ 2019-04-10  8:00 ` Mao Han
  2019-04-14 20:32   ` Mark Wielaard
  2019-04-14 20:23 ` [PATCH V2 0/2] Add C-SKY support Mark Wielaard
  2 siblings, 1 reply; 10+ messages in thread
From: Mao Han @ 2019-04-10  8:00 UTC (permalink / raw)
  To: elfutils-devel; +Cc: ren_guo, Mao Han

Signed-off-by: Mao Han <han_mao@c-sky.com>
---
 libelf/ChangeLog |  4 +++
 libelf/elf.h     | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 98 insertions(+), 2 deletions(-)

diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index d9b7749..d3bdac3 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,7 @@
+2019-04-01  Mao Han  <han_mao@c-sky.com>
+
+	* elf.h: Update from glibc.
+
 2019-03-07  Mark Wielaard  <mark@klomp.org>
 
 	* elf32_updatefile.c (updatemmap): Use posix_memalign instead of
diff --git a/libelf/elf.h b/libelf/elf.h
index 75043bc..01648bd 100644
--- a/libelf/elf.h
+++ b/libelf/elf.h
@@ -1,5 +1,5 @@
 /* This file defines standard ELF types, structures, and macros.
-   Copyright (C) 1995-2018 Free Software Foundation, Inc.
+   Copyright (C) 1995-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -360,8 +360,9 @@ typedef struct
 #define EM_RISCV	243	/* RISC-V */
 
 #define EM_BPF		247	/* Linux BPF -- in-kernel virtual machine */
+#define EM_CSKY		252     /* C-SKY */
 
-#define EM_NUM		248
+#define EM_NUM		253
 
 /* Old spellings/synonyms.  */
 
@@ -808,6 +809,9 @@ typedef struct
 #define NT_ARM_SYSTEM_CALL	0x404	/* ARM system call number */
 #define NT_ARM_SVE	0x405		/* ARM Scalable Vector Extension
 					   registers */
+#define NT_VMCOREDD	0x700		/* Vmcore Device Dump Note.  */
+#define NT_MIPS_DSP	0x800		/* MIPS DSP ASE registers.  */
+#define NT_MIPS_FP_MODE	0x801		/* MIPS floating-point mode.  */
 
 /* Legal values for the note segment descriptor types for object files.  */
 
@@ -1214,6 +1218,9 @@ typedef struct
 #define AT_L3_CACHESIZE		46
 #define AT_L3_CACHEGEOMETRY	47
 
+#define AT_MINSIGSTKSZ		51 /* Stack needed for signal delivery
+				      (AArch64).  */
+
 /* Note section contents.  Each entry in the note section begins with
    a header of a fixed form.  */
 
@@ -3015,6 +3022,81 @@ enum
 /* Keep this the last entry.  */
 #define R_ARM_NUM		256
 
+/* C-SKY */
+#define R_CKCORE_NONE               0	/* no reloc */
+#define R_CKCORE_ADDR32             1	/* direct 32 bit (S + A) */
+#define R_CKCORE_PCRELIMM8BY4       2	/* disp ((S + A - P) >> 2) & 0xff   */
+#define R_CKCORE_PCRELIMM11BY2      3	/* disp ((S + A - P) >> 1) & 0x7ff  */
+#define R_CKCORE_PCREL32            5	/* 32-bit rel (S + A - P)           */
+#define R_CKCORE_PCRELJSR_IMM11BY2  6	/* disp ((S + A - P) >>1) & 0x7ff   */
+#define R_CKCORE_RELATIVE           9	/* 32 bit adjust program base(B + A)*/
+#define R_CKCORE_COPY               10	/* 32 bit adjust by program base    */
+#define R_CKCORE_GLOB_DAT           11	/* off between got and sym (S)      */
+#define R_CKCORE_JUMP_SLOT          12	/* PLT entry (S) */
+#define R_CKCORE_GOTOFF             13	/* offset to GOT (S + A - GOT)      */
+#define R_CKCORE_GOTPC              14	/* PC offset to GOT (GOT + A - P)   */
+#define R_CKCORE_GOT32              15	/* 32 bit GOT entry (G) */
+#define R_CKCORE_PLT32              16	/* 32 bit PLT entry (G) */
+#define R_CKCORE_ADDRGOT            17	/* GOT entry in GLOB_DAT (GOT + G)  */
+#define R_CKCORE_ADDRPLT            18	/* PLT entry in GLOB_DAT (GOT + G)  */
+#define R_CKCORE_PCREL_IMM26BY2     19	/* ((S + A - P) >> 1) & 0x3ffffff   */
+#define R_CKCORE_PCREL_IMM16BY2     20	/* disp ((S + A - P) >> 1) & 0xffff */
+#define R_CKCORE_PCREL_IMM16BY4     21	/* disp ((S + A - P) >> 2) & 0xffff */
+#define R_CKCORE_PCREL_IMM10BY2     22	/* disp ((S + A - P) >> 1) & 0x3ff  */
+#define R_CKCORE_PCREL_IMM10BY4     23	/* disp ((S + A - P) >> 2) & 0x3ff  */
+#define R_CKCORE_ADDR_HI16          24	/* high & low 16 bit ADDR */
+                                        /* ((S + A) >> 16) & 0xffff */
+#define R_CKCORE_ADDR_LO16          25	/* (S + A) & 0xffff */
+#define R_CKCORE_GOTPC_HI16         26	/* high & low 16 bit GOTPC */
+                                        /* ((GOT + A - P) >> 16) & 0xffff */
+#define R_CKCORE_GOTPC_LO16         27	/* (GOT + A - P) & 0xffff */
+#define R_CKCORE_GOTOFF_HI16        28	/* high & low 16 bit GOTOFF */
+                                        /* ((S + A - GOT) >> 16) & 0xffff */
+#define R_CKCORE_GOTOFF_LO16        29	/* (S + A - GOT) & 0xffff */
+#define R_CKCORE_GOT12              30	/* 12 bit disp GOT entry (G) */
+#define R_CKCORE_GOT_HI16           31	/* high & low 16 bit GOT */
+                                        /* (G >> 16) & 0xffff */
+#define R_CKCORE_GOT_LO16           32	/* (G & 0xffff) */
+#define R_CKCORE_PLT12              33	/* 12 bit disp PLT entry (G) */
+#define R_CKCORE_PLT_HI16           34	/* high & low 16 bit PLT */
+                                        /* (G >> 16) & 0xffff */
+#define R_CKCORE_PLT_LO16           35	/* G & 0xffff */
+#define R_CKCORE_ADDRGOT_HI16       36	/* high & low 16 bit ADDRGOT */
+                                        /* (GOT + G * 4) & 0xffff */
+#define R_CKCORE_ADDRGOT_LO16       37	/* (GOT + G * 4) & 0xffff */
+#define R_CKCORE_ADDRPLT_HI16       38	/* high & low 16 bit ADDRPLT */
+                                        /* ((GOT + G * 4) >> 16) & 0xFFFF */
+#define R_CKCORE_ADDRPLT_LO16       39	/* (GOT+G*4) & 0xffff */
+#define R_CKCORE_PCREL_JSR_IMM26BY2 40	/* disp ((S+A-P) >>1) & x3ffffff */
+#define R_CKCORE_TOFFSET_LO16       41	/* (S+A-BTEXT) & 0xffff */
+#define R_CKCORE_DOFFSET_LO16       42	/* (S+A-BTEXT) & 0xffff */
+#define R_CKCORE_PCREL_IMM18BY2     43	/* disp ((S+A-P) >>1) & 0x3ffff */
+#define R_CKCORE_DOFFSET_IMM18      44	/* disp (S+A-BDATA) & 0x3ffff */
+#define R_CKCORE_DOFFSET_IMM18BY2   45	/* disp ((S+A-BDATA)>>1) & 0x3ffff */
+#define R_CKCORE_DOFFSET_IMM18BY4   46	/* disp ((S+A-BDATA)>>2) & 0x3ffff */
+#define R_CKCORE_GOT_IMM18BY4       48	/* disp (G >> 2) */
+#define R_CKCORE_PLT_IMM18BY4       49	/* disp (G >> 2) */
+#define R_CKCORE_PCREL_IMM7BY4      50	/* disp ((S+A-P) >>2) & 0x7f */
+#define R_CKCORE_TLS_LE32           51	/* 32 bit offset to TLS block */
+#define R_CKCORE_TLS_IE32           52
+#define R_CKCORE_TLS_GD32           53
+#define R_CKCORE_TLS_LDM32          54
+#define R_CKCORE_TLS_LDO32          55
+#define R_CKCORE_TLS_DTPMOD32       56
+#define R_CKCORE_TLS_DTPOFF32       57
+#define R_CKCORE_TLS_TPOFF32        58
+
+/* C-SKY elf header definition.  */
+#define EF_CSKY_ABIMASK		    0XF0000000
+#define EF_CSKY_OTHER		    0X0FFF0000
+#define EF_CSKY_PROCESSOR	    0X0000FFFF
+
+#define EF_CSKY_ABIV1		    0X10000000
+#define EF_CSKY_ABIV2		    0X20000000
+
+/* C-SKY attributes section.  */
+#define SHT_CSKY_ATTRIBUTES	    (SHT_LOPROC + 1)
+
 /* IA-64 specific declarations.  */
 
 /* Processor specific flags for the Ehdr e_flags field.  */
@@ -3915,6 +3997,16 @@ enum
 #define R_METAG_TLS_LE_HI16	60
 #define R_METAG_TLS_LE_LO16	61
 
+/* NDS32 relocations.  */
+#define R_NDS32_NONE		0
+#define R_NDS32_32_RELA 	20
+#define R_NDS32_COPY		39
+#define R_NDS32_GLOB_DAT	40
+#define R_NDS32_JMP_SLOT	41
+#define R_NDS32_RELATIVE	42
+#define R_NDS32_TLS_TPOFF	102
+#define R_NDS32_TLS_DESC	119
+
 __END_DECLS
 
 #endif	/* elf.h */
-- 
2.7.4

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

* [PATCH V2 2/2] Add backend support for C-SKY
  2019-04-10  7:59 [PATCH V2 0/2] Add C-SKY support Mao Han
@ 2019-04-10  8:00 ` Mao Han
  2019-04-15 11:09   ` Mark Wielaard
  2019-04-10  8:00 ` [PATCH V2 1/2] libelf: Sync elf.h from glibc Mao Han
  2019-04-14 20:23 ` [PATCH V2 0/2] Add C-SKY support Mark Wielaard
  2 siblings, 1 reply; 10+ messages in thread
From: Mao Han @ 2019-04-10  8:00 UTC (permalink / raw)
  To: elfutils-devel; +Cc: ren_guo, 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       |  13 +++++
 backends/Makefile.am     |   9 +++-
 backends/csky_cfi.c      |  60 +++++++++++++++++++++++
 backends/csky_corenote.c |  61 ++++++++++++++++++++++++
 backends/csky_init.c     |  65 +++++++++++++++++++++++++
 backends/csky_initreg.c  |  86 +++++++++++++++++++++++++++++++++
 backends/csky_regs.c     | 122 +++++++++++++++++++++++++++++++++++++++++++++++
 backends/csky_reloc.def  |  86 +++++++++++++++++++++++++++++++++
 backends/csky_symbol.c   |  77 ++++++++++++++++++++++++++++++
 libebl/eblopenbackend.c  |   1 +
 src/elflint.c            |   2 +-
 11 files changed, 579 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 0c61a0b..0c3193e 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,16 @@
+2019-04-01 Mao Han <han_mao@c-sky.com>
+
+	* backends/Makefile.am: Add C-SKY.
+	* backends/csky_cfi.c: New file.
+	* backends/csky_corenote.c: Likewise.
+	* backends/csky_init.c: Likewise.
+	* backends/csky_initreg.c: Likewise.
+	* backends/csky_regs.c: Likewise.
+	* backends/csky_reloc.def: Likewise.
+	* backends/csky_symbol.c: Likewise.
+	* libebl/eblopenbackend.c: Add C-SKY.
+	* src/elflint.c: Likewise.
+
 2019-02-15  Mark Wielaard  <mark@klomp.org>
 
 	* s390_init.c (s390_init): Hook check_special_symbol.
diff --git a/backends/Makefile.am b/backends/Makefile.am
index 2126a2e..155db8a 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..6895c9e
--- /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..c32b386
--- /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 = 38, .bits = 32 } /* r0..r31 */
+  };
+#define PRSTATUS_REGS_SIZE	(38 * 4)
+
+#include "linux-core-note.c"
diff --git a/backends/csky_init.c b/backends/csky_init.c
new file mode 100644
index 0000000..2ae3481
--- /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 = 71;
+
+  return MODVERSION;
+}
diff --git a/backends/csky_initreg.c b/backends/csky_initreg.c
new file mode 100644
index 0000000..6563b8a
--- /dev/null
+++ b/backends/csky_initreg.c
@@ -0,0 +1,86 @@
+/* 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[71];
+
+  /* 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[34] = user_regs.rhi;
+  /* lo.  */
+  dwarf_regs[35] = user_regs.rlo;
+  /* pc.  */
+  dwarf_regs[70] = user_regs.pc;
+
+  return setfunc (0, 71, dwarf_regs, arg);
+#endif
+}
diff --git a/backends/csky_regs.c b/backends/csky_regs.c
new file mode 100644
index 0000000..0b6706e
--- /dev/null
+++ b/backends/csky_regs.c
@@ -0,0 +1,122 @@
+/* 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 71;
+
+  *prefix = "";
+  *bits = 38;
+  *type = DW_ATE_signed;
+  *setname = "integer";
+
+  switch (regno)
+    {
+    case 0:
+      stpcpy (name, "tls");
+      namelen = 3;
+      break;
+
+    case 1:
+      stpcpy (name, "lr");
+      namelen = 2;
+      break;
+
+    case 2:
+      stpcpy (name, "pc");
+      namelen = 2;
+      break;
+
+    case 3:
+      stpcpy (name, "sr");
+      namelen = 2;
+      break;
+
+    case 4:
+      stpcpy (name, "usp");
+      namelen = 2;
+      break;
+
+    case 5 ... 14:
+      name[0] = 'r';
+      name[1] = regno - 5 + '0';
+      namelen = 2;
+      break;
+
+    case 15 ... 24:
+      name[0] = 'r';
+      name[1] = '1';
+      name[2] = regno - 15 + '0';
+      namelen = 3;
+      break;
+
+    case 25 ... 34:
+      name[0] = 'r';
+      name[1] = '2';
+      name[2] = regno - 25 + '0';
+      namelen = 3;
+      break;
+
+    case 35:
+      stpcpy (name, "r31");
+      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..96235cb
--- /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_ABIV1:
+    case EF_CSKY_ABIV2:
+      return true;
+    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/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/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] 10+ messages in thread

* Re: [PATCH V2 0/2] Add C-SKY support
  2019-04-10  7:59 [PATCH V2 0/2] Add C-SKY support Mao Han
  2019-04-10  8:00 ` [PATCH V2 2/2] Add backend support for C-SKY Mao Han
  2019-04-10  8:00 ` [PATCH V2 1/2] libelf: Sync elf.h from glibc Mao Han
@ 2019-04-14 20:23 ` Mark Wielaard
  2019-04-17  6:45   ` Mao Han
  2 siblings, 1 reply; 10+ messages in thread
From: Mark Wielaard @ 2019-04-14 20:23 UTC (permalink / raw)
  To: Mao Han, elfutils-devel; +Cc: ren_guo

On Wed, 2019-04-10 at 15:51 +0800, Mao Han wrote:
> I'v check some of the failed testcase.

Thanks for double checking, it seems we understand all of the cases why
they fail except...

> > I haven't looked at the code yet, so maybe none of the backtrace tests
> > would work even if you could run in "full system mode". If you do have
> > a way to generate a C-SKY core file it would be interesting to see if
> > you can get a backtrace from it using eu-stack.
> 
> I'v tried that and not able to get a backtrace, seems something wrong
> with the csky_corenote.c?
> # eu-stack --core=./core 
> PID 142 - core
> eu-stack: Couldn't show any frames.

It is hard to say what went wrong.
In theory you can examine the executable and core file cross arch, if
there is backend support. So if you could post a small binary and a
core file for it somewhere we can try debugging together.

Try something like:
$ ulimit -c unlimited
$ echo "int main () { int i = 1; i /= i - 1; }" | gcc -xc -static -o divzero -
$ ./divzero 
Floating point exception (core dumped)
$ eu-stack --core core.18678 --exec divzero
PID 18678 - core
TID 18678:
#0  0x0000000000400ff3 main
#1  0x00000000004011e4 generic_start_main
#2  0x0000000000401461 __libc_start_main
#3  0x0000000000400ef6 _start

If you could run that on your C-SKY setup and post the (static) binary
and core file somewhere (they are probably too big for the mailinglist.

Cheers,

Mark

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

* Re: [PATCH V2 1/2] libelf: Sync elf.h from glibc
  2019-04-10  8:00 ` [PATCH V2 1/2] libelf: Sync elf.h from glibc Mao Han
@ 2019-04-14 20:32   ` Mark Wielaard
  0 siblings, 0 replies; 10+ messages in thread
From: Mark Wielaard @ 2019-04-14 20:32 UTC (permalink / raw)
  To: Mao Han, elfutils-devel; +Cc: ren_guo

On Wed, 2019-04-10 at 15:51 +0800, Mao Han wrote:
> +2019-04-01  Mao Han  <han_mao@c-sky.com>
> +
> +	* elf.h: Update from glibc.

Looks like a clean sync from glibc.
Pushed to master.

Thanks,

Mark

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

* Re: [PATCH V2 2/2] Add backend support for C-SKY
  2019-04-10  8:00 ` [PATCH V2 2/2] Add backend support for C-SKY Mao Han
@ 2019-04-15 11:09   ` Mark Wielaard
  2019-04-16  7:14     ` Mao Han
  0 siblings, 1 reply; 10+ messages in thread
From: Mark Wielaard @ 2019-04-15 11:09 UTC (permalink / raw)
  To: Mao Han, elfutils-devel; +Cc: ren_guo

On Wed, 2019-04-10 at 15:51 +0800, Mao Han wrote:
> 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>

Thanks for adding those references.

> diff --git a/backends/ChangeLog b/backends/ChangeLog
> index 0c61a0b..0c3193e 100644
> --- a/backends/ChangeLog
> +++ b/backends/ChangeLog
> @@ -1,3 +1,16 @@
> +2019-04-01 Mao Han <han_mao@c-sky.com>
> +
> +	* backends/Makefile.am: Add C-SKY.
> +	* backends/csky_cfi.c: New file.
> +	* backends/csky_corenote.c: Likewise.
> +	* backends/csky_init.c: Likewise.
> +	* backends/csky_initreg.c: Likewise.
> +	* backends/csky_regs.c: Likewise.
> +	* backends/csky_reloc.def: Likewise.
> +	* backends/csky_symbol.c: Likewise.
> +	* libebl/eblopenbackend.c: Add C-SKY.
> +	* src/elflint.c: Likewise.

We have ChangeLog files per directory.
So you don't need to prefix with backends/
And the last two entries should go into their own (libebl and src)
ChangeLog files.

> diff --git a/backends/Makefile.am b/backends/Makefile.am
> index 2126a2e..155db8a 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)

Looks correct.

> diff --git a/backends/csky_cfi.c b/backends/csky_cfi.c
> new file mode 100644
> index 0000000..6895c9e
> --- /dev/null
> +++ b/backends/csky_cfi.c
> +#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;
> +}

OK, that seems to match the calling convention, CFA is defined as sp,
prev SP comes from the cfa address, the link register has the default
return address.

> diff --git a/backends/csky_corenote.c b/backends/csky_corenote.c
> new file mode 100644
> index 0000000..c32b386
> --- /dev/null
> +++ b/backends/csky_corenote.c
> +#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 = 38, .bits = 32 } /* r0..r31 */
> +  };
> +#define PRSTATUS_REGS_SIZE	(38 * 4)
> +
> +#include "linux-core-note.c"

OK, that is a very simple 32bit architecture/register setup.

> diff --git a/backends/csky_init.c b/backends/csky_init.c
> new file mode 100644
> index 0000000..2ae3481
> --- /dev/null
> +++ b/backends/csky_init.c
> @@ -0,0 +1,65 @@
> +/* Initialization of C-SKY specific backend library.
> +
> +#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 = 71;
> +
> +  return MODVERSION;
> +}

The hooks are setup correctly.

The 71 matches what can/is being restored through other hooks. But
seems to not match the c-SKY V2 CPU ABI DWARF register mappings. Also
maybe it should be 70, because you are using link as return register
and don't explicitly need to store the pc (see below).

> diff --git a/backends/csky_initreg.c b/backends/csky_initreg.c
> new file mode 100644
> index 0000000..6563b8a
> --- /dev/null
> +++ b/backends/csky_initreg.c
> @@ -0,0 +1,86 @@
> +/* Fetch live process registers from TID. C-SKY version.
> +
> +#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[71];
> +
> +  /* 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[34] = user_regs.rhi;
> +  /* lo.  */
> +  dwarf_regs[35] = user_regs.rlo;
> +  /* pc.  */
> +  dwarf_regs[70] = user_regs.pc;
> +
> +  return setfunc (0, 71, dwarf_regs, arg);
> +#endif
> +}

I think you should use setfunc (-1, -1, &regs[70], arg) to set the pc
explicitly and then setfunc (0, 36, dwarf_regs, arg) to set the rest.
But you don't seem to actually need the full 71 dwarf_regs array. Again
I am confused about the actual DWARF register number mapping.

> diff --git a/backends/csky_regs.c b/backends/csky_regs.c
> new file mode 100644
> index 0000000..0b6706e
> --- /dev/null
> +++ b/backends/csky_regs.c
> @@ -0,0 +1,122 @@
> +/* Register names and numbers for C-SKY DWARF.
> +#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 71;
> +
> +  *prefix = "";
> +  *bits = 38;
> +  *type = DW_ATE_signed;
> +  *setname = "integer";
> +
> +  switch (regno)
> +    {
> +    case 0:
> +      stpcpy (name, "tls");
> +      namelen = 3;
> +      break;
> +
> +    case 1:
> +      stpcpy (name, "lr");
> +      namelen = 2;
> +      break;
> +
> +    case 2:
> +      stpcpy (name, "pc");
> +      namelen = 2;
> +      break;
> +
> +    case 3:
> +      stpcpy (name, "sr");
> +      namelen = 2;
> +      break;
> +
> +    case 4:
> +      stpcpy (name, "usp");
> +      namelen = 2;
> +      break;
> +
> +    case 5 ... 14:
> +      name[0] = 'r';
> +      name[1] = regno - 5 + '0';
> +      namelen = 2;
> +      break;
> +
> +    case 15 ... 24:
> +      name[0] = 'r';
> +      name[1] = '1';
> +      name[2] = regno - 15 + '0';
> +      namelen = 3;
> +      break;
> +
> +    case 25 ... 34:
> +      name[0] = 'r';
> +      name[1] = '2';
> +      name[2] = regno - 25 + '0';
> +      namelen = 3;
> +      break;
> +
> +    case 35:
> +      stpcpy (name, "r31");
> +      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;
> +}

This confuses me too. So there are 71 registers? But you only handle
0..38? The names don't seem to match the usage in other places, but I
am assuming DWARF register numbers match native register numbering.
Which might not be how things actually work?

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

OK, not double checked against ABI doc, but looks reasonable.

> diff --git a/backends/csky_symbol.c b/backends/csky_symbol.c
> new file mode 100644
> index 0000000..96235cb
> --- /dev/null
> +++ b/backends/csky_symbol.c
> @@ -0,0 +1,77 @@
> +/* C-SKY specific symbolic name handling.
> +
> +#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;
> +    }
> +}

Yes, R_CKCORE_ADDR32 is probably all that is ever needed for inter
DWARF relocations.

> +bool
> +csky_machine_flag_check (GElf_Word flags)
> +{
> +  switch (flags & EF_CSKY_ABIMASK)
> +    {
> +    case EF_CSKY_ABIV1:
> +    case EF_CSKY_ABIV2:
> +      return true;
> +    default:
> +      return false;
> +    }
> +}

OK.
Does the current backend handle both?

> +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;
> +}

OK.
I couldn't find any description of this section.
Is it like SHT_ARM_ATTRIBUTES/SHT_GNU_ATTRIBUTES?
Then you might also want to handle it like that in src/readelf.c
(print_attributes).

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

Looks correct.

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

Likewise.

Thanks,

Mark

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

* Re: [PATCH V2 2/2] Add backend support for C-SKY
  2019-04-15 11:09   ` Mark Wielaard
@ 2019-04-16  7:14     ` Mao Han
  0 siblings, 0 replies; 10+ messages in thread
From: Mao Han @ 2019-04-16  7:14 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: guoren, elfutils-devel

On Mon, Apr 15, 2019 at 01:08:58PM +0200, Mark Wielaard wrote:
> > +	* backends/Makefile.am: Add C-SKY.
> > +	* backends/csky_cfi.c: New file.
> > +	* backends/csky_corenote.c: Likewise.
> > +	* backends/csky_init.c: Likewise.
> > +	* backends/csky_initreg.c: Likewise.
> > +	* backends/csky_regs.c: Likewise.
> > +	* backends/csky_reloc.def: Likewise.
> > +	* backends/csky_symbol.c: Likewise.
> > +	* libebl/eblopenbackend.c: Add C-SKY.
> > +	* src/elflint.c: Likewise.
> 
> We have ChangeLog files per directory.
> So you don't need to prefix with backends/
> And the last two entries should go into their own (libebl and src)
> ChangeLog files.
>
OK
 
> > diff --git a/backends/csky_corenote.c b/backends/csky_corenote.c
> > new file mode 100644
> > index 0000000..c32b386
> > --- /dev/null
> > +++ b/backends/csky_corenote.c
> > +#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 = 38, .bits = 32 } /* r0..r31 */
> > +  };
> > +#define PRSTATUS_REGS_SIZE	(38 * 4)
> > +
> > +#include "linux-core-note.c"
> 
> OK, that is a very simple 32bit architecture/register setup.

The actual size of pr_reg is 36 word, so changed to
static const Ebl_Register_Location prstatus_regs[] =
  {
    /* pc, a1, a0, sr, r2 ~ r31, reserved, reserved */
    { .offset = 0, .regno = 0, .count = 36, .bits = 32 }
  };
#define PRSTATUS_REGS_SIZE      (36 * 4)

We also have 400 bytes fpu registers .reg2 section, will it
cause any prblem if it is not handled?

> > +  /* gcc/config/ #define DWARF_FRAME_REGISTERS.  */
> > +  eh->frame_nregs = 71;
> > +
> > +  return MODVERSION;
> 
> The 71 matches what can/is being restored through other hooks. But
> seems to not match the c-SKY V2 CPU ABI DWARF register mappings. Also
> maybe it should be 70, because you are using link as return register
> and don't explicitly need to store the pc (see below).

As I mentioned in:
https://sourceware.org/ml/elfutils-devel/2019-q2/msg00006.html
DWARF mappings from the document is mismatch with GCC source code.

71 comes from FIRST_PSEUDO_REGISTER
./gcc/defaults.h:#define DWARF_FRAME_REGISTERS FIRST_PSEUDO_REGISTER
The DWARF register mappings should be some thing like(rr stands 
for reserved):
// r0   r1   r2   r3   r4   r5   r6   r7
// 0    1    2    3    4    5    6    7
// r8   r9   r10  r11  r12  r13  sp   lr
// 8    9    10   11   12   13   14   15
// r16  r17  r18  r19  r20  r21  r22  r23
// 16   17   18   19   20   21   22   23
// r24  r25  r26  r27  r28  r29  r30  r31
// 24   25   26   27   28   29   30   31
// rr   rr   rr   rr   hi   lo   epc
// 32   33   34   35   36   37   72
This part is quite similar to native register numbering.
from 38 to 68 are fpu registers, each fpu register is 
consist of two dwarf register. I was intended to support
the fpu part, but the fpu register mapping is not so clear
at present. So I'll drop the fpu part first, only use 38
DWARF registers.

> > diff --git a/backends/csky_regs.c b/backends/csky_regs.c
> > new file mode 100644
> > index 0000000..0b6706e
> > +
> This confuses me too. So there are 71 registers? But you only handle
> 0..38? The names don't seem to match the usage in other places, but I
> am assuming DWARF register numbers match native register numbering.
> Which might not be how things actually work?
>
Likewise.

> > +  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[34] = user_regs.rhi;
> > +  /* lo.  */
> > +  dwarf_regs[35] = user_regs.rlo;
> > +  /* pc.  */
> > +  dwarf_regs[70] = user_regs.pc;
> > +
> > +  return setfunc (0, 71, dwarf_regs, arg);
> > +#endif
> > +}
> 
> I think you should use setfunc (-1, -1, &regs[70], arg) to set the pc
> explicitly and then setfunc (0, 36, dwarf_regs, arg) to set the rest.
> But you don't seem to actually need the full 71 dwarf_regs array. Again
> I am confused about the actual DWARF register number mapping.
> 
OK

> 
> > +bool
> > +csky_machine_flag_check (GElf_Word flags)
> > +{
> > +  switch (flags & EF_CSKY_ABIMASK)
> > +    {
> > +    case EF_CSKY_ABIV1:
> > +    case EF_CSKY_ABIV2:
> > +      return true;
> > +    default:
> > +      return false;
> > +    }
> > +}
> 
> OK.
> Does the current backend handle both?
ABIV1 is not supported with this patch, so return false for ABIV1?

> > +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;
> > +}
> 
> OK.
> I couldn't find any description of this section.
> Is it like SHT_ARM_ATTRIBUTES/SHT_GNU_ATTRIBUTES?
> Then you might also want to handle it like that in src/readelf.c
> (print_attributes).
Yes, it is.
static int
process_csky_specific (FILE * file)
{
  return process_attributes (file, "csky", SHT_CSKY_ATTRIBUTES,
			     display_csky_attribute, NULL);
}
binutils-gdb/binutils/readelf.c
https://github.com/c-sky/binutils-gdb/blob/binutils-2_27-branch-csky/binutils/readelf.c

Thanks,
Mao Han

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

* Re: [PATCH V2 0/2] Add C-SKY support
  2019-04-14 20:23 ` [PATCH V2 0/2] Add C-SKY support Mark Wielaard
@ 2019-04-17  6:45   ` Mao Han
  2019-06-24 22:26     ` Mark Wielaard
  0 siblings, 1 reply; 10+ messages in thread
From: Mao Han @ 2019-04-17  6:45 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: guoren, elfutils-devel

On Sun, Apr 14, 2019 at 10:23:49PM +0200, Mark Wielaard wrote:
> It is hard to say what went wrong.
> In theory you can examine the executable and core file cross arch, if
> there is backend support. So if you could post a small binary and a
> core file for it somewhere we can try debugging together.
> 
> Try something like:
> $ ulimit -c unlimited
> $ echo "int main () { int i = 1; i /= i - 1; }" | gcc -xc -static -o divzero -
> $ ./divzero 
> Floating point exception (core dumped)
> $ eu-stack --core core.18678 --exec divzero
> PID 18678 - core
> TID 18678:
> #0  0x0000000000400ff3 main
> #1  0x00000000004011e4 generic_start_main
> #2  0x0000000000401461 __libc_start_main
> #3  0x0000000000400ef6 _start
> 
> If you could run that on your C-SKY setup and post the (static) binary
> and core file somewhere (they are probably too big for the mailinglist.
>

I'v just spent sometime debuging this. Core dump backtrace on C-SKY seems
can't be supported with current generic routine. DWARF register order is
different from the order in core notes. The initialization of frame
registers is totally incorrect. As the comment says some fix with
private function is needed.

# eu-stack --core core
PID 140 - core
TID 140:
#0  0x0000000000136bd2
eu-stack: dwfl_thread_getframes tid 140 at 0x136bd2 in <unknown>: No DWARF information found

./libdwfl/linux-core-attach.c:260
          /* PPC provides DWARF register 65 irrelevant for
             CFI which clashes with register 108 (LR) we need.
             LR (108) is provided earlier (in NT_PRSTATUS) than the # 65.
             FIXME: It depends now on their order in core notes.
             FIXME: It uses private function.  */
          if (regno < nregs
              && __libdwfl_frame_reg_get (thread->unwound, regno, NULL))
            continue;
          Dwarf_Word val;
          switch (regloc->bits)

linux/arch/csky/abiv2/inc/abi/elf.h
#define ELF_CORE_COPY_REGS(pr_reg, regs) do {   \
        pr_reg[0] = regs->pc;                   \
        pr_reg[1] = regs->a1;                   \
        pr_reg[2] = regs->a0;                   \
        pr_reg[3] = regs->sr;                   \
        pr_reg[4] = regs->a2;                   \
        pr_reg[5] = regs->a3;                   \
        pr_reg[6] = regs->regs[0];              \
        pr_reg[7] = regs->regs[1];              \
        pr_reg[8] = regs->regs[2];              \
        pr_reg[9] = regs->regs[3];              \
        pr_reg[10] = regs->regs[4];             \
        pr_reg[11] = regs->regs[5];             \
        pr_reg[12] = regs->regs[6];             \
        pr_reg[13] = regs->regs[7];             \
        pr_reg[14] = regs->regs[8];             \
        pr_reg[15] = regs->regs[9];             \

BTW the error log seems incorrect here.

diff --git a/src/stack.c b/src/stack.c
index c5f347e..4daabce 100644
--- a/src/stack.c
+++ b/src/stack.c
@@ -608,7 +608,7 @@ parse_opt (int key, char *arg __attribute__ ((unused)),
       if (core != NULL)
        {
          if (dwfl_core_file_attach (dwfl, core) < 0)
-           error (EXIT_BAD, 0, "dwfl_core_file_report: %s", dwfl_errmsg (-1));
+           error (EXIT_BAD, 0, "dwfl_core_file_attach: %s", dwfl_errmsg (-1));
        }
 
       /* Makes sure we are properly attached.  */

Thanks,
Mao Han 

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

* Re: [PATCH V2 0/2] Add C-SKY support
  2019-04-17  6:45   ` Mao Han
@ 2019-06-24 22:26     ` Mark Wielaard
  2019-06-26  7:21       ` Mao Han
  0 siblings, 1 reply; 10+ messages in thread
From: Mark Wielaard @ 2019-06-24 22:26 UTC (permalink / raw)
  To: Mao Han; +Cc: guoren, elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 1241 bytes --]

Hi,

On Wed, 2019-04-17 at 14:41 +0800, Mao Han wrote:
> I'v just spent sometime debuging this. Core dump backtrace on C-SKY
> seems
> can't be supported with current generic routine. DWARF register order is
> different from the order in core notes. The initialization of frame
> registers is totally incorrect. As the comment says some fix with
> private function is needed.

My apologies for taking so long to reply. I am looking at your latest
patch and found this discussion. It will take me a bit to properly
review everything. But I didn't forget.

> BTW the error log seems incorrect here.
> 
> diff --git a/src/stack.c b/src/stack.c
> index c5f347e..4daabce 100644
> --- a/src/stack.c
> +++ b/src/stack.c
> @@ -608,7 +608,7 @@ parse_opt (int key, char *arg __attribute__
> ((unused)),
>        if (core != NULL)
>         {
>           if (dwfl_core_file_attach (dwfl, core) < 0)
> -           error (EXIT_BAD, 0, "dwfl_core_file_report: %s",
> dwfl_errmsg (-1));
> +           error (EXIT_BAD, 0, "dwfl_core_file_attach: %s",
> dwfl_errmsg (-1));
>         }
>  
>        /* Makes sure we are properly attached.  */

You are totally correct. I have installed the attached patch.

Thanks,

Mark

[-- Attachment #2: 0001-stack-Fix-error-message-when-dwfl_core_file_attach-f.patch --]
[-- Type: text/x-patch, Size: 1241 bytes --]

From ac9e5349dd662289485e67403be943a4ec78cd4d Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Tue, 25 Jun 2019 00:21:42 +0200
Subject: [PATCH] stack: Fix error message when dwfl_core_file_attach fails.

Reported-by: Mao Han <han_mao@c-sky.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog | 4 ++++
 src/stack.c   | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 2cde63c..c78e6fa 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2019-06-25  Mark Wielaard  <mark@klomp.org>
+
+	* stack.c (parse_opt): Fix dwfl_core_file_attach error message.
+
 2019-06-18  Mark Wielaard  <mark@klomp.org>
 
 	* strip.c (handle_elf): Use elf_begin ELF_C_WRITE, instead of
diff --git a/src/stack.c b/src/stack.c
index c5f347e..4daabce 100644
--- a/src/stack.c
+++ b/src/stack.c
@@ -608,7 +608,7 @@ parse_opt (int key, char *arg __attribute__ ((unused)),
       if (core != NULL)
 	{
 	  if (dwfl_core_file_attach (dwfl, core) < 0)
-	    error (EXIT_BAD, 0, "dwfl_core_file_report: %s", dwfl_errmsg (-1));
+	    error (EXIT_BAD, 0, "dwfl_core_file_attach: %s", dwfl_errmsg (-1));
 	}
 
       /* Makes sure we are properly attached.  */
-- 
1.8.3.1


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

* Re: [PATCH V2 0/2] Add C-SKY support
  2019-06-24 22:26     ` Mark Wielaard
@ 2019-06-26  7:21       ` Mao Han
  0 siblings, 0 replies; 10+ messages in thread
From: Mao Han @ 2019-06-26  7:21 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

On Tue, Jun 25, 2019 at 12:26:55AM +0200, Mark Wielaard wrote:
> Hi,
> 
> On Wed, 2019-04-17 at 14:41 +0800, Mao Han wrote:
> > I'v just spent sometime debuging this. Core dump backtrace on C-SKY
> > seems
> > can't be supported with current generic routine. DWARF register order is
> > different from the order in core notes. The initialization of frame
> > registers is totally incorrect. As the comment says some fix with
> > private function is needed.
> 
> My apologies for taking so long to reply. I am looking at your latest
> patch and found this discussion. It will take me a bit to properly
> review everything. But I didn't forget.
Thanks for remembering that and the careful review, looking forward to
seeing the review comments :).

Best Regards,
Mao Han

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

end of thread, other threads:[~2019-06-26  7:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-10  7:59 [PATCH V2 0/2] Add C-SKY support Mao Han
2019-04-10  8:00 ` [PATCH V2 2/2] Add backend support for C-SKY Mao Han
2019-04-15 11:09   ` Mark Wielaard
2019-04-16  7:14     ` Mao Han
2019-04-10  8:00 ` [PATCH V2 1/2] libelf: Sync elf.h from glibc Mao Han
2019-04-14 20:32   ` Mark Wielaard
2019-04-14 20:23 ` [PATCH V2 0/2] Add C-SKY support Mark Wielaard
2019-04-17  6:45   ` Mao Han
2019-06-24 22:26     ` Mark Wielaard
2019-06-26  7:21       ` Mao Han

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