[PATCH] D44121: [scudo] Use gc-sections by default

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 5 15:29:25 PST 2018


cryptoad created this revision.
cryptoad added reviewers: alekseyshl, flowerhack.
Herald added subscribers: Sanitizers, delcypher, mgorny.

If not using `-Wl,--gc-sections`, a whole lot of unused `sanitizer_common` code
and related static variables are pulled into the shared library.
Keep the binary size smaller, and its memory footprint smaller as well, by
using the compiler flags `-ffunction-section` & `-fdata-sections` by default,
as well as the linker flags `-Wl,--gc-sections`.

Current experiments show a large discrepency between binary sizes generated
by gcc (big) and clang (small). I am not sure yet how I can make a test that
would encompass both, so it's an outstanding work item.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D44121

Files:
  lib/scudo/CMakeLists.txt


Index: lib/scudo/CMakeLists.txt
===================================================================
--- lib/scudo/CMakeLists.txt
+++ lib/scudo/CMakeLists.txt
@@ -9,6 +9,10 @@
 
 set(SCUDO_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
 
+# Use gc-sections by default to avoid unused code being pulled in.
+list(APPEND SCUDO_CFLAGS -ffunction-sections -fdata-sections)
+list(APPEND SCUDO_DYNAMIC_LINK_FLAGS -Wl,--gc-sections)
+
 set(SCUDO_SOURCES
   scudo_allocator.cpp
   scudo_crc32.cpp


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44121.137094.patch
Type: text/x-patch
Size: 492 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180305/715e0833/attachment.bin>


More information about the llvm-commits mailing list