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

[Minios-devel] [UNIKRAFT/LIBCXX PATCH v4 2/3] 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>
---
 CODING_STYLE.md                               |   4 +
 CONTRIBUTING.md                               |   4 +
 Config.uk                                     |   6 +
 MAINTAINERS.md                                |  11 ++
 Makefile.uk                                   | 137 ++++++++++++++++++
 README.md                                     |   5 +
 glue.c                                        |  40 +++++
 include/__config_unikraft                     |  16 ++
 include/cmath                                 |   2 +
 include/math.h                                |  59 ++++++++
 include/nl_types.h                            |  30 ++++
 include/stdlib.h                              |  10 ++
 ...001-Update-the-default-configuration.patch |  26 ++++
 ...-from-long-double-function-to-double.patch |  40 +++++
 14 files changed, 390 insertions(+)
 create mode 100644 CODING_STYLE.md
 create mode 100644 CONTRIBUTING.md
 create mode 100644 Config.uk
 create mode 100644 MAINTAINERS.md
 create mode 100644 Makefile.uk
 create mode 100644 README.md
 create mode 100644 glue.c
 create mode 100644 include/__config_unikraft
 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-Update-the-default-configuration.patch
 create mode 100644 
patches/0002-Change-from-long-double-function-to-double.patch

diff --git a/CODING_STYLE.md b/CODING_STYLE.md
new file mode 100644
index 0000000..5730041
--- /dev/null
+++ b/CODING_STYLE.md
@@ -0,0 +1,4 @@
+Coding Style
+============
+
+Please refer to the `CODING_STYLE.md` file in the main Unikraft repository.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..5f55eca
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,4 @@
+Contributing to Unikraft
+=======================
+
+Please refer to the `CONTRIBUTING.md` file in the main Unikraft repository.
diff --git a/Config.uk b/Config.uk
new file mode 100644
index 0000000..9962669
--- /dev/null
+++ b/Config.uk
@@ -0,0 +1,6 @@
+menuconfig LIBCXX
+    bool "libcxx - C++ standard library"
+       select LIBNOLIBC if !HAVE_LIBC
+       select LIBCXXABI
+       select LIBUNWIND
+    default n
diff --git a/MAINTAINERS.md b/MAINTAINERS.md
new file mode 100644
index 0000000..ddcf3ca
--- /dev/null
+++ b/MAINTAINERS.md
@@ -0,0 +1,11 @@
+Maintainers List
+================
+
+For notes on how to read this information, please refer to `MAINTAINERS.md` in
+the main Unikraft repository.
+
+       LIBCXX-UNIKRAFT
+       M:      Felipe Huici <felipe.huici@xxxxxxxxx>
+       M:      Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
+       L:      minios-devel@xxxxxxxxxxxxx
+       F: *
diff --git a/Makefile.uk b/Makefile.uk
new file mode 100644
index 0000000..ddd39da
--- /dev/null
+++ b/Makefile.uk
@@ -0,0 +1,137 @@
+#  libcxx 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,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 -D __DYNAMIC_REENT__     
\
+
+
+
+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/README.md b/README.md
new file mode 100644
index 0000000..4fe4e92
--- /dev/null
+++ b/README.md
@@ -0,0 +1,5 @@
+libcxx for Unikraft
+===================
+
+Please refer to the `README.md` as well as the documentation in the `doc/`
+subdirectory of the main unikraft repository.
diff --git a/glue.c b/glue.c
new file mode 100644
index 0000000..b65464b
--- /dev/null
+++ b/glue.c
@@ -0,0 +1,40 @@
+/*
+ *      Unikraft port of C++ standard library.
+ *      Copyright(C) 2019 Vlad-Andrei Badoiu, University Politehnica
+ *      of Bucharest
+ *
+ *      This library is free software; you can redistribute it and/or
+ *      modify it under the terms of the GNU Lesser General Public
+ *      License as published by the Free Software Foundation; either
+ *      version 2 of the License, or (at your option) any later version.
+ *
+ *      This library 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
+ *      Lesser General Public License for more details.
+ *
+ *      You should have received a copy of the GNU Lesser General Public
+ *      License along with this library in the file COPYING.LIB;
+ *      if not, write to the Free Software Foundation, Inc.,
+ *      59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#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/__config_unikraft b/include/__config_unikraft
new file mode 100644
index 0000000..d67a232
--- /dev/null
+++ b/include/__config_unikraft
@@ -0,0 +1,16 @@
+#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
+
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-Update-the-default-configuration.patch 
b/patches/0001-Update-the-default-configuration.patch
new file mode 100644
index 0000000..8e0eb9d
--- /dev/null
+++ b/patches/0001-Update-the-default-configuration.patch
@@ -0,0 +1,26 @@
+From d8d1e8312a8cec9d163fb4713f3ec622b920e75d Mon Sep 17 00:00:00 2001
+From: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
+Date: Thu, 4 Apr 2019 19:06:08 +0300
+Subject: [PATCH 1/1] Update the default configuration
+
+Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
+---
+ include/__config | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/include/__config b/include/__config
+index 738d891..9a5659b 100644
+--- a/include/__config
++++ b/include/__config
+@@ -23,6 +23,8 @@
+ 
+ #ifdef __cplusplus
+ 
++#include <__config_unikraft>
++
+ #ifdef __GNUC__
+ #  define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
+ // The _GNUC_VER_NEW macro better represents the new GCC versioning scheme
+-- 
+2.20.1
+
diff --git a/patches/0002-Change-from-long-double-function-to-double.patch 
b/patches/0002-Change-from-long-double-function-to-double.patch
new file mode 100644
index 0000000..5420f04
--- /dev/null
+++ b/patches/0002-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
+
-- 
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®.