[PATCH 0/2] Add C-SKY support
it.sh PASS: run-attr-integrate-skel.sh PASS: run-all-dwarf-ranges.sh PASS: run-unit-info.sh PASS: run-reloc-bpf.sh PASS: run-next-cfi.sh PASS: run-next-cfi-self.sh PASS: run-copyadd-sections.sh PASS: run-copymany-sections.sh PASS: run-typeiter-many.sh PASS: run-strip-test-many.sh PASS: run-strip-version.sh PASS: msg_tst PASS: system-elf-libelf-test PASS: asm-tst1 PASS: asm-tst2 PASS: asm-tst3 PASS: asm-tst4 PASS: asm-tst5 PASS: asm-tst6 PASS: asm-tst7 PASS: asm-tst8 PASS: asm-tst9 PASS: run-disasm-bpf.sh Testsuite summary for elfutils 0.176 # TOTAL: 203 # PASS: 194 # SKIP: 5 # XFAIL: 0 # FAIL: 4 # XPASS: 0 # ERROR: 0 See tests/test-suite.log Please report to https://sourceware.org/bugzilla == elfutils 0.176: tests/test-suite.log == # TOTAL: 203 # PASS: 194 # 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-exprlocs-self.sh == /home/vmh/elfutilswk/tests/varlocs: dwarf_getlocation_attr for addr: .debug_addr section missing *** failure in /home/vmh/elfutilswk/tests/varlocs --exprlocs -e /home/vmh/elfutilswk/src/readelf FAIL run-exprlocs-self.sh (exit status: 1) FAIL: run-native-test.sh allregs: 23064: No such file or directory FAIL run-native-test.sh (exit status: 1) 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) SKIP: run-backtrace-data.sh === /home/vmh/elfutilswk/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.12362 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 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) 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 | 59 +++ backends/csky_corenote.c | 60 +++ backends/csky_init.c | 64 + backends/csky_initreg.c | 85 + backends/csky_regs.c | 121 +++ backends/csky_reloc.def | 85 + backends/csky_symbol.c | 76 + libebl/eblopenbackend.c | 1 + libelf/ChangeLog | 4 ++ libelf/elf.h | 96 - src/elflint.c| 2 +- 13 files changed, 670 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
[PATCH 2/2] Add backend support for C-SKY
--- backends/ChangeLog | 13 + backends/Makefile.am | 9 +++- backends/csky_cfi.c | 59 +++ backends/csky_corenote.c | 60 +++ backends/csky_init.c | 64 + backends/csky_initreg.c | 85 + backends/csky_regs.c | 121 +++ backends/csky_reloc.def | 85 + backends/csky_symbol.c | 76 + libebl/eblopenbackend.c | 1 + src/elflint.c| 2 +- 11 files changed, 572 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 + + * 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 * 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 000..5c30a5f --- /dev/null +++ b/backends/csky_cfi.c @@ -0,0 +1,59 @@ +/* C-SKY ABI-specified defaults for DWARF CFI. + 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 +#endif + +#include + +#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. */ + + re
[PATCH 1/2] libelf: Sync elf.h from glibc
--- 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 + + * elf.h: Update from glibc. + 2019-03-07 Mark Wielaard * 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_CSKY252 /* 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_VMCOREDD0x700 /* Vmcore Device Dump Note. */ +#define NT_MIPS_DSP0x800 /* MIPS DSP ASE registers. */ +#define NT_MIPS_FP_MODE0x801 /* MIPS floating-point mode. */ /* Legal values for the note segment descriptor types for object files. */ @@ -1214,6 +1218,9 @@ typedef struct #define AT_L3_CACHESIZE46 #define AT_L3_CACHEGEOMETRY47 +#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_PCREL325 /* 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_ADDRGOT17 /* GOT entry in GLOB_DAT (GOT + G) */ +#define R_CKCORE_ADDRPLT18 /* PLT entry in GLOB_DAT (GOT + G) */ +#define R_CKCORE_PCREL_IMM26BY2 19 /* ((S + A - P) >> 1) & 0x3ff */ +#define R_CKCORE_PCREL_IMM16BY2 20 /* disp ((S + A - P) >> 1) & 0x */ +#define R_CKCORE_PCREL_IMM16BY4 21 /* disp ((S + A - P) >> 2) & 0x */ +#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) & 0x */ +#define R_CKCORE_ADDR_LO16 25 /* (S + A) & 0x */ +#define R_CKCORE_GOTPC_HI16 26 /* high & low 16 bit GOTPC */ +/* ((GOT + A - P) >> 16) & 0x */ +#define R_CKCORE_GOTPC_LO16 27 /* (GOT + A - P) & 0x */ +#define R_CKCORE_GOTOFF_HI1628 /* high & low 16 bit GOTOFF */ +/* ((S + A - GOT) >> 16) & 0x */ +#define R_CKCORE_GOTOFF_LO1629 /* (S + A - GOT) & 0x */ +#define R_CKCORE_GOT12 30 /* 12 bit disp GOT entry (G) */ +#define R_CKCORE_GOT_HI16 31 /* high & low 16 bit GOT */ +/* (G >> 16) & 0x */ +#define R_CKCORE_GOT_LO16 32 /* (G & 0x) */ +#define R_CKCORE_PLT12 33 /* 12 bit disp PLT entry (G) */ +#define R_CKCORE_PLT_HI16 34 /* high & low 16 bit PLT */ +
Re: [PATCH 0/2] Add C-SKY support
Hi, On Wed, Apr 03, 2019 at 10:54:11PM +0200, Mark Wielaard wrote: > Hi, > > On Mon, Apr 01, 2019 at 10:31:55AM +0800, Mao Han wrote: > > This patch add backend support for C-SKY architecture. > > Thanks. I don't know anything about the C-SKY architecture. Do you > have an URL to the ELF/DWARF supplemental spec that describes the ELF > structures and DWARF register numbers C-SKY uses? It would be good to > have that in the commit message and/or in a comment in the backend. ELF structures can be found inside the ABI manual. CSKY V2 ABI manual: https://github.com/c-sky/csky-doc/blob/master/C-SKY_V2_CPU_Applications_Binary_I +nterface_Standards_Manual.pdf CSKY architecture user guide: https://github.com/c-sky/csky-doc/blob/master/CSKY%20Architecture%20user_guide.p +df The DWARF part of the document is out of date. GCC source code can be used as reference: const int csky_dbx_regno[FIRST_PSEUDO_REGISTER] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, -1, -1, 36, 37, 35, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, -1, -1, 72 }; The number in the array is the DWARF register numbers, the corresponding register can be found in the corresponding below. #define FIXED_REGISTERS \ /* r0r1r2r3r4r5r6r7 */ \ {0,0,0,0,0,0,0,0, \ /* r8r9r10 r11 r12 r13 r14 r15 */ \ 0,0,0,0,0,0,1,0, \ /* r16 r17 r18 r19 r20 r21 r22 r23 */ \ 0,0,0,0,0,0,0,0, \ /* r24 r25 r26 r27 r28 r29 r30 tls */ \ 0,0,1,1,1,1,1,1, \ /* reserve c hilo */ \ 1, 1,0,0, \ /* reserved */ \ 1,1,1,1,1,1,1,1, \ 1,1,1,1,1,1,1,1, \ /* vr0 vr1 vr2 vr3 vr4 vr5 vr6 vr7 */ \ 0,0,0,0,0,0,0,0, \ /* vr8 vr9 vr10 vr11 vr12 vr13 vr14 vr15 */ \ 0,0,0,0,0,0,0,0 , \ /* reserved */ \ 1,1, \ /* epc */ \ 1 \ } These code come from gcc/config/csky/csky.c and gcc/config/csky/csky.h: https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/csky/csky.c;h=e4ac93323c0 +287d8d3d8191d51260983490fcac1;hb=73c7feb34d49e52ca5b6c2342cda882a9b06a036 > In general please read the CONTRIBUTING file and add a Signed-off-by > line if you agree with and can contribute the patch under the > appropriate licenses. Please also add a copyright line to the new > files. > Ok, I'll add the Signed-off-by line and the copyright. > Does qemu support full system or user-mode only C-SKY? > Yes, we have support for both system-mode and user-mode. Our linux system is available at: https://gitlab.com/c-sky/buildroot Our linux ci enviroment: https://gitlab.com/c-sky/buildroot/-/jobs/187862406 > > FAIL: run-exprlocs-self.sh > > == > > > > /home/vmh/elfutilswk/tests/varlocs: dwarf_getlocation_attr for addr: > > +.debug_addr section missing > > *** failure in /home/vmh/elfutilswk/tests/varlocs --exprlocs -e > > +/home/vmh/elfutilswk/src/readelf > > FAIL run-exprlocs-self.sh (exit status: 1) > > This is somewhat surprising. Do you build with -gdwarf-5? If you > could make the /home/vmh/elfutilswk/src/readelf binary available > somewhere we could investigate what goes on. > The default compile option is dwarf 4. I'v upload the binary to https://github.com/c-sky/test-result/blob/master/elfutils/readelf As I used the non-upstream version gcc to do the test, the machine code is 39(EM_RCE) not 252(EM_CSKY). > > > > biarch testing disabled > > SKIP run-backtrace-native-core-biarch.sh (exit status: 77) > > 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. > Ok, I'll try if I can get a backtrace with C-SKY core file. Thanks, Mao Han
Re: [PATCH 0/2] Add C-SKY support
Hi, FIX NEWLINE IN LAST EMAIL On Wed, Apr 03, 2019 at 10:54:11PM +0200, Mark Wielaard wrote: > Hi, > > On Mon, Apr 01, 2019 at 10:31:55AM +0800, Mao Han wrote: > > This patch add backend support for C-SKY architecture. > > Thanks. I don't know anything about the C-SKY architecture. Do you > have an URL to the ELF/DWARF supplemental spec that describes the ELF > structures and DWARF register numbers C-SKY uses? It would be good to > have that in the commit message and/or in a comment in the backend. ELF structures can be found inside the ABI manual. CSKY V2 ABI manual: https://github.com/c-sky/csky-doc/blob/master/C-SKY_V2_CPU_Applications_Binary_Interface_Standards_Manual.pdf CSKY architecture user guide: https://github.com/c-sky/csky-doc/blob/master/CSKY%20Architecture%20user_guide.pdf The DWARF part of the document is out of date. GCC source code can be used as reference: const int csky_dbx_regno[FIRST_PSEUDO_REGISTER] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, -1, -1, 36, 37, 35, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, -1, -1, 72 }; The number in the array is the DWARF register numbers, the corresponding register can be found in the corresponding below. #define FIXED_REGISTERS \ /* r0r1r2r3r4r5r6r7 */ \ {0,0,0,0,0,0,0,0, \ /* r8r9r10 r11 r12 r13 r14 r15 */ \ 0,0,0,0,0,0,1,0, \ /* r16 r17 r18 r19 r20 r21 r22 r23 */ \ 0,0,0,0,0,0,0,0, \ /* r24 r25 r26 r27 r28 r29 r30 tls */ \ 0,0,1,1,1,1,1,1, \ /* reserve c hilo */ \ 1, 1,0,0, \ /* reserved */ \ 1,1,1,1,1,1,1,1, \ 1,1,1,1,1,1,1,1, \ /* vr0 vr1 vr2 vr3 vr4 vr5 vr6 vr7 */ \ 0,0,0,0,0,0,0,0, \ /* vr8 vr9 vr10 vr11 vr12 vr13 vr14 vr15 */ \ 0,0,0,0,0,0,0,0 , \ /* reserved */ \ 1,1, \ /* epc */ \ 1 \ } These code come from gcc/config/csky/csky.c and gcc/config/csky/csky.h: https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/csky/csky.c;h=e4ac93323c0287d8d3d8191d51260983490fcac1;hb=73c7feb34d49e52ca5b6c2342cda882a9b06a036 > In general please read the CONTRIBUTING file and add a Signed-off-by > line if you agree with and can contribute the patch under the > appropriate licenses. Please also add a copyright line to the new > files. > Ok, I'll add the Signed-off-by line and the copyright. > Does qemu support full system or user-mode only C-SKY? > Yes, we have support for both system-mode and user-mode. Our linux system is available at: https://gitlab.com/c-sky/buildroot Our linux ci enviroment: https://gitlab.com/c-sky/buildroot/-/jobs/187862406 > > FAIL: run-exprlocs-self.sh > > == > > > > /home/vmh/elfutilswk/tests/varlocs: dwarf_getlocation_attr for addr: > > .debug_addr section missing > > *** failure in /home/vmh/elfutilswk/tests/varlocs --exprlocs -e > > /home/vmh/elfutilswk/src/readelf > > FAIL run-exprlocs-self.sh (exit status: 1) > > This is somewhat surprising. Do you build with -gdwarf-5? If you > could make the /home/vmh/elfutilswk/src/readelf binary available > somewhere we could investigate what goes on. > The default compile option is dwarf 4. I'v upload the binary to https://github.com/c-sky/test-result/blob/master/elfutils/readelf As I used the non-upstream version gcc to do the test, the machine code is 39(EM_RCE) not 252(EM_CSKY). > > > > biarch testing disabled > > SKIP run-backtrace-native-core-biarch.sh (exit status: 77) > > 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. > Ok, I'll try if I can get a backtrace with C-SKY core file. Thanks, Mao Han
[PATCH V2 2/2] Add backend support for C-SKY
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 --- 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 + + * 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 * 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 000..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 +#endif + +#include + +#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
[PATCH V2 0/2] Add C-SKY support
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
[PATCH V2 1/2] libelf: Sync elf.h from glibc
Signed-off-by: Mao Han --- 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 + + * elf.h: Update from glibc. + 2019-03-07 Mark Wielaard * 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_CSKY252 /* 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_VMCOREDD0x700 /* Vmcore Device Dump Note. */ +#define NT_MIPS_DSP0x800 /* MIPS DSP ASE registers. */ +#define NT_MIPS_FP_MODE0x801 /* MIPS floating-point mode. */ /* Legal values for the note segment descriptor types for object files. */ @@ -1214,6 +1218,9 @@ typedef struct #define AT_L3_CACHESIZE46 #define AT_L3_CACHEGEOMETRY47 +#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_PCREL325 /* 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_ADDRGOT17 /* GOT entry in GLOB_DAT (GOT + G) */ +#define R_CKCORE_ADDRPLT18 /* PLT entry in GLOB_DAT (GOT + G) */ +#define R_CKCORE_PCREL_IMM26BY2 19 /* ((S + A - P) >> 1) & 0x3ff */ +#define R_CKCORE_PCREL_IMM16BY2 20 /* disp ((S + A - P) >> 1) & 0x */ +#define R_CKCORE_PCREL_IMM16BY4 21 /* disp ((S + A - P) >> 2) & 0x */ +#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) & 0x */ +#define R_CKCORE_ADDR_LO16 25 /* (S + A) & 0x */ +#define R_CKCORE_GOTPC_HI16 26 /* high & low 16 bit GOTPC */ +/* ((GOT + A - P) >> 16) & 0x */ +#define R_CKCORE_GOTPC_LO16 27 /* (GOT + A - P) & 0x */ +#define R_CKCORE_GOTOFF_HI1628 /* high & low 16 bit GOTOFF */ +/* ((S + A - GOT) >> 16) & 0x */ +#define R_CKCORE_GOTOFF_LO1629 /* (S + A - GOT) & 0x */ +#define R_CKCORE_GOT12 30 /* 12 bit disp GOT entry (G) */ +#define R_CKCORE_GOT_HI16 31 /* high & low 16 bit GOT */ +/* (G >> 16) & 0x */ +#define R_CKCORE_GOT_LO16 32 /* (G & 0x) */ +#define R_CKCORE_PLT12 33 /* 12 bit disp PLT entry (G) */ +#define R_CKCORE_PLT_HI16 34 /* high
[PATCH] wrong backend definition?
--- backends/riscv_cfi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backends/riscv_cfi.c b/backends/riscv_cfi.c index 1a84a38..5d3e884 100644 --- a/backends/riscv_cfi.c +++ b/backends/riscv_cfi.c @@ -31,7 +31,7 @@ #include -#define BACKEND aarch64_ +#define BACKEND riscv_ #include "libebl_CPU.h" -- 2.7.4
Re: [PATCH V2 2/2] Add backend support for C-SKY
; + > > + return setfunc (0, 71, dwarf_regs, arg); > > +#endif > > +} > > I think you should use setfunc (-1, -1, ®s[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
Re: [PATCH V2 0/2] Add C-SKY support
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 0x00400ff3 main > #1 0x004011e4 generic_start_main > #2 0x00401461 __libc_start_main > #3 0x00400ef6 _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 0x00136bd2 eu-stack: dwfl_thread_getframes tid 140 at 0x136bd2 in : 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
[PATCH v3 1/1] Add backend support for C-SKY
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 --- 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 + + * 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 * 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 000..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 +#endif + +#include + +#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 +
[PATCH v3 0/1] Add C-SKY support
This patch add backend support for C-SKY architecture. 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
[[RESEND & PING]PATCH V3 0/1] Add C-SKY support
w.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
[[RESEND & PING]PATCH V3 1/1] Add backend support for C-SKY
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 --- 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 + + * 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 * 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 000..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 +#endif + +#include + +#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),
Re: [PATCH V2 0/2] Add C-SKY support
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
Re: [[RESEND & PING]PATCH V3 0/1] Add C-SKY support
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
Re: [[RESEND & PING]PATCH V3 1/1] Add backend support for C-SKY
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
Re: [[RESEND & PING]PATCH V3 0/1] Add C-SKY support
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
Re: [[RESEND & PING]PATCH V3 1/1] Add backend support for C-SKY
Hi Mark, I can't find the origin mail thread in my mailbox, as my mutt can only keep the newest 5000 mails. So I just reply in a new thread. > > 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. The ELF_ARCH was defined as 39 inside linux kernel(before 4.20), so the the core file generated was EM_RCE. I'v regenerated the core file with ELF_ARCH defined as 252: https://github.com/c-sky/test-result/blob/master/elfutils/zeroptr https://github.com/c-sky/test-result/raw/master/elfutils/core.zeroptr We have extended our core dump reg set last year, linux kernel have upstreamed this change, but the gdb does not. I'v only got an old released toolchain(EM_RCE) and the upstream toolchain(out of date reg set) in my enviroment, so I can't generate/verify EM_CSKY core file with any toolchain I have. > > 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. This case can pass with the newest elfutils. I believe it is fixed with commit d08c68. > 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 (GOTOFF,REL) > > +RELOC_TYPE (GOTPC, REL) > > +RELOC_TYPE (GOT32, REL) > > +RELOC_TYPE (PLT32, REL) > > +RELOC_TYPE (ADDRGOT, REL) > > +RELOC_TYPE (ADDRPLT, REL) > > v1 only? > > > R_CKCORE_GOTOFF_IMM18 is missing, but it is also missing in elf.h. > > > +RELOC_TYPE (GOT_IMM18BY4, REL) > > +RELOC_TYPE (PLT_IMM18BY4, REL) > > 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. The content of the ABI manual is quite old, binutils souce code seems much reliable to refer to. binutils/bfd/elf32-csky.c says, only three relocations are abiv1 exclusive: R_CKCORE_PCREL_JSR_IMM11BY2 R_CKCORE_PCREL_IMM8BY4 R_CKCORE_PCREL_IMM11BY2 The following relocations can occur in v2 ELF binaries. R_CKCORE_PCREL32 R_CKCORE_GOTOFF R_CKCORE_GOTPC R_CKCORE_GOT32 R_CKCORE_PLT32 R_CKCORE_ADDRGOT R_CKCORE_ADDRPLT R_CKCORE_GOTOFF_IMM18 seems unused at present. > 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
[PATCH V4 0/1] Add C-SKY support
ted > > descriptions. > > Some thing like: > > CSKY_ARCH_NAME: "ck810" > > CSKY_CPU_NAME: "ck810f" > > CSKY_ISA_FLAG: 0x12345678 > > CSKY_ISA_EXT_FLAG: 5 > > They are not documented yet. > > I'v ask the person who is responsible for these to update the ABI > > documents, but I think it will take a quite long time for them to > > do that. They are quite busy at present. > > OK. If you can add that tweak to src/readelf.c and add an > check_object_attribute hook that handles the above attributes that > would be good. > > Ideally you also add a testcase for tests/readelf-A.sh > Some of those tests cheat and create the attributes by hand. > But it would be nice if you could generate a small .o file with the > latest toolchain to be used as testcase in some other tests. I'm not sure about how to handle different data type here. It seems only tag_name is required when data type is string, I could not found how to handle int here. The binary with csky.attribute currently can not be generate with public released toolchain, so I don't know how to add the testcase. Tested on x86 Testsuite summary for elfutils 0.176 # TOTAL: 209 # PASS: 204 # SKIP: 5 # XFAIL: 0 # FAIL: 0 # XPASS: 0 # ERROR: 0 ============ 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 Changes since v3: - add testfilecsky.bz2 and hello_csky.ko.bz2 - add csky_check_object_attribute Mao Han (1): Add backend support for C-SKY backends/ChangeLog | 12 ++ backends/Makefile.am | 9 - backends/csky_attrs.c| 67 +++ 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 +- src/readelf.c| 4 +- tests/ChangeLog | 7 tests/hello_csky.ko.bz2 | Bin 0 -> 26448 bytes tests/run-addrcfi.sh | 43 tests/run-strip-reloc.sh | 3 +- tests/testfilecsky.bz2 | Bin 0 -> 3145 bytes 20 files changed, 688 insertions(+), 5 deletions(-) create mode 100644 backends/csky_attrs.c 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 create mode 100644 tests/hello_csky.ko.bz2 create mode 100644 tests/testfilecsky.bz2 -- 2.7.4
[PATCH V4 1/1] Add backend support for C-SKY
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 --- backends/ChangeLog | 12 ++ backends/Makefile.am | 9 - backends/csky_attrs.c| 67 +++ 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 +- src/readelf.c| 4 +- tests/ChangeLog | 7 tests/hello_csky.ko.bz2 | Bin 0 -> 26448 bytes tests/run-addrcfi.sh | 43 tests/run-strip-reloc.sh | 3 +- tests/testfilecsky.bz2 | Bin 0 -> 3145 bytes 20 files changed, 688 insertions(+), 5 deletions(-) create mode 100644 backends/csky_attrs.c 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 create mode 100644 tests/hello_csky.ko.bz2 create mode 100644 tests/testfilecsky.bz2 diff --git a/backends/ChangeLog b/backends/ChangeLog index af1a40e..f1eaf14 100644 --- a/backends/ChangeLog +++ b/backends/ChangeLog @@ -1,3 +1,15 @@ +2019-07-13 Mao Han + + * Makefile.am: Add C-SKY. + * csky_attrs.c: New file. + * csky_cfi.c: New file. + * csky_corenote.c: Likewise. + * csky_init.c: Likewise. + * csky_initreg.c: Likewise. + * csky_regs.c: Likewise. + * csky_reloc.def: Likewise. + * csky_symbol.c: Likewise. + 2019-06-28 Mark Wielaard * aarch64_init.c (aarch64_init.c): Remove eh->name; diff --git a/backends/Makefile.am b/backends/Makefile.am index 2126a2e..175468f 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_attrs.c csky_init.c csky_symbol.c csky_cfi.c \ + csky_regs.c csky_initreg.c csky_corenote.c +libebl_csky_pic_a_SOURCES = $(csky_SRCS) +am_libebl_csky_pic_a_OBJECTS = $(csky_SRCS:.c=.os) libebl_%.so libebl_%.map: libebl_%_pic.a $(libelf) $(libdw) $(libeu) @rm -f $(@:.so=.map) diff --git a/backends/csky_attrs.c b/backends/csky_attrs.c new file mode 100644 index 000..9b236f1 --- /dev/null +++ b/backends/csky_attrs.c @@ -0,0 +1,67 @@ +/* C-SKY ABI-specified defaults for DWARF CFI. + Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see <http:/
Re: [PATCH V4 0/1] Add C-SKY support
On Tue, Jul 16, 2019 at 03:48:22PM +0200, Mark Wielaard wrote: > > > > These attributes including cpu name and some other ISA related > > > > descriptions. > > > > Some thing like: > > > > CSKY_ARCH_NAME: "ck810" > > > > CSKY_CPU_NAME: "ck810f" > > > > CSKY_ISA_FLAG: 0x12345678 > > > > CSKY_ISA_EXT_FLAG: 5 > > > > They are not documented yet. > > > > I'v ask the person who is responsible for these to update the ABI > > > > documents, but I think it will take a quite long time for them to > > > > do that. They are quite busy at present. > > > > > > OK. If you can add that tweak to src/readelf.c and add an > > > check_object_attribute hook that handles the above attributes that > > > would be good. > > > > > > Ideally you also add a testcase for tests/readelf-A.sh > > > Some of those tests cheat and create the attributes by hand. > > > But it would be nice if you could generate a small .o file with the > > > latest toolchain to be used as testcase in some other tests. > > > > I'm not sure about how to handle different data type here. It seems > > only tag_name is required when data type is string, I could not > > found how to handle int here. > > The binary with csky.attribute currently can not be generate with > > public > > released toolchain, so I don't know how to add the testcase. > > OK, lets add a testcase once this has gone upstream in the rest of the > toolchain. Good point about the tag representing a string or number. > But I think this is (accidentially) handled correctly already. See this > comment in readelf.c (print_attributes): > >/* GNU style tags have either a uleb128 value, > when lowest bit is not set, or a string > when the lowest bit is set. > "compatibility" (32) is special. It has > both a string and a uleb128 value. For > non-gnu we assume 6 till 31 only take ints. > XXX see arm backend, do we need a separate > hook? */ > > We probably need another hook one day, but it looks like csky follows > this assumption (4 and 5 are strings, 6 and 7 are numbers). Yes, csky follows this assumption, so it is handled correctly already. > There is one bug in the implementation though. The vendor check is > wrong, checks for "gnu", should obviously be "csky": > > diff --git a/backends/csky_attrs.c b/backends/csky_attrs.c > index 9b236f1c..177f0ba2 100644 > --- a/backends/csky_attrs.c > +++ b/backends/csky_attrs.c > @@ -43,7 +43,7 @@ csky_check_object_attribute (Ebl *ebl __attribute__ > ((unused)), > const char **tag_name, > const char **value_name __attribute__ ((unused))) > { > - if (!strcmp (vendor, "gnu")) > + if (!strcmp (vendor, "csky")) > switch (tag) >{ >case 4: > > > Tested on x86 > > > > Testsuite summary for elfutils 0.176 > > > > # TOTAL: 209 > > # PASS: 204 > > # SKIP: 5 > > # XFAIL: 0 > > # FAIL: 0 > > # XPASS: 0 > > # ERROR: 0 > > > > > > 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 > > > > Changes since v3: > > - add testfilecsky.bz2 and hello_csky.ko.bz2 > > - add csky_check_object_attribute > > > > Mao Han (1): > > Add backend support for C-SKY > > The new patch looks really good. Thanks. The addition of the testcases > really helps showing things look good. I can make that one small fix > s/gnu/csky/ in csky_attrs.c if you agree that is what was intended. > Then I'll push it to master. Yes, please. Thanks for your review and help improveing the patch. > And after the next release we can add some more testcases and handle to > register mappings more correctly. OK. Thanks, Mao Han