Skip to content

Commit

Permalink
Update Makefile so LTO works on OSX
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sayke committed Jan 24, 2020
1 parent ea0a67a commit a7dd190
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 =
Expand Down

0 comments on commit a7dd190

Please sign in to comment.