Strip dead code when linking by default with BFD ld (linux, ...) and ld64 (os x).
authorNico Weber <nicolasweber@gmx.de>
Fri, 27 Dec 2013 22:38:59 +0000 (22:38 +0000)
committerNico Weber <nicolasweber@gmx.de>
Fri, 27 Dec 2013 22:38:59 +0000 (22:38 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198087 91177308-0d34-0410-b5e6-96231b3b80d8

Makefile.rules
tools/bugpoint/Makefile
tools/llc/Makefile
tools/llvm-shlib/Makefile
tools/lto/Makefile
tools/opt/Makefile

index 68f6cf8ec5d12b0f1d4a3735129c6c5027bb8a4d..1eeadac1989965101426fd11020089a08d929aab 100644 (file)
@@ -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
index 20493218b0646df24cd30676b972e611696e408a..96c0fcf519e651d6900072ef8d982935ffabb827 100644 (file)
@@ -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
index c24f378bc53891d2c94be103d6c06e5bbf868c71..71bce4dc1adf9a9cc303b1cd432a67f44d70b8af 100644 (file)
@@ -11,5 +11,8 @@ LEVEL := ../..
 TOOLNAME := llc
 LINK_COMPONENTS := all-targets bitreader asmparser irreader
 
+# Support plugins.
+NO_DEAD_STRIP := 1
+
 include $(LEVEL)/Makefile.common
 
index 92f3132ff5393f23e60fea287376c4f82296c87b..317da517202df73c89ef1b342e8a10e9f40dc703 100644 (file)
@@ -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/')
index cedbee188c0e9da318bee1b4b543f6dc2ca79622..e2b0ff80ef2086125feeaf8e1c18a627d5dc7540 100644 (file)
@@ -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/')
index a451005574a55b591a0aeb04799ebcd86d635e5d..fa2d0145531953b9aae244fba226c2140bc51411 100644 (file)
@@ -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