[[RESEND & PING]PATCH V3 0/1] Add C-SKY support

2019-06-03 Thread Mao Han
CC: Mark Wielaard 

This patch add backend support for C-SKY architecture.

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

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

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

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

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

Tested on x86:

Testsuite summary for elfutils 0.176

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


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

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

.. contents:: :depth: 2

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

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

FAIL: run-native-test.sh


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

FAIL: run-dwarf-getmacros.sh


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

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

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

SKIP: run-backtrace-native-biarch.sh


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

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

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

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

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

FAIL: run-deleted.sh


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

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


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

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

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

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

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

copy_elf: /home/vmh/workspace/elfutils/libdw/libdw.so -> libdw.so.rev 
(read,reverse)
se

[[RESEND & PING]PATCH V3 1/1] Add backend support for C-SKY

2019-06-03 Thread 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 
---
 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 .  */
+
+#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 S

[COMMITTED] tests: elfcopy --reverse-offs should only swap sections next to each other.

2019-06-03 Thread Mark Wielaard
The run-reverse-sections-self.sh (which really should have been called
"swap-sections") could fail if the ELF file had sections that were not
directly next to each other swapped. Add a check to make sure the swapped
sections are actually directly next to each other.

Signed-off-by: Mark Wielaard 
---
 tests/ChangeLog | 5 +
 tests/elfcopy.c | 1 +
 2 files changed, 6 insertions(+)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index b4877db..e038793 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2019-06-03  Mark Wielaard  
+
+   * elfcopy.c (copy_elf): When swapping the sh_offsets of two sections,
+   make sure they are actually next to each other.
+
 2019-05-12  Mark Wielaard  
 
* Makefile.am (check_PROGRAMS): Add elfrdwrnop.
diff --git a/tests/elfcopy.c b/tests/elfcopy.c
index d457bad..454 100644
--- a/tests/elfcopy.c
+++ b/tests/elfcopy.c
@@ -225,6 +225,7 @@ copy_elf (const char *in, const char *out, bool use_mmap, 
bool reverse_offs)
  && shdr.sh_addralign == 1
  && last_shdr.sh_type != SHT_NOBITS
  && shdr.sh_type != SHT_NOBITS
+ && last_shdr.sh_offset + last_shdr.sh_size == shdr.sh_offset
  && (phnum == 0
  || ((shdr.sh_flags & SHF_ALLOC) == 0
  && (last_shdr.sh_flags & SHF_ALLOC) == 0)))
-- 
1.8.3.1