From 4d0b56d6793c61e0b8d9dd03149c86de433e40f1 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Mon, 22 Feb 2021 18:17:09 -0800 Subject: [PATCH] scons: Check for "make" when using LTO with gcc. gcc uses "make" to parallelize LTO. If we're using gcc and make isn't found, we have to use single threaded LTO instead. A warning will let the user know what's happening and that they might want to correct the situation. Technically gcc can use the MAKE environment variable to override the program it uses, although I assume it still has to be "make" compatible. Given the fairly low likelihood that someone will need that override and the fact that scons won't pipe that variable through unless we plumb it up, we'll just ignore that for now. Change-Id: I891b213ece2a75bd8a915ee91f4130458dab397b Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/41773 Reviewed-by: Earl Ou Maintainer: Gabe Black Tested-by: kokoro --- SConstruct | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/SConstruct b/SConstruct index cc3af90d48..19a5da9df5 100755 --- a/SConstruct +++ b/SConstruct @@ -360,14 +360,24 @@ if main['GCC']: # Add the appropriate Link-Time Optimization (LTO) flags # unless LTO is explicitly turned off. if not GetOption('no_lto'): + # g++ uses "make" to parallelize LTO. The program can be overriden with + # the environment variable "MAKE", but we currently make no attempt to + # plumb that variable through. + parallelism = '' + if main.Detect('make'): + parallelism = '=%d' % GetOption('num_jobs') + else: + warning('"make" not found, link time optimization will be ' + 'single threaded.') + # Pass the LTO flag when compiling to produce GIMPLE # output, we merely create the flags here and only append # them later - main['LTO_CCFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] + main['LTO_CCFLAGS'] = ['-flto%s' % parallelism] # Use the same amount of jobs for LTO as we are running # scons with - main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs')] + main['LTO_LDFLAGS'] = ['-flto%s' % parallelism] main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc', '-fno-builtin-realloc', '-fno-builtin-free'])