From 42fd0f5dad9ef7a10872be61d73f4eb5def96ad0 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 11 Dec 2018 17:24:32 -0800 Subject: [PATCH] reduce AAR's content by about 150K We simply don't emit unwind tables, which are not needed anyways since we're compiling without exceptions. the combined saving for all four targets we support is about 120K. This seems to improve .aar's compression, for a total gain of 152 KiB. We also disable stack-protector in the jni code, since it wasn't enabled in libfilament.a anyways. However, we now compile all debug builds with -fstack-protector --- CMakeLists.txt | 3 ++- android/filament-android/CMakeLists.txt | 5 +++-- libs/utils/src/CallStack.cpp | 12 ++++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b48f6a4c2c..cac2f5eca1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,7 +159,7 @@ endif() # On Android RELEASE builds, we disable exceptions and RTTI to save some space (about 75 KiB # saved by -fno-exception and 10 KiB saved by -fno-rtti). if (ANDROID OR WEBGL) - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-exceptions -fno-rtti") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti") endif() # ================================================================================================== @@ -169,6 +169,7 @@ endif() # -fsanitize=undefined causes extremely long link times # -fsanitize=address causes a crash with assimp, which we can't explain for now #set(EXTRA_SANITIZE_OPTIONS "-fsanitize=undefined -fsanitize=address") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fstack-protector") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${EXTRA_SANITIZE_OPTIONS}") # ================================================================================================== diff --git a/android/filament-android/CMakeLists.txt b/android/filament-android/CMakeLists.txt index 12ec3a62b7..c6f703ee63 100644 --- a/android/filament-android/CMakeLists.txt +++ b/android/filament-android/CMakeLists.txt @@ -29,11 +29,12 @@ set_target_properties(smol-v PROPERTIES IMPORTED_LOCATION include_directories(${FILAMENT_DIR}/include) -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-exceptions -fno-rtti") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-stack-protector") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ffast-math -ffp-contract=fast") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fvisibility-inlines-hidden") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fvisibility=hidden") -set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ffunction-sections -fdata-sections") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer -ffunction-sections -fdata-sections") set(CMAKE_SHARED_LINKER_FLAGS" ${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections") set(CMAKE_SHARED_LINKER_FLAGS" ${CMAKE_SHARED_LINKER_FLAGS} -Wl,-Bsymbolic-functions") diff --git a/libs/utils/src/CallStack.cpp b/libs/utils/src/CallStack.cpp index 93f15845e9..1dd236ad09 100644 --- a/libs/utils/src/CallStack.cpp +++ b/libs/utils/src/CallStack.cpp @@ -30,7 +30,7 @@ #define HAS_EXECINFO 0 #endif -#if !defined(WIN32) +#if !defined(NDEBUG) && !defined(WIN32) #include #endif @@ -56,7 +56,7 @@ CallStack CallStack::unwind(size_t ignore) noexcept { // ------------------------------------------------------------------------------------------------ -intptr_t CallStack::operator [](size_t index) const { +intptr_t CallStack::operator[](size_t index) const { if (index >= m_frame_count) { #ifdef __EXCEPTIONS throw std::out_of_range("out-of-range access in CallStack::operator[]"); @@ -78,13 +78,13 @@ void CallStack::update_gcc(size_t ignore) noexcept { // reset the object ssize_t size = 0; - void *array[NUM_FRAMES]; + void* array[NUM_FRAMES]; #if HAS_EXECINFO size = ::backtrace(array, NUM_FRAMES); size -= ignore; #endif for (ssize_t i = 0; i < size; i++) { - m_stack[i].pc = intptr_t(array[ignore+i]); + m_stack[i].pc = intptr_t(array[ignore + i]); } size--; // the last one seems to always be 0x0 @@ -92,7 +92,7 @@ void CallStack::update_gcc(size_t ignore) noexcept { m_frame_count = size_t(std::max(ssize_t(0), size)); } -bool CallStack::operator <(const CallStack& rhs) const { +bool CallStack::operator<(const CallStack& rhs) const { if (m_frame_count != rhs.m_frame_count) { return m_frame_count < rhs.m_frame_count; } @@ -102,7 +102,7 @@ bool CallStack::operator <(const CallStack& rhs) const { // ------------------------------------------------------------------------------------------------ utils::CString CallStack::demangleTypeName(const char* mangled) { -#if !defined(WIN32) +#if !defined(NDEBUG) && !defined(WIN32) size_t len; int status; std::unique_ptr demangled(abi::__cxa_demangle(mangled, nullptr, &len, &status));