0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 17:10:48 +01:00

SERVER-16200 Improve LTO integration for gcc and clang

This commit is contained in:
Andrew Morrow 2014-12-12 15:01:07 -05:00
parent 4580fe1b3e
commit 0777616ff7
3 changed files with 41 additions and 2 deletions

View File

@ -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" )

View File

@ -447,8 +447,11 @@ def removeIfPresent(lst, item):
except ValueError:
pass
for to_remove in ['-Werror', '-Wall', '-W']:
# NOTE: Along with the warning flags, remove any flags for LTO when building v8,
# as LTO builds currently appear to generate bad code with clang.
for to_remove in ['-Werror', '-Wall', '-W', "-flto"]:
removeIfPresent(env['CCFLAGS'], to_remove)
removeIfPresent(env['LINKFLAGS'], to_remove)
# specify rules for building libraries.cc and experimental-libraries.cc
env['BUILDERS']['JS2C'] = Builder(action=js2c.JS2C)

View File

@ -377,8 +377,11 @@ def removeIfPresent(lst, item):
except ValueError:
pass
for to_remove in ['-Werror', '-Wall', '-W']:
# NOTE: Along with the warning flags, remove any flags for LTO when building v8,
# as LTO builds currently appear to generate bad code with clang.
for to_remove in ['-Werror', '-Wall', '-W', "-flto"]:
removeIfPresent(env['CCFLAGS'], to_remove)
removeIfPresent(env['LINKFLAGS'], to_remove)
# specify rules for building libraries.cc and experimental-libraries.cc
env['BUILDERS']['JS2C'] = Builder(action=js2c.JS2C)