diff options
author | Andreas Sandberg <andreas@sandberg.pp.se> | 2013-03-18 10:57:26 +0100 |
---|---|---|
committer | Andreas Sandberg <andreas@sandberg.pp.se> | 2013-03-18 10:57:26 +0100 |
commit | 468ad10f502837ed00f9e91ed16b9eb180adff4c (patch) | |
tree | e271ae815e4734c67848a586e2d362045cb10353 | |
parent | 9e9a47cb9ae69b081206372179b069e6150e7891 (diff) | |
download | gem5-468ad10f502837ed00f9e91ed16b9eb180adff4c.tar.xz |
scons: Avoid malloc/free compiler optimization when using tcmalloc
According to the tcmalloc readme, the recommended way of compiling
applications that make use of tcmalloc is to disable compiler
optimizations that make assumptions about malloc and friends. This
changeset adds the necessary compiler flags for both gcc and clang.
From the tcmalloc readme:
"NOTE: When compiling with programs with gcc, that you plan to link
with libtcmalloc, it's safest to pass in the flags
-fno-builtin-malloc -fno-builtin-calloc
-fno-builtin-realloc -fno-builtin-free
when compiling."
-rwxr-xr-x | SConstruct | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/SConstruct b/SConstruct index 2be0a6767..b175cb491 100755 --- a/SConstruct +++ b/SConstruct @@ -505,6 +505,12 @@ Export('MakeAction') main['LTO_CCFLAGS'] = [] main['LTO_LDFLAGS'] = [] +# According to the readme, tcmalloc works best if the compiler doesn't +# assume that we're using the builtin malloc and friends. These flags +# are compiler-specific, so we need to set them after we detect which +# compiler we're using. +main['TCMALLOC_CCFLAGS'] = [] + CXX_version = readCommand([main['CXX'],'--version'], exception=False) CXX_V = readCommand([main['CXX'],'-V'], exception=False) @@ -581,6 +587,9 @@ if main['GCC']: main['LTO_LDFLAGS'] = ['-flto=%d' % GetOption('num_jobs'), '-fuse-linker-plugin'] + main.Append(TCMALLOC_CCFLAGS=['-fno-builtin-malloc', '-fno-builtin-calloc', + '-fno-builtin-realloc', '-fno-builtin-free']) + elif main['CLANG']: # Check for a supported version of clang, >= 2.9 is needed to # support similar features as gcc 4.4. See @@ -607,6 +616,8 @@ elif main['CLANG']: '-Wno-parentheses', '-Wno-self-assign']) + main.Append(TCMALLOC_CCFLAGS=['-fno-builtin']) + # On Mac OS X/Darwin we need to also use libc++ (part of XCode) as # opposed to libstdc++ to make the transition from TR1 to # C++11. See http://libcxx.llvm.org. However, clang has chosen a @@ -914,7 +925,9 @@ have_posix_clock = \ conf.CheckLibWithHeader('rt', 'time.h', 'C', 'clock_nanosleep(0,0,NULL,NULL);') -if not conf.CheckLib('tcmalloc_minimal'): +if conf.CheckLib('tcmalloc_minimal'): + main.Append(CCFLAGS=main['TCMALLOC_CCFLAGS']) +else: print termcap.Yellow + termcap.Bold + \ "You can get a 12% performance improvement by installing tcmalloc "\ "(libgoogle-perftools-dev package on Ubuntu or RedHat)." + \ |