From 856ea2bad3b3eac565215c0ac79f37a4ba4cd5b7 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 13 Dec 2019 21:07:04 -0800 Subject: [PATCH] libcxx: Add package Currently in OpenWrt, there are two libc++: libstdcpp and uClibc++. The former is huge and the latter supports only C++98 with some basic support for C++11. Those C++ versions seem to be specific to the compiler version libcxx supports C++11 and above while being much smaller than libstdcpp. On mt7621, these are the sizes of the ipks that I get: libstdcpp: 460786 libcxx: 182881 uClibc++:67720 libcxx is faster than uClibc++ and is under active development as part of the LLVM project while uClibc++ is effectively dead. This PR modifies uclibc++.mk to expose the make menuconfig option. Further cleanup is beyond the scope of this PR. What that means is, this is not used by default. A g++-libcxx wrapper based on the uClibc++ one was added. Works the same way. Compile tested with all packages that use uclibc++.mk in their Makefiles under mipsel_24kc. kismet fails compilation but that package needs to be cleaned up and updated. Runtime tested with gddrescue, gdisk, dcwapd, bonnie++, and aircrack-ng on a TP-Link Archer C7v2. Signed-off-by: Rosen Penev --- config/Config-build.in | 3 ++ include/uclibc++.mk | 12 +++++- package/libs/libcxx/Makefile | 62 ++++++++++++++++++++++++++++ package/libs/libcxx/files/g++-libcxx | 19 +++++++++ 4 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 package/libs/libcxx/Makefile create mode 100755 package/libs/libcxx/files/g++-libcxx diff --git a/config/Config-build.in b/config/Config-build.in index 872e5c12ab..bde5730e76 100644 --- a/config/Config-build.in +++ b/config/Config-build.in @@ -197,6 +197,9 @@ menu "Global build settings" config USE_UCLIBCXX bool "uClibc++" + config USE_LIBCXX + bool "libc++" + config USE_LIBSTDCXX bool "libstdc++" endchoice diff --git a/include/uclibc++.mk b/include/uclibc++.mk index a1a61f26d4..27533279c9 100644 --- a/include/uclibc++.mk +++ b/include/uclibc++.mk @@ -4,8 +4,8 @@ ifndef DUMP endif endif -PKG_PREPARED_DEPENDS += CONFIG_USE_UCLIBCXX -CXX_DEPENDS = +USE_UCLIBCXX:uclibcxx +USE_LIBSTDCXX:libstdcpp +PKG_PREPARED_DEPENDS += CONFIG_USE_UCLIBCXX CONFIG_USE_LIBCXX +CXX_DEPENDS = +USE_UCLIBCXX:uclibcxx +USE_LIBCXX:libcxx +USE_LIBSTDCXX:libstdcpp ifneq ($(CONFIG_USE_UCLIBCXX),) ifneq ($(CONFIG_CCACHE),) @@ -14,3 +14,11 @@ ifneq ($(CONFIG_USE_UCLIBCXX),) TARGET_CXX=g++-uc endif endif + +ifneq ($(CONFIG_USE_LIBCXX),) + ifneq ($(CONFIG_CCACHE),) + TARGET_CXX_NOCACHE=g++-libcxx + else + TARGET_CXX=g++-libcxx + endif +endif diff --git a/package/libs/libcxx/Makefile b/package/libs/libcxx/Makefile new file mode 100644 index 0000000000..c1fa1d6b07 --- /dev/null +++ b/package/libs/libcxx/Makefile @@ -0,0 +1,62 @@ +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=libcxx +PKG_VERSION:=9.0.1 +PKG_RELEASE:=1 + +PKG_SOURCE_PROTO:=git +PKG_SOURCE_URL:=https://git.llvm.org/git/libcxx +PKG_SOURCE_VERSION:=2076f539f410805ef88692b9c0ce0a0b882a7680 +PKG_MIRROR_HASH:=6dff036660d478bfaa14e407fc5de26d22da1087118c897b1a3ad2e90cb7bf39 + +PKG_MAINTAINER:=Rosen Penev +PKG_LICENSE:=MIT +PKG_LICENSE_FILES:=LICENSE.txt + +PKG_BUILD_PARALLEL:=1 +CMAKE_BINARY_SUBDIR:=build + +include $(INCLUDE_DIR)/package.mk +include $(INCLUDE_DIR)/cmake.mk + +define Package/libcxx + SECTION:=libs + CATEGORY:=Libraries + TITLE:=LLVM libstdc++ + URL:=https://libcxx.llvm.org/ + DEPENDS:=+libatomic +libpthread +endef + +define Package/libcxx/description + LLVM C++ library targeting C++11 and above +endef + +CMAKE_OPTIONS += \ + -DLIBCXX_ENABLE_ASSERTIONS=OFF \ + -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF \ + -DLIBCXX_INCLUDE_BENCHMARKS=OFF \ + -DLIBCXX_INCLUDE_DOCS=OFF \ + -DLIBCXX_INCLUDE_TESTS=OFF \ + -DLIBCXX_HAS_MUSL_LIBC=ON \ + -DLIBCXX_STANDALONE_BUILD=ON + +TARGET_CXXFLAGS += -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -Wno-attributes -flto +TARGET_LDFLAGS += -Wl,--as-needed + +define Build/InstallDev + $(call Build/InstallDev/cmake,$(1)) + $(CP) files/g++-libcxx $(TOOLCHAIN_DIR)/bin/ + $(SED) 's,CXX,$(TARGET_CXX),g' $(TOOLCHAIN_DIR)/bin/g++-libcxx +endef + +define Package/libcxx/install + $(INSTALL_DIR) $(1)/usr/lib + $(CP) $(PKG_INSTALL_DIR)/usr/lib/libc++.so.* $(1)/usr/lib/ +endef + +$(eval $(call BuildPackage,libcxx)) diff --git a/package/libs/libcxx/files/g++-libcxx b/package/libs/libcxx/files/g++-libcxx new file mode 100755 index 0000000000..81ca46eb0e --- /dev/null +++ b/package/libs/libcxx/files/g++-libcxx @@ -0,0 +1,19 @@ +#!/bin/sh + +WRAPPER_INCLUDEDIR="-I$STAGING_DIR/usr/include/c++/v1" +WRAPPER_LIBDIR="-L$STAGING_DIR/usr/lib" +WRAPPER_LIBS="-lc -lgcc_s -lssp_nonshared" + +WRAPPER_OPTIONS="" +WRAPPER_INCLIB="Y" +for arg +do + case "$arg" in + -c|-E|-S) WRAPPER_INCLIB="N" ;; + -static) [ "$WRAPPER_LIBS" != "-lc -lgcc_s -lssp_nonshared -lgcc_eh" ] && WRAPPER_LIBS="-lc -lgcc_s -lssp_nonshared -lgcc_eh" ;; + esac +done +[ "$WRAPPER_INCLIB" = "Y" ] && WRAPPER_OPTIONS="-nodefaultlibs $WRAPPER_LIBDIR -lc++ -lsupc++ $WRAPPER_LIBS" + +exec CXX -fno-builtin -nostdinc++ -DGCC_HASCLASSVISIBILITY "$WRAPPER_INCLUDEDIR" "$@" $WRAPPER_OPTIONS + -- 2.25.1