diff options
author | Andrew Morrow <acm@mongodb.com> | 2014-12-12 15:01:07 -0500 |
---|---|---|
committer | Andrew Morrow <acm@mongodb.com> | 2014-12-30 14:11:20 -0500 |
commit | 0777616ff7ce85292e865c0340d92aadf7ba9867 (patch) | |
tree | 96a7258d55580089aaa0a5ae2204801017879336 /SConstruct | |
parent | 4580fe1b3e01d8651fcec46522e506d82b0824c0 (diff) | |
download | mongo-0777616ff7ce85292e865c0340d92aadf7ba9867.tar.gz |
SERVER-16200 Improve LTO integration for gcc and clang
Diffstat (limited to 'SConstruct')
-rw-r--r-- | SConstruct | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/SConstruct b/SConstruct index 2dbb78ad436..700ecc3d131 100644 --- a/SConstruct +++ b/SConstruct @@ -1746,6 +1746,39 @@ def doConfigure(myenv): # and link lines. if AddToCCFLAGSIfSupported(myenv, '-flto'): myenv.Append(LINKFLAGS=['-flto']) + + def LinkHelloWorld(context, adornment = None): + test_body = """ + #include <iostream> + int main() { + std::cout << "Hello, World!" << std::endl; + return 0; + } + """ + message = "Trying to link with LTO" + if adornment: + message = message + " " + adornment + message = message + "..." + context.Message(message) + ret = context.TryLink(textwrap.dedent(test_body), ".cpp") + context.Result(ret) + return ret + + conf = Configure(myenv, help=False, custom_tests = { + 'LinkHelloWorld' : LinkHelloWorld, + }) + + # Some systems (clang, on a system with the BFD linker by default) may need to + # explicitly request the gold linker for LTO to work. If we can't LTO link a + # simple program, see if -fuse=ld=gold helps. + if not conf.LinkHelloWorld(): + conf.env.Append(LINKFLAGS=["-fuse-ld=gold"]) + if not conf.LinkHelloWorld("(with -fuse-ld=gold)"): + print("Error: Couldn't link with LTO") + Exit(1) + + myenv = conf.Finish() + else: print( "Link time optimization requested, " + "but selected compiler does not honor -flto" ) |