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

[Minios-devel] [UNIKRAFT/LIBCXX PATCH 2/2] Initial port of libcxx to Unikraft



This is our initial port of compiler-rt to Unikraft as external
library. Libc is requiered 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                                     |  14 ++
 Makefile.uk                                   | 139 ++++++++++++++++++
 glue.c                                        |  19 +++
 include/cmath                                 |   2 +
 include/math.h                                |  59 ++++++++
 include/nl_types.h                            |  30 ++++
 include/stdlib.h                              |  10 ++
 ...-from-long-double-function-to-double.patch |  40 +++++
 ...default-config-to-work-with-Unikraft.patch |  40 +++++
 9 files changed, 353 insertions(+)
 create mode 100644 Config.uk
 create mode 100644 Makefile.uk
 create mode 100644 glue.c
 create mode 100644 include/cmath
 create mode 100644 include/math.h
 create mode 100644 include/nl_types.h
 create mode 100644 include/stdlib.h
 create mode 100644 
patches/0001-Change-from-long-double-function-to-double.patch
 create mode 100644 
patches/0001-Update-default-config-to-work-with-Unikraft.patch

diff --git a/Config.uk b/Config.uk
new file mode 100644
index 0000000..712ba96
--- /dev/null
+++ b/Config.uk
@@ -0,0 +1,14 @@
+menuconfig LIBCXX
+    bool "libcxx - C++ standard library"
+       select LIBNOLIBC if !HAVE_LIBC
+       select LIBCXXABI
+       select LIBUNWIND
+    default n
+
+if LIBCXX
+
+config CXX_THREADS
+    bool "Enable CXX threads support"
+    default n
+
+endif
diff --git a/Makefile.uk b/Makefile.uk
new file mode 100644
index 0000000..b384d2c
--- /dev/null
+++ b/Makefile.uk
@@ -0,0 +1,139 @@
+#  libcxx Makefile.uk
+#
+#  Authors: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
+#
+#  Copyright (c) 2019, NEC Europe Ltd., NEC Corporation. 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,libcxx,$(CONFIG_LIBCXX)))
+
+################################################################################
+# Sources
+################################################################################
+LIBCXX_VERSION=7.0.0
+LIBCXX_URL=http://releases.llvm.org/7.0.0/libcxx-7.0.0.src.tar.xz
+LIBCXX_PATCHDIR=$(LIBCXX_BASE)/patches
+$(eval $(call fetch,libcxx,$(LIBCXX_URL)))
+$(eval $(call patch,libcxx,$(LIBCXX_PATCHDIR),libcxx-$(LIBCXX_VERSION).src))
+
+################################################################################
+# Helpers
+################################################################################
+LIBCXX_SUBDIR=libcxx-$(LIBCXX_VERSION).src
+LIBCXX_SRC = $(LIBCXX_ORIGIN)/$(LIBCXX_SUBDIR)
+
+################################################################################
+# Library includes
+################################################################################
+CXXINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_BASE)/include
+CINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_BASE)/include
+
+CINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/src
+CINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/fuzzing
+CINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/cal
+CINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/func
+CINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/tuple
+CINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/allocator
+CINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/lib
+CINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/auto
+CINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/string
+CINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/number
+CINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/types
+CINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/func
+CINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/include
+CINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/utils
+CXXINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/src
+CXXINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/fuzzing
+CXXINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/cal
+CXXINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/func
+CXXINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/tuple
+CXXINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/allocator
+CXXINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/lib
+CXXINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/auto
+CXXINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/string
+CXXINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/number
+CXXINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/types
+CXXINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/func
+CXXINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/include
+CXXINCLUDES-$(CONFIG_LIBCXX) += -I$(LIBCXX_SRC)/utils
+
+################################################################################
+# Global flags
+################################################################################
+CONFIG_FLAGS   += -D _LIBCPP_BUILDING_LIBRARY  -D LIBCXX_BUILDING_LIBCXXABI -D 
_LIBCPPABI_VERSION -D __x86_64__ -D _LIBCPP_STD_VER=15 -D 
_LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
+
+ifdef CONFIG_CXX_THREADS
+CONFIG_FLAGS   +=      -D __linux__ -D _LIBCPP_HAS_THREAD_API_PTHREAD -D 
CLOCK_MONOTONIC
+else
+CONFIG_FLAGS   +=      -D _LIBCPP_HAS_NO_THREADS -D 
_LIBCPP_HAS_NO_MONOTONIC_CLOCK
+endif
+
+LIBCXX_CFLAGS-y    +=   $(CONFIG_FLAGS)
+LIBCXX_CXXFLAGS-y    +=   $(CONFIG_FLAGS)
+
+LIBCXX_SRCS-y += $(LIBCXX_BASE)/glue.c
+################################################################################
+# Library sources
+################################################################################
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/valarray.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/algorithm.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/regex.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/ios.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/system_error.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/typeinfo.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/iostream.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/string.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/locale.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/stdexcept.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/optional.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/strstream.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/memory.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/chrono.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/random.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/variant.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/experimental/memory_resource.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/utility.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/charconv.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/vector.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/bind.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/new.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/thread.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/any.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/shared_mutex.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/functional.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/future.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/exception.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/mutex.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/condition_variable.cpp
+LIBCXX_SRCS-y += $(LIBCXX_SRC)/src/hash.cpp
diff --git a/glue.c b/glue.c
new file mode 100644
index 0000000..f5ec86a
--- /dev/null
+++ b/glue.c
@@ -0,0 +1,19 @@
+#include <nl_types.h>
+
+int catclose(nl_catd catalog)
+{
+        return 0;
+}
+
+nl_catd catopen(const char *name, int flag)
+{
+        return 0;
+}
+
+char *catgets(nl_catd catalog, int set_number, int message_number,
+                     const char *message)
+{
+        return 0;
+}
+
+void* __dso_handle = (void*) &__dso_handle;
diff --git a/include/cmath b/include/cmath
new file mode 100644
index 0000000..569dabc
--- /dev/null
+++ b/include/cmath
@@ -0,0 +1,2 @@
+#include <math.h>
+#include_next <cmath>
diff --git a/include/math.h b/include/math.h
new file mode 100644
index 0000000..e300379
--- /dev/null
+++ b/include/math.h
@@ -0,0 +1,59 @@
+extern long double atanl(long double);
+extern long double cosl (long double);
+extern long double sinl(long double);
+extern long double tanl(long double);
+extern long double tanhl(long double);
+extern long double frexpl(long double, int *);
+extern long double modfl(long double, long double *);
+extern long double ceill(long double);
+extern long double fabsl(long double); 
+extern long double floorl(long double);
+extern long double log1pl(long double);
+extern long double expm1l(long double);
+extern long double acosl(long double);
+extern long double asinl(long double);
+extern long double atan2l(long double, long double);
+extern long double coshl(long double);
+extern long double sinhl(long double);
+extern long double expl(long double);
+extern long double ldexpl(long double, int);
+extern long double logl(long double);
+extern long double log10l(long double);
+extern long double powl(long double, long double);
+extern long double fmodl(long double, long double);
+extern long double copysignl(long double, long double);
+extern long double nanl(const char *);
+extern int ilogbl(long double);
+extern long double asinhl(long double);
+extern long double cbrtl(long double);
+extern long double nextafterl(long double, long double);
+extern float nexttowardf(float, long double);
+extern double nexttoward(double, long double);
+extern long double nexttowardl(long double, long double);
+extern long double logbl(long double);
+extern long double log2l(long double);
+extern long double rintl(long double);
+extern long double scalbnl(long double, int);
+extern long double exp2l(long double);
+extern long double scalblnl(long double, long);
+extern long double tgammal(long double);
+extern long double nearbyintl(long double);
+extern long int lrintl(long double);
+extern long long int llrintl(long double);
+extern long double roundl(long double);
+extern long lroundl(long double);
+extern long long int llroundl(long double);
+extern long double truncl(long double);
+extern long double remquol(long double, long double, int *);
+extern long double fdiml(long double, long double);
+extern long double fmaxl(long double, long double);
+extern long double fminl(long double, long double);
+extern long double fmal(long double, long double, long double);
+extern long double acoshl(long double);
+extern long double atanhl(long double);
+extern long double remainderl(long double, long double);
+extern long double lgammal(long double);
+extern long double erfl(long double);
+extern long double erfcl(long double);
+
+#include_next <math.h>
diff --git a/include/nl_types.h b/include/nl_types.h
new file mode 100644
index 0000000..4f57f40
--- /dev/null
+++ b/include/nl_types.h
@@ -0,0 +1,30 @@
+// -*- C++ -*-
+//===-------------------- support/android/wchar_support.c 
------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _NL_TYPES_H
+#define _NL_TYPES_H 1
+
+#define NL_SETD 1
+#define NL_CAT_LOCALE 1
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void* nl_catd;
+typedef int nl_item;
+nl_catd  catopen(const char*, int);
+char*    catgets(nl_catd, int, int, const char*);
+int      catclose(nl_catd);
+
+#ifdef __cplusplus
+}  // extern "C"
+#endif
+
+#endif /* nl_types.h  */
diff --git a/include/stdlib.h b/include/stdlib.h
new file mode 100644
index 0000000..b5e21ff
--- /dev/null
+++ b/include/stdlib.h
@@ -0,0 +1,10 @@
+#include <xlocale.h>
+//extern long double strtold (const char*, char**);
+//extern long double strtold(char const*, char**);
+extern long double strtold (const char *__restrict, char **__restrict);
+extern long double strtold_l (const char *__restrict, char **__restrict,
+                                                 locale_t);
+
+#include_next <stdlib.h>
+
+
diff --git a/patches/0001-Change-from-long-double-function-to-double.patch 
b/patches/0001-Change-from-long-double-function-to-double.patch
new file mode 100644
index 0000000..5420f04
--- /dev/null
+++ b/patches/0001-Change-from-long-double-function-to-double.patch
@@ -0,0 +1,40 @@
+From d8d29b3dc00ff53e4813533a4154ce7249c4d415 Mon Sep 17 00:00:00 2001
+From: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
+Date: Thu, 28 Mar 2019 18:57:17 +0200
+Subject: [PATCH 1/1] Change from long double function to double
+
+Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
+---
+ include/locale | 2 +-
+ src/string.cpp | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/include/locale b/include/locale
+index e240799..f7a3f09 100644
+--- a/include/locale
++++ b/include/locale
+@@ -817,7 +817,7 @@ double __do_strtod<double>(const char* __a, char** __p2) {
+ template <>
+ inline _LIBCPP_INLINE_VISIBILITY
+ long double __do_strtod<long double>(const char* __a, char** __p2) {
+-    return strtold_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
++    return strtod_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
+ }
+ 
+ template <class _Tp>
+diff --git a/src/string.cpp b/src/string.cpp
+index d7ebdd3..9e7a85c 100644
+--- a/src/string.cpp
++++ b/src/string.cpp
+@@ -217,7 +217,7 @@ inline
+ long double
+ as_float( const string& func, const string& s, size_t* idx )
+ {
+-    return as_float_helper<long double>( func, s, idx, strtold );
++    return as_float_helper<long double>( func, s, idx, strtod );
+ }
+ 
+ template<>
+-- 
+2.20.1
+
diff --git a/patches/0001-Update-default-config-to-work-with-Unikraft.patch 
b/patches/0001-Update-default-config-to-work-with-Unikraft.patch
new file mode 100644
index 0000000..ef6e30d
--- /dev/null
+++ b/patches/0001-Update-default-config-to-work-with-Unikraft.patch
@@ -0,0 +1,40 @@
+From fc82b5790a71200eff14098b3eb937f7196834e2 Mon Sep 17 00:00:00 2001
+From: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
+Date: Thu, 28 Mar 2019 16:15:25 +0200
+Subject: [PATCH 1/1] Update default config to work with Unikraft
+
+Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
+---
+ include/__config | 16 ++++++++++++++++
+ 1 file changed, 16 insertions(+)
+
+diff --git a/include/__config b/include/__config
+index 738d891..df61ab1 100644
+--- a/include/__config
++++ b/include/__config
+@@ -23,6 +23,22 @@
+ 
+ #ifdef __cplusplus
+ 
++#include <uk/config.h>
++
++#ifdef CONFIG_CXX_THREADS
++#if !defined(__linux__)
++#define __linux__
++#endif
++#else
++#if !defined(_LIBCPP_HAS_NO_THREADS)
++#define _LIBCPP_HAS_NO_THREADS
++#endif
++#endif
++
++#if !defined(_LIBCPP_BUILDING_LIBRARY)
++#define _LIBCPP_BUILDING_LIBRARY
++#endif
++
+ #ifdef __GNUC__
+ #  define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
+ // The _GNUC_VER_NEW macro better represents the new GCC versioning scheme
+-- 
+2.20.1
+
-- 
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®.