[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT/LIBUNWIND v2 2/2] Initial port of Libunwind to Unikraft



This is our initial port of libunwind to Unikraft as external
library. Libc is required for it to work.

In the dependency list it should stay as follows:
...:$(UK_LIBS)/libunwind:$(UK_LIBS)/compiler-rt:
$(UK_LIBS)/libcxxabi:$(UK_LIBS)/libcxx:$(UK_LIBS)/newlib:...

Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
---
 Config.uk                          |  6 ++
 Makefile.uk                        | 95 ++++++++++++++++++++++++++++++
 exportsyms.uk                      | 33 +++++++++++
 patches/0001-Updated-the-RIP.patch | 37 ++++++++++++
 4 files changed, 171 insertions(+)
 create mode 100644 Config.uk
 create mode 100644 Makefile.uk
 create mode 100644 exportsyms.uk
 create mode 100644 patches/0001-Updated-the-RIP.patch

diff --git a/Config.uk b/Config.uk
new file mode 100644
index 0000000..9f78aee
--- /dev/null
+++ b/Config.uk
@@ -0,0 +1,6 @@
+menuconfig LIBUNWIND
+    bool "libunwind - unwinder"
+       select LIBNOLIBC if !HAVE_LIBC
+       select LIBCOMPILER_RT
+       depends on !PLAT_LINUXU
+    default n
diff --git a/Makefile.uk b/Makefile.uk
new file mode 100644
index 0000000..2753a6d
--- /dev/null
+++ b/Makefile.uk
@@ -0,0 +1,95 @@
+#  libunwind Makefile.uk
+#
+#  Authors: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
+#
+#  Copyright (c) 2019, Politehnica University of Bucharest. All rights 
reserved.
+#
+#  Redistribution and use in source and binary forms, with or without
+#  modification, are permitted provided that the following conditions
+#  are met:
+#
+#  1. Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+#  2. Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#  3. Neither the name of the copyright holder nor the names of its
+#     contributors may be used to endorse or promote products derived from
+#     this software without specific prior written permission.
+#
+#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+#  POSSIBILITY OF SUCH DAMAGE.
+#
+#  THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+#
+
+
+################################################################################
+# Library registration
+################################################################################
+$(eval $(call addlib_s,libunwind,$(CONFIG_LIBUNWIND)))
+
+ifeq ($(CONFIG_LIBUNWIND),y)
+ifneq ($(CONFIG_LIBCOMPILER_RT),y)
+$(error Require libcompiler_rt)
+endif
+ifeq ($(CONFIG_PLAT_LINUXU), y)
+$(error Libunwind not supported on Linuxu)
+endif
+endif
+
+################################################################################
+# Sources
+################################################################################
+LIBUNWIND_VERSION=7.0.0
+LIBUNWIND_URL=http://releases.llvm.org/$(LIBUNWIND_VERSION)/libunwind-$(LIBUNWIND_VERSION).src.tar.xz
+LIBUNWIND_PATCHDIR=$(LIBUNWIND_BASE)/patches
+$(eval $(call fetch,libunwind,$(LIBUNWIND_URL)))
+$(eval $(call 
patch,libunwind,$(LIBUNWIND_PATCHDIR),libunwind-$(LIBUNWIND_VERSION).src))
+
+################################################################################
+# Helpers
+################################################################################
+LIBUNWIND_SUBDIR=libunwind-$(LIBUNWIND_VERSION).src
+LIBUNWIND_SRC=$(LIBUNWIND_ORIGIN)/$(LIBUNWIND_SUBDIR)
+
+################################################################################
+# Library includes
+################################################################################
+CINCLUDES-$(CONFIG_LIBUNWIND) += -I$(LIBUNWIND_SRC)/src
+CINCLUDES-$(CONFIG_LIBUNWIND) += -I$(LIBUNWIND_SRC)/include
+CXXINCLUDES-$(CONFIG_LIBUNWIND) += -I$(LIBUNWIND_SRC)/src
+CXXINCLUDES-$(CONFIG_LIBUNWIND) += -I$(LIBUNWIND_SRC)/include
+
+CXXINCLUDES-$(CONFIG_LIBUNWIND) += -I$(LIBUNWIND_BASE)/include
+CINCLUDES-$(CONFIG_LIBUNWIND) += -I$(LIBUNWIND_BASE)/include
+
+################################################################################
+# Global flags
+################################################################################
+CONFIG_FLAGS   += -D _LIBUNWIND_HAS_NO_THREADS  -D __ELF__  -D 
_LIBUNWIND_IS_NATIVE_ONLY               \
+                                 -D _LIBUNWIND_SUPPORT_DWARF_UNWIND -D 
_LIBUNWIND_IS_BAREMETAL                                 \
+                                 -D _LIBUNWIND_BUILD_ZERO_COST_APIS -D 
_LIBUNWIND_TARGET_X86_64 -D __x86_64__  
+
+LIBUNWIND_CFLAGS-y      +=  $(CONFIG_FLAGS)
+LIBUNWIND_CXXFLAGS-y    +=  $(CONFIG_FLAGS)
+
+################################################################################
+# Library sources
+################################################################################
+LIBUNWIND_SRCS-y += $(LIBUNWIND_SRC)/src/UnwindLevel1.c
+LIBUNWIND_SRCS-y += $(LIBUNWIND_SRC)/src/Unwind-sjlj.c
+LIBUNWIND_SRCS-y += $(LIBUNWIND_SRC)/src/UnwindLevel1-gcc-ext.c
+LIBUNWIND_SRCS-y += $(LIBUNWIND_SRC)/src/libunwind.cpp
+LIBUNWIND_SRCS-y += $(LIBUNWIND_SRC)/src/Unwind-EHABI.cpp
+LIBUNWIND_SRCS-y += $(LIBUNWIND_SRC)/src/UnwindRegistersRestore.S
+LIBUNWIND_SRCS-y += $(LIBUNWIND_SRC)/src/UnwindRegistersSave.S
diff --git a/exportsyms.uk b/exportsyms.uk
new file mode 100644
index 0000000..1b7cf1e
--- /dev/null
+++ b/exportsyms.uk
@@ -0,0 +1,33 @@
+_Unwind_Backtrace
+_Unwind_DeleteException
+_Unwind_FindEnclosingFunction
+_Unwind_Find_FDE
+_Unwind_ForcedUnwind
+_Unwind_GetCFA
+_Unwind_GetDataRelBase
+_Unwind_GetGR
+_Unwind_GetIP
+_Unwind_GetIPInfo
+_Unwind_GetLanguageSpecificData
+_Unwind_GetRegionStart
+_Unwind_GetTextRelBase
+_Unwind_RaiseException
+_Unwind_Resume
+_Unwind_Resume_or_Rethrow
+_Unwind_SetGR
+_Unwind_SetIP
+unw_getcontext
+unw_get_fpreg
+unw_get_proc_info
+unw_get_proc_name
+unw_get_reg
+unw_init_local
+unw_is_fpreg
+unw_is_signal_frame
+unw_iterate_dwarf_unwind_cache
+unw_local_addr_space
+unw_regname
+unw_resume
+unw_set_fpreg
+unw_set_reg
+unw_step
diff --git a/patches/0001-Updated-the-RIP.patch 
b/patches/0001-Updated-the-RIP.patch
new file mode 100644
index 0000000..dcbdfcd
--- /dev/null
+++ b/patches/0001-Updated-the-RIP.patch
@@ -0,0 +1,37 @@
+From 863cddb4f2f89b51b38785f49b6c7cf3fc9e3f2c Mon Sep 17 00:00:00 2001
+From: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
+Date: Mon, 3 Dec 2018 18:59:59 +0200
+Subject: [PATCH] Updated the RIP
+
+This patch changes the RIP that is saved
+by the unw_getcontext function. Now the
+RIP is pointing to the throw that has
+triggered the exception.
+
+Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
+---
+ UnwindRegistersSave.S | 8 +++++++-
+ 1 file changed, 7 insertions(+), 1 deletion(-)
+
+diff --git a/UnwindRegistersSave.S b/UnwindRegistersSave.S
+index 07db14b..8223ea1 100644
+--- a/src/UnwindRegistersSave.S
++++ b/src/UnwindRegistersSave.S
+@@ -88,7 +88,13 @@ DEFINE_LIBUNWIND_FUNCTION(unw_getcontext)
+   movq  %r13,104(PTR)
+   movq  %r14,112(PTR)
+   movq  %r15,120(PTR)
+-  movq  (%rsp),TMP
++  push %rax 
++  movq %rbp, (%rax)
++  movq (%rax), %rax
++  addq $8, %rax
++  movq (%rax), %rax
++  movq  %rax, TMP
++  pop %rax 
+   movq  TMP,128(PTR) # store return address as rip
+   # skip rflags
+   # skip cs
+-- 
+2.19.2
+
-- 
2.20.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.