From a7dd190262da5722698aecbd7f17574ff83554c8 Mon Sep 17 00:00:00 2001 From: sayke <thesayke@gmail.com> Date: Fri, 24 Jan 2020 10:31:59 -0800 Subject: [PATCH] Update Makefile so LTO works on OSX The gold linker can only produce ELF binaries, not Mach, so it doesn't work on OSX. This lets link-time optimization work when linking Mach binaries from clang. --- Makefile | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index aee2300aa49c6..74480688a7411 100644 --- a/Makefile +++ b/Makefile @@ -185,7 +185,8 @@ ifeq ($(RUNTESTS), 1) TESTS = tests endif -# tiles object directories are because gcc gets confused # Appears that the default value of $LD is unsuitable on most systems +# tiles object directories are because gcc gets confused +# Appears that the default value of $LD is unsuitable on most systems # when preprocessor defines change, but the source doesn't ODIR = $(BUILD_PREFIX)obj @@ -283,6 +284,7 @@ ifdef RELEASE OPTLEVEL = -Os endif endif + ifdef LTO ifdef CLANG # LLVM's LTO will complain if the optimization level isn't between O0 and @@ -293,7 +295,14 @@ ifdef RELEASE CXXFLAGS += $(OPTLEVEL) ifdef LTO - LDFLAGS += -fuse-ld=gold + ifeq ($(NATIVE), osx) + ifdef CLANG + LTOFLAGS += -flto=full + endif + else + LDFLAGS += -fuse-ld=gold # This breaks in OS X because gold can only produce ELF binaries, not Mach + endif + ifdef CLANG LTOFLAGS += -flto else @@ -303,6 +312,8 @@ ifdef RELEASE CXXFLAGS += $(LTOFLAGS) # OTHERS += -mmmx -m3dnow -msse -msse2 -msse3 -mfpmath=sse -mtune=native + # OTHERS += -march=native # Uncomment this to build an optimized binary for your machine only + # Strip symbols, generates smaller executable. OTHERS += $(RELEASE_FLAGS) DEBUG =