Update Makefile so LTO works on OSX #37356
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
SUMMARY: Build "Update Makefile so LTO works on OSX"
Purpose of change
Using the LTO flag on OSX would previously break the build (linking) process. The gold linker can only produce ELF binaries, not Mach, so it doesn't work on OSX. This minor tweak lets link-time optimization work when linking Mach binaries from clang.
I also added a commented-out line to let people easily build custom binaries for their hardware by uncommenting it:
# OTHERS += -march=native # Uncomment this to build an optimized binary for your machine only
Describe the solution
This uses
-flto=full
to use clang LTO instead of trying to use the gold linker via-fuse-ld=gold
, thus enabling LTO on OSX.Describe alternatives you've considered
I considering consolidating the
ifdef LTO
conditionals but I can see why someone would in principlewant to separate out the OPTLEVEL and LTOFLAGS stages.
Testing
I built it on OSX and it works.
Additional context
Current OSX binaries are basically unoptimized, because optimizations apparently break compatibility with OSX 10.11 and older versions. If we dropped compatibility for those old versions of OSX then user-facing performance would significantly increase.