From e4eefcbab46a9bfd8082fdc5159c5af7af6a4ae3 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Tue, 8 Jun 2021 23:23:31 +0200 Subject: [PATCH] Build support for s390x: libunwind (#53286) * Merge https://github.com/libunwind/libunwind/pull/245 * Add s390x support to local CMake files --- src/coreclr/pal/src/libunwind/CMakeLists.txt | 6 +++ .../include/tdep-s390x/libunwind_i.h | 14 +++---- .../src/libunwind/include/tdep/dwarf-config.h | 2 + .../pal/src/libunwind/libunwind-version.txt | 1 + .../pal/src/libunwind/src/CMakeLists.txt | 37 +++++++++++++++++++ .../pal/src/libunwind/src/s390x/Gresume.c | 4 +- 6 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/coreclr/pal/src/libunwind/CMakeLists.txt b/src/coreclr/pal/src/libunwind/CMakeLists.txt index 44e9bc6c35e..6e31eae9f71 100644 --- a/src/coreclr/pal/src/libunwind/CMakeLists.txt +++ b/src/coreclr/pal/src/libunwind/CMakeLists.txt @@ -28,6 +28,8 @@ if(CLR_CMAKE_HOST_UNIX) set(arch arm) elseif(CLR_CMAKE_HOST_ARCH_I386) set(arch x86) + elseif(CLR_CMAKE_HOST_ARCH_S390X) + set(arch s390x) endif () # Disable warning due to incorrect format specifier in debugging printf via the Debug macro @@ -105,6 +107,10 @@ if(CLR_CMAKE_HOST_WIN32) set(TARGET_ARM 1) set(arch arm) add_definitions(-D__arm__) + elseif(CLR_CMAKE_TARGET_ARCH_S390X) + set(TARGET_S390X 1) + set(arch s390x) + add_definitions(-D__s390x__) else () message(FATAL_ERROR "Unrecognized TARGET") endif () diff --git a/src/coreclr/pal/src/libunwind/include/tdep-s390x/libunwind_i.h b/src/coreclr/pal/src/libunwind/include/tdep-s390x/libunwind_i.h index 8c34d6a9584..ba75c0742f6 100644 --- a/src/coreclr/pal/src/libunwind/include/tdep-s390x/libunwind_i.h +++ b/src/coreclr/pal/src/libunwind/include/tdep-s390x/libunwind_i.h @@ -164,16 +164,16 @@ dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val) if (DWARF_IS_NULL_LOC (loc)) return -UNW_EBADREG; + /* GPRs may be saved in FPRs */ + if (DWARF_IS_FP_LOC (loc)) + return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc), (unw_fpreg_t*)val, + 0, c->as_arg); if (DWARF_IS_REG_LOC (loc)) return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val, 0, c->as_arg); if (DWARF_IS_MEM_LOC (loc)) return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val, 0, c->as_arg); - /* GPRs may be saved in FPRs */ - if (DWARF_IS_FP_LOC (loc)) - return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc), (unw_fpreg_t*)val, - 0, c->as_arg); assert(DWARF_IS_VAL_LOC (loc)); *val = DWARF_GET_LOC (loc); return 0; @@ -188,13 +188,13 @@ dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val) if (DWARF_IS_NULL_LOC (loc)) return -UNW_EBADREG; - if (DWARF_IS_REG_LOC (loc)) - return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val, - 1, c->as_arg); /* GPRs may be saved in FPRs */ if (DWARF_IS_FP_LOC (loc)) return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc), (unw_fpreg_t*) &val, 1, c->as_arg); + if (DWARF_IS_REG_LOC (loc)) + return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val, + 1, c->as_arg); assert(DWARF_IS_MEM_LOC (loc)); return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val, diff --git a/src/coreclr/pal/src/libunwind/include/tdep/dwarf-config.h b/src/coreclr/pal/src/libunwind/include/tdep/dwarf-config.h index c759a46c63b..e27e2a23690 100644 --- a/src/coreclr/pal/src/libunwind/include/tdep/dwarf-config.h +++ b/src/coreclr/pal/src/libunwind/include/tdep/dwarf-config.h @@ -15,6 +15,8 @@ # include "tdep-ppc32/dwarf-config.h" #elif defined __powerpc64__ # include "tdep-ppc64/dwarf-config.h" +#elif defined __s390x__ +# include "tdep-s390x/dwarf-config.h" #elif defined __sh__ # include "tdep-sh/dwarf-config.h" #elif defined __i386__ diff --git a/src/coreclr/pal/src/libunwind/libunwind-version.txt b/src/coreclr/pal/src/libunwind/libunwind-version.txt index 9ebc86f5b15..566086b14ae 100644 --- a/src/coreclr/pal/src/libunwind/libunwind-version.txt +++ b/src/coreclr/pal/src/libunwind/libunwind-version.txt @@ -4,3 +4,4 @@ https://github.com/libunwind/libunwind/commit/9165d2a150d707d3037c2045f2cdc0fabd Remove upstream CMakelist.txt & src/CMakelist.txt, keep .NET Core custom version Keep .NET Core oop directory Apply https://github.com/libunwind/libunwind/pull/186 +Apply https://github.com/libunwind/libunwind/pull/245 diff --git a/src/coreclr/pal/src/libunwind/src/CMakeLists.txt b/src/coreclr/pal/src/libunwind/src/CMakeLists.txt index 56420c1558f..b6dee4f413a 100644 --- a/src/coreclr/pal/src/libunwind/src/CMakeLists.txt +++ b/src/coreclr/pal/src/libunwind/src/CMakeLists.txt @@ -276,6 +276,35 @@ SET(libunwind_x86_64_la_SOURCES_x86_64 x86_64/Gstash_frame.c x86_64/Gstep.c x86_64/Gtrace.c ) +# The list of files that go both into libunwind and libunwind-s390x: +SET(libunwind_la_SOURCES_s390x_common + ${libunwind_la_SOURCES_common} + s390x/is_fpreg.c s390x/regname.c +) + +# The list of files that go into libunwind: +SET(libunwind_la_SOURCES_s390x + ${libunwind_la_SOURCES_s390x_common} + ${libunwind_la_SOURCES_local} + s390x/setcontext.S s390x/getcontext.S + s390x/Lapply_reg_state.c s390x/Lreg_states_iterate.c + s390x/Lcreate_addr_space.c s390x/Lget_save_loc.c s390x/Lglobal.c + s390x/Linit.c s390x/Linit_local.c s390x/Linit_remote.c + s390x/Lget_proc_info.c s390x/Lregs.c s390x/Lresume.c + s390x/Lis_signal_frame.c s390x/Lstep.c +) + +# The list of files that go into libunwind-s390x: +SET(libunwind_s390x_la_SOURCES_s390x + ${libunwind_la_SOURCES_s390x_common} + ${libunwind_la_SOURCES_generic} + s390x/Gapply_reg_state.c s390x/Greg_states_iterate.c + s390x/Gcreate_addr_space.c s390x/Gget_save_loc.c s390x/Gglobal.c + s390x/Ginit.c s390x/Ginit_local.c s390x/Ginit_remote.c + s390x/Gget_proc_info.c s390x/Gregs.c s390x/Gresume.c + s390x/Gis_signal_frame.c s390x/Gstep.c +) + if(CLR_CMAKE_HOST_UNIX) if(CLR_CMAKE_HOST_ARCH_ARM64) SET(libunwind_la_SOURCES ${libunwind_la_SOURCES_aarch64}) @@ -297,6 +326,10 @@ if(CLR_CMAKE_HOST_UNIX) SET(libunwind_remote_la_SOURCES ${libunwind_x86_64_la_SOURCES_x86_64}) SET(libunwind_elf_la_SOURCES ${libunwind_elf64_la_SOURCES}) list(APPEND libunwind_setjmp_la_SOURCES x86_64/longjmp.S x86_64/siglongjmp.SA) + elseif(CLR_CMAKE_HOST_ARCH_S390X) + SET(libunwind_la_SOURCES ${libunwind_la_SOURCES_s390x}) + SET(libunwind_remote_la_SOURCES ${libunwind_s390x_la_SOURCES_s390x}) + SET(libunwind_elf_la_SOURCES ${libunwind_elf64_la_SOURCES}) endif() if(CLR_CMAKE_HOST_OSX) @@ -340,6 +373,10 @@ else(CLR_CMAKE_HOST_UNIX) SET(libunwind_remote_la_SOURCES ${libunwind_x86_64_la_SOURCES_x86_64}) SET(libunwind_elf_la_SOURCES ${libunwind_elf64_la_SOURCES}) list(APPEND libunwind_setjmp_la_SOURCES x86_64/longjmp.S x86_64/siglongjmp.SA) + elseif(CLR_CMAKE_TARGET_ARCH_S390X) + SET(libunwind_la_SOURCES ${libunwind_la_SOURCES_s390x}) + SET(libunwind_remote_la_SOURCES ${libunwind_s390x_la_SOURCES_s390x}) + SET(libunwind_elf_la_SOURCES ${libunwind_elf64_la_SOURCES}) endif() set_source_files_properties(${CLR_DIR}/pal/src/exception/remote-unwind.cpp PROPERTIES COMPILE_FLAGS /TP INCLUDE_DIRECTORIES ${CLR_DIR}/inc) diff --git a/src/coreclr/pal/src/libunwind/src/s390x/Gresume.c b/src/coreclr/pal/src/libunwind/src/s390x/Gresume.c index fd9d13027e2..bfc4d5cab4e 100644 --- a/src/coreclr/pal/src/libunwind/src/s390x/Gresume.c +++ b/src/coreclr/pal/src/libunwind/src/s390x/Gresume.c @@ -68,7 +68,7 @@ s390x_local_resume (unw_addr_space_t as, unw_cursor_t *cursor, void *arg) sp = c->sigcontext_sp; ip = c->sigcontext_pc; __asm__ __volatile__ ( - "lgr 15, %[sp]\n" + "lgr %%r15, %[sp]\n" "br %[ip]\n" : : [sp] "r" (sp), [ip] "r" (ip) ); @@ -86,7 +86,7 @@ s390x_local_resume (unw_addr_space_t as, unw_cursor_t *cursor, void *arg) sp = c->sigcontext_sp; ip = c->sigcontext_pc; __asm__ __volatile__ ( - "lgr 15, %[sp]\n" + "lgr %%r15, %[sp]\n" "br %[ip]\n" : : [sp] "r" (sp), [ip] "r" (ip) ); -- GitLab