diff --git a/llvm/Makefile.rules b/llvm/Makefile.rules index 68f6cf8ec5d1..1eeadac19899 100644 --- a/llvm/Makefile.rules +++ b/llvm/Makefile.rules @@ -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 diff --git a/llvm/tools/bugpoint/Makefile b/llvm/tools/bugpoint/Makefile index 20493218b064..96c0fcf519e6 100644 --- a/llvm/tools/bugpoint/Makefile +++ b/llvm/tools/bugpoint/Makefile @@ -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 diff --git a/llvm/tools/llc/Makefile b/llvm/tools/llc/Makefile index c24f378bc538..71bce4dc1adf 100644 --- a/llvm/tools/llc/Makefile +++ b/llvm/tools/llc/Makefile @@ -11,5 +11,8 @@ LEVEL := ../.. TOOLNAME := llc LINK_COMPONENTS := all-targets bitreader asmparser irreader +# Support plugins. +NO_DEAD_STRIP := 1 + include $(LEVEL)/Makefile.common diff --git a/llvm/tools/llvm-shlib/Makefile b/llvm/tools/llvm-shlib/Makefile index 92f3132ff539..317da517202d 100644 --- a/llvm/tools/llvm-shlib/Makefile +++ b/llvm/tools/llvm-shlib/Makefile @@ -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/') diff --git a/llvm/tools/lto/Makefile b/llvm/tools/lto/Makefile index cedbee188c0e..e2b0ff80ef20 100644 --- a/llvm/tools/lto/Makefile +++ b/llvm/tools/lto/Makefile @@ -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/') diff --git a/llvm/tools/opt/Makefile b/llvm/tools/opt/Makefile index a451005574a5..fa2d01455319 100644 --- a/llvm/tools/opt/Makefile +++ b/llvm/tools/opt/Makefile @@ -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