Skip to content

Commit

Permalink
Build support for s390x: libunwind (#53286)
Browse files Browse the repository at this point in the history
* Merge libunwind/libunwind#245

* Add s390x support to local CMake files
  • Loading branch information
uweigand authored Jun 8, 2021
1 parent 5d6278a commit e4eefcb
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 9 deletions.
6 changes: 6 additions & 0 deletions src/coreclr/pal/src/libunwind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ()
Expand Down
14 changes: 7 additions & 7 deletions src/coreclr/pal/src/libunwind/include/tdep-s390x/libunwind_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/pal/src/libunwind/include/tdep/dwarf-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/pal/src/libunwind/libunwind-version.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 37 additions & 0 deletions src/coreclr/pal/src/libunwind/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/pal/src/libunwind/src/s390x/Gresume.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand All @@ -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)
);
Expand Down

0 comments on commit e4eefcb

Please sign in to comment.