Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Link Time Optimization (LTO) with clang #2920

Merged
merged 3 commits into from Jan 22, 2017

Conversation

@artemdinaburg
Copy link
Contributor

@artemdinaburg artemdinaburg commented Jan 18, 2017

  • Change the LLVM formula to build the LLVMgold plugin
  • Pass "-flto" for osquery and all dependencies when building with clang on Unix
  • Pass "-flto" to modules when they are built
  • Set ranlib and ar to their LLVM versions when building on Linux

In my quick tests, an LTO build results in an osqueryd binary thats about 2MiB smaller than the equivalent non-LTO build.

Enabling LTO is also a first step to turning on Control Flow Integrity.

* Change the LLVM formula to build the LLVMgold plugin
* Pass "-flto" for osquery and all dependencies when building with clang on Unix
* Pass "-flto" to modules when they are built
* Set `ranlib` and `ar` to their LLVM verions when building on Linux
@muffins
Copy link
Contributor

@muffins muffins commented Jan 19, 2017

ok to test

@osqueryer
Copy link

@osqueryer osqueryer commented Jan 19, 2017

👎 The commit 32074b5 (Job results: 278) failed one or more tests (macOS/OS X).

@osqueryer
Copy link

@osqueryer osqueryer commented Jan 19, 2017

👎 The commit 32074b5 (Job results: 4026) failed one or more tests (Linux).

@osqueryer
Copy link

@osqueryer osqueryer commented Jan 19, 2017

👎 The commit 32074b5 (Job results: 4027) failed one or more tests (Linux).

Updat the revision on llvm formula in llvm.rb to force a rebuild.
Re-enable bottle code since rebuilds are now triggered by the revision change.
@facebook-github-bot
Copy link

@facebook-github-bot facebook-github-bot commented Jan 19, 2017

@artemdinaburg updated the pull request - view changes

@@ -142,6 +148,20 @@ else()
endif()
endif()

if(UNIX AND NOT APPLE)

This comment has been minimized.

@theopolis

theopolis Jan 20, 2017
Member

Maybe just if(LINUX)

This comment has been minimized.

@theopolis

theopolis Jan 20, 2017
Member

Could you add the CMAKE_CXX_COMPILER MATCHES "clang" to this conditional too? It seems more consistent with the rest of the CMake logic changes.

This comment has been minimized.

@artemdinaburg

artemdinaburg Jan 21, 2017
Author Contributor

I kept it at UNIX AND NOT APPLE since I figured other platforms like FreeBSD can also build with LTO; although I have not tested. If FreeBSD and other UNIXes are not a worry, I can change it to IF(LINUX)

This comment has been minimized.

@theopolis

theopolis Jan 21, 2017
Member

Right, there're too many conditionals using LINUX, other UNIXes have been left behind.

@@ -33,6 +33,12 @@ else()
-Wno-unused-parameter
-Wno-gnu-case-range
)
if (CMAKE_CXX_COMPILER MATCHES "clang")

This comment has been minimized.

@theopolis

theopolis Jan 20, 2017
Member

You should be able to nix this.

This comment has been minimized.

@artemdinaburg

artemdinaburg Jan 21, 2017
Author Contributor

Are we guaranteed to be on clang at this point? I added it since if someone were to set CC=gcc as an environment variable, -flto would cause issues.

This comment has been minimized.

@theopolis

theopolis Jan 21, 2017
Member

Ah, I meant the whole body, the CMakeLists.txt in the top level should have added this compile option right?

# When doing a clang on Unix LTO build, the link step also needs
# -flto on the comand line
ADD_OSQUERY_LINK_CORE("-flto")
ADD_OSQUERY_LINK_ADDITIONAL("-flto")

This comment has been minimized.

@theopolis

theopolis Jan 20, 2017
Member

You can nix this, core's links should be added to additional's IIRC.

@facebook-github-bot
Copy link

@facebook-github-bot facebook-github-bot commented Jan 22, 2017

@artemdinaburg updated the pull request - view changes

@theopolis theopolis merged commit 24513a3 into osquery:master Jan 22, 2017
4 checks passed
4 checks passed
Code Audit Build finished.
Details
Linux Build finished.
Details
Windows Build finished.
Details
macOS/OS X Build finished.
Details
@artemdinaburg artemdinaburg deleted the artemdinaburg:clang_lto_pr branch Jan 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.