From 5231685e8e463362d76e7244022c28d1471cdf42 Mon Sep 17 00:00:00 2001 From: simonb Date: Tue, 23 Jun 2015 05:57:53 -0700 Subject: [PATCH] Reduce the crazy linker's on-disk footprint. The change to enable libc++ on Android caused a large increase in the size of libchromium_android_linker.so: https://codereview.chromium.org/951983002 Most of this size increase comes from LLVM's __cxa_demangle, but this function is not required by the crazy linker. Providing a local stub implementation prevents LLVM's implementation being linked from libc++, and reduces the size of the crazy linker -- for example from 292kb down to 83kb on ARM. BUG=502299 Review URL: https://codereview.chromium.org/1193393008 Cr-Commit-Position: refs/heads/master@{#335659} --- third_party/android_crazy_linker/README.chromium | 2 ++ .../src/src/crazy_linker_wrappers.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/third_party/android_crazy_linker/README.chromium b/third_party/android_crazy_linker/README.chromium index 97147d28f3ed..6880c889e4bf 100644 --- a/third_party/android_crazy_linker/README.chromium +++ b/third_party/android_crazy_linker/README.chromium @@ -80,3 +80,5 @@ Local Modifications: - Convert packed relocation code to handle Android packed relocations. +- Implement a stub __cxa_demangle to avoid linking to LLVM's implementation. + diff --git a/third_party/android_crazy_linker/src/src/crazy_linker_wrappers.cpp b/third_party/android_crazy_linker/src/src/crazy_linker_wrappers.cpp index 4b73969bc975..6d5a1fb4cfc1 100644 --- a/third_party/android_crazy_linker/src/src/crazy_linker_wrappers.cpp +++ b/third_party/android_crazy_linker/src/src/crazy_linker_wrappers.cpp @@ -38,6 +38,24 @@ namespace crazy { namespace { +// LLVM's demangler is large, and we have no need of it. Overriding it with +// our own stub version here stops a lot of code being pulled in from libc++. +// This reduces the on-disk footprint of the crazy linker library by more than +// 70%, down from over 290kb to under 85kb on ARM. +// +// For details, see: +// https://code.google.com/p/chromium/issues/detail?id=502299 +// https://llvm.org/svn/llvm-project/libcxxabi/trunk/src/cxa_demangle.cpp +extern "C" char* __cxa_demangle(const char* mangled_name, + char* buf, + size_t* n, + int* status) { + static const int kMemoryAllocFailure = -1; // LLVM's memory_alloc_failure. + if (status) + *status = kMemoryAllocFailure; + return NULL; +} + #ifdef __arm__ extern "C" int __cxa_atexit(void (*)(void*), void*, void*); -- 2.11.4.GIT