[OpenWrt-Devel] [PATCH 2/2] libcxx: Add size optimizations

Rosen Penev rosenp at gmail.com
Tue Dec 31 22:37:35 EST 2019


Changed standard to 2a. 2a (as well as 17) contain more constexpr
functions, which are evaluated at compile time. This saves space.

Added --gc-sections. With the CXXABI change, this now makes the package
smaller.

With these, size went down to 210845 on mipsel_24kc.

Also fixed two small compiler warnings. No real change in behavior.

Signed-off-by: Rosen Penev <rosenp at gmail.com>
---
 package/libs/libcxx/Makefile                |  2 +-
 package/libs/libcxx/patches/010-cxx17.patch | 14 ++++++++++++
 package/libs/libcxx/patches/020-fixes.patch | 24 +++++++++++++++++++++
 3 files changed, 39 insertions(+), 1 deletion(-)
 create mode 100644 package/libs/libcxx/patches/010-cxx17.patch
 create mode 100644 package/libs/libcxx/patches/020-fixes.patch

diff --git a/package/libs/libcxx/Makefile b/package/libs/libcxx/Makefile
index 60978bdc31..1d8e502221 100644
--- a/package/libs/libcxx/Makefile
+++ b/package/libs/libcxx/Makefile
@@ -47,7 +47,7 @@ CMAKE_OPTIONS += \
 	-DLIBCXX_HAS_MUSL_LIBC=$(if $(CONFIG_USE_MUSL),ON,OFF)
 
 TARGET_CXXFLAGS += -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -Wno-attributes -flto
-TARGET_LDFLAGS += -Wl,--as-needed
+TARGET_LDFLAGS += -Wl,--gc-sections,--as-needed -flto=jobserver
 
 define Build/InstallDev
 	$(call Build/InstallDev/cmake,$(1))
diff --git a/package/libs/libcxx/patches/010-cxx17.patch b/package/libs/libcxx/patches/010-cxx17.patch
new file mode 100644
index 0000000000..c313c47611
--- /dev/null
+++ b/package/libs/libcxx/patches/010-cxx17.patch
@@ -0,0 +1,14 @@
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -524,9 +524,9 @@ remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
+ if (LIBCXX_HAS_MUSL_LIBC OR LIBCXX_TARGETING_CLANG_CL)
+   # musl's pthread implementations uses volatile types in their structs which is
+   # not a constexpr in C++11 but is in C++14, so we use C++14 with musl.
+-  set(LIBCXX_STANDARD_VER c++14 CACHE STRING "internal option to change build dialect")
++  set(LIBCXX_STANDARD_VER c++2a CACHE STRING "internal option to change build dialect")
+ else()
+-  set(LIBCXX_STANDARD_VER c++11 CACHE STRING "internal option to change build dialect")
++  set(LIBCXX_STANDARD_VER c++2a CACHE STRING "internal option to change build dialect")
+ endif()
+ add_compile_flags_if_supported(-std=${LIBCXX_STANDARD_VER})
+ add_compile_flags_if_supported("/std:${LIBCXX_STANDARD_VER}")
diff --git a/package/libs/libcxx/patches/020-fixes.patch b/package/libs/libcxx/patches/020-fixes.patch
new file mode 100644
index 0000000000..abc630d42f
--- /dev/null
+++ b/package/libs/libcxx/patches/020-fixes.patch
@@ -0,0 +1,24 @@
+--- a/include/memory
++++ b/include/memory
+@@ -1696,7 +1696,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
+             ptrdiff_t _Np = __end1 - __begin1;
+             __end2 -= _Np;
+             if (_Np > 0)
+-                _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
++                __end2 = __begin1;
+         }
+ 
+ private:
+--- a/src/filesystem/filesystem_common.h
++++ b/src/filesystem/filesystem_common.h
+@@ -197,8 +197,8 @@ private:
+ using chrono::duration;
+ using chrono::duration_cast;
+ 
+-using TimeSpec = struct ::timespec;
+-using StatT = struct ::stat;
++using TimeSpec = struct timespec;
++using StatT = struct stat;
+ 
+ template <class FileTimeT, class TimeT,
+           bool IsFloat = is_floating_point<typename FileTimeT::rep>::value>
-- 
2.24.1


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list