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

enhance GCC easyblock to make sure that system GCC provides LTO support, and disable LTO when building MPFR if not #2498

Merged
merged 1 commit into from
Jun 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions easybuild/easyblocks/g/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
from easybuild.framework.easyconfig import CUSTOM
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.config import build_option
from easybuild.tools.filetools import apply_regex_substitutions, change_dir, copy_file, move_file, symlink, write_file
from easybuild.tools.filetools import apply_regex_substitutions, change_dir, copy_file, move_file, symlink
from easybuild.tools.filetools import which, write_file
from easybuild.tools.modules import get_software_root
from easybuild.tools.run import run_cmd
from easybuild.tools.systemtools import check_os_dependency, get_os_name, get_os_type
Expand Down Expand Up @@ -152,6 +153,9 @@ def disable_lto_mpfr_old_gcc(self, objdir):

# for MPFR v4.x & newer, we need a recent GCC that supports -flto
if LooseVersion(mpfr_ver) >= LooseVersion('4.0'):

disable_mpfr_lto = False

# check GCC version being used
# GCC 4.5 is required for -flto (cfr. https://gcc.gnu.org/gcc-4.5/changes.html)
gcc_ver = get_gcc_version()
Expand All @@ -161,14 +165,26 @@ def disable_lto_mpfr_old_gcc(self, objdir):
elif LooseVersion(gcc_ver) < LooseVersion(min_gcc_ver_lto):
self.log.info("Configuring MPFR to build without LTO in stage 1 (GCC %s is too old: < %s)!",
gcc_ver, min_gcc_ver_lto)
disable_mpfr_lto = True
else:
self.log.info("GCC %s (>= %s) is OK for building MPFR in stage 1 with LTO enabled",
gcc_ver, min_gcc_ver_lto)

# check whether GCC actually supports LTO (it may be configured with --disable-lto),
# by compiling a simple C program using -flto
out, ec = run_cmd("echo 'void main() {}' | gcc -x c -flto - -o /dev/null", simple=False, log_ok=False)
gcc_path = which('gcc')
if ec:
self.log.info("GCC command %s doesn't seem to support LTO, test compile failed: %s", gcc_path, out)
disable_mpfr_lto = True
else:
self.log.info("GCC command %s provides LTO support, so using it when building MPFR", gcc_path)

if disable_mpfr_lto:
# patch GCC's Makefile to inject --disable-lto when building MPFR
stage1_makefile = os.path.join(objdir, 'Makefile')
regex_subs = [(r'(--with-gmp-lib=\$\$r/\$\(HOST_SUBDIR\)/gmp/.libs) \\', r'\1 --disable-lto \\')]
apply_regex_substitutions(stage1_makefile, regex_subs)
else:
self.log.info("GCC %s (>= %s) is OK for building MPFR in stage 1 with LTO enabled",
gcc_ver, min_gcc_ver_lto)

def prep_extra_src_dirs(self, stage, target_prefix=None):
"""
Expand Down