[llvm] r198087 - Strip dead code when linking by default with BFD ld (linux, ...) and ld64 (os x).
Nico Weber
nicolasweber at gmx.de
Fri Dec 27 14:39:00 PST 2013
Author: nico
Date: Fri Dec 27 16:38:59 2013
New Revision: 198087
URL: http://llvm.org/viewvc/llvm-project?rev=198087&view=rev
Log:
Strip dead code when linking by default with BFD ld (linux, ...) and ld64 (os x).
This reduces the size of clang-format from 22 MB to 1.8 MB, diagtool goes from
21 MB to 2.8 MB, libclang.so goes from 29 MB to 20 MB, etc. The size of the
bin/ folder shrinks from 270 MB to 200 MB.
Targets that support plugins and don't already use EXPORTED_SYMBOL_FILE
(which libclang and libLTO already do) can set NO_DEAD_STRIP to opt out.
Modified:
llvm/trunk/Makefile.rules
llvm/trunk/tools/bugpoint/Makefile
llvm/trunk/tools/llc/Makefile
llvm/trunk/tools/llvm-shlib/Makefile
llvm/trunk/tools/lto/Makefile
llvm/trunk/tools/opt/Makefile
Modified: llvm/trunk/Makefile.rules
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/Makefile.rules?rev=198087&r1=198086&r2=198087&view=diff
==============================================================================
--- llvm/trunk/Makefile.rules (original)
+++ llvm/trunk/Makefile.rules Fri Dec 27 16:38:59 2013
@@ -608,6 +608,22 @@ ifndef KEEP_SYMBOLS
Install.StripFlag += -s
endif
+# By default, strip dead symbols at link time
+ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
+ifneq ($(HOST_OS),Darwin)
+ CXX.Flags += -ffunction-sections -fdata-sections
+endif
+endif
+ifndef NO_DEAD_STRIP
+ ifeq ($(HOST_OS),Darwin)
+ LD.Flags += -Wl,-dead_strip
+ else
+ ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
+ LD.Flags += -Wl,--gc-sections
+ endif
+ endif
+endif
+
# Adjust linker flags for building an executable
ifneq ($(HOST_OS), $(filter $(HOST_OS), Cygwin MingW))
ifndef TOOL_NO_EXPORTS
Modified: llvm/trunk/tools/bugpoint/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/Makefile?rev=198087&r1=198086&r2=198087&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/Makefile (original)
+++ llvm/trunk/tools/bugpoint/Makefile Fri Dec 27 16:38:59 2013
@@ -12,4 +12,7 @@ TOOLNAME := bugpoint
LINK_COMPONENTS := asmparser instrumentation scalaropts ipo linker bitreader \
bitwriter irreader vectorize objcarcopts
+# Support plugins.
+NO_DEAD_STRIP := 1
+
include $(LEVEL)/Makefile.common
Modified: llvm/trunk/tools/llc/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/Makefile?rev=198087&r1=198086&r2=198087&view=diff
==============================================================================
--- llvm/trunk/tools/llc/Makefile (original)
+++ llvm/trunk/tools/llc/Makefile Fri Dec 27 16:38:59 2013
@@ -11,5 +11,8 @@ LEVEL := ../..
TOOLNAME := llc
LINK_COMPONENTS := all-targets bitreader asmparser irreader
+# Support plugins.
+NO_DEAD_STRIP := 1
+
include $(LEVEL)/Makefile.common
Modified: llvm/trunk/tools/llvm-shlib/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-shlib/Makefile?rev=198087&r1=198086&r2=198087&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-shlib/Makefile (original)
+++ llvm/trunk/tools/llvm-shlib/Makefile Fri Dec 27 16:38:59 2013
@@ -49,9 +49,6 @@ ifeq ($(HOST_OS),Darwin)
endif
# Include everything from the .a's into the shared library.
LLVMLibsOptions := $(LLVMLibsOptions) -all_load
- # extra options to override libtool defaults
- LLVMLibsOptions := $(LLVMLibsOptions) \
- -Wl,-dead_strip
# Mac OS X 10.4 and earlier tools do not allow a second -install_name on command line
DARWIN_VERS := $(shell echo $(TARGET_TRIPLE) | sed 's/.*darwin\([0-9]*\).*/\1/')
Modified: llvm/trunk/tools/lto/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/Makefile?rev=198087&r1=198086&r2=198087&view=diff
==============================================================================
--- llvm/trunk/tools/lto/Makefile (original)
+++ llvm/trunk/tools/lto/Makefile Fri Dec 27 16:38:59 2013
@@ -37,9 +37,6 @@ ifeq ($(HOST_OS),Darwin)
-Wl,$(LTO_LIBRARY_VERSION).$(LLVM_SUBMIT_SUBVERSION) \
-Wl,-compatibility_version -Wl,1
endif
- # extra options to override libtool defaults
- LLVMLibsOptions := $(LLVMLibsOptions) \
- -Wl,-dead_strip
# Mac OS X 10.4 and earlier tools do not allow a second -install_name on command line
DARWIN_VERS := $(shell echo $(TARGET_TRIPLE) | sed 's/.*darwin\([0-9]*\).*/\1/')
Modified: llvm/trunk/tools/opt/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/Makefile?rev=198087&r1=198086&r2=198087&view=diff
==============================================================================
--- llvm/trunk/tools/opt/Makefile (original)
+++ llvm/trunk/tools/opt/Makefile Fri Dec 27 16:38:59 2013
@@ -11,4 +11,7 @@ LEVEL := ../..
TOOLNAME := opt
LINK_COMPONENTS := bitreader bitwriter asmparser irreader instrumentation scalaropts objcarcopts ipo vectorize all-targets
+# Support plugins.
+NO_DEAD_STRIP := 1
+
include $(LEVEL)/Makefile.common
More information about the llvm-commits
mailing list