Language-specific PIC flags (#15474)

* Language-specific PIC flags

* Add tests for every compiler flag

* Fix bad rebase

* pic_flag -> cxx_pic_flag
This commit is contained in:
Adam J. Stewart
2020-04-17 16:28:51 -05:00
committed by GitHub
parent ad8977467b
commit 284e450c91
62 changed files with 415 additions and 160 deletions

View File

@@ -169,7 +169,7 @@ def _do_patch_libtool(self):
line = 'wl="-Wl,"\n'
if line == 'pic_flag=""\n':
line = 'pic_flag="{0}"\n'\
.format(self.compiler.pic_flag)
.format(self.compiler.cc_pic_flag)
sys.stdout.write(line)
@property

View File

@@ -410,6 +410,30 @@ def c11_flag(self):
"the C11 standard",
"c11_flag")
@property
def cc_pic_flag(self):
"""Returns the flag used by the C compiler to produce
Position Independent Code (PIC)."""
return '-fPIC'
@property
def cxx_pic_flag(self):
"""Returns the flag used by the C++ compiler to produce
Position Independent Code (PIC)."""
return '-fPIC'
@property
def f77_pic_flag(self):
"""Returns the flag used by the F77 compiler to produce
Position Independent Code (PIC)."""
return '-fPIC'
@property
def fc_pic_flag(self):
"""Returns the flag used by the FC compiler to produce
Position Independent Code (PIC)."""
return '-fPIC'
#
# Compiler classes have methods for querying the version of
# specific compiler executables. This is used when discovering compilers.

View File

@@ -80,7 +80,19 @@ def c11_flag(self):
return "-std=c11"
@property
def pic_flag(self):
def cc_pic_flag(self):
return "-fPIC"
@property
def cxx_pic_flag(self):
return "-fPIC"
@property
def f77_pic_flag(self):
return "-fPIC"
@property
def fc_pic_flag(self):
return "-fPIC"
required_libs = ['libclang', 'libflang']

View File

@@ -68,5 +68,17 @@ def c11_flag(self):
'< 8.5')
@property
def pic_flag(self):
def cc_pic_flag(self):
return "-h PIC"
@property
def cxx_pic_flag(self):
return "-h PIC"
@property
def f77_pic_flag(self):
return "-h PIC"
@property
def fc_pic_flag(self):
return "-h PIC"

View File

@@ -174,7 +174,19 @@ def c11_flag(self):
return "-std=c11"
@property
def pic_flag(self):
def cc_pic_flag(self):
return "-fPIC"
@property
def cxx_pic_flag(self):
return "-fPIC"
@property
def f77_pic_flag(self):
return "-fPIC"
@property
def fc_pic_flag(self):
return "-fPIC"
required_libs = ['libclang']

View File

@@ -59,5 +59,17 @@ def c11_flag(self):
return "-std=c11"
@property
def pic_flag(self):
def cc_pic_flag(self):
return "-KPIC"
@property
def cxx_pic_flag(self):
return "-KPIC"
@property
def f77_pic_flag(self):
return "-KPIC"
@property
def fc_pic_flag(self):
return "-KPIC"

View File

@@ -110,7 +110,19 @@ def c11_flag(self):
return "-std=c11"
@property
def pic_flag(self):
def cc_pic_flag(self):
return "-fPIC"
@property
def cxx_pic_flag(self):
return "-fPIC"
@property
def f77_pic_flag(self):
return "-fPIC"
@property
def fc_pic_flag(self):
return "-fPIC"
required_libs = ['libgcc', 'libgfortran']

View File

@@ -92,7 +92,19 @@ def c11_flag(self):
return "-std=c1x"
@property
def pic_flag(self):
def cc_pic_flag(self):
return "-fPIC"
@property
def cxx_pic_flag(self):
return "-fPIC"
@property
def f77_pic_flag(self):
return "-fPIC"
@property
def fc_pic_flag(self):
return "-fPIC"
@property

View File

@@ -41,7 +41,11 @@ def cxx11_flag(self):
return "-std=c++11"
@property
def pic_flag(self):
def f77_pic_flag(self):
return "-PIC"
@property
def fc_pic_flag(self):
return "-PIC"
# Unlike other compilers, the NAG compiler passes options to GCC, which

View File

@@ -46,7 +46,19 @@ def cxx11_flag(self):
return "-std=c++11"
@property
def pic_flag(self):
def cc_pic_flag(self):
return "-fpic"
@property
def cxx_pic_flag(self):
return "-fpic"
@property
def f77_pic_flag(self):
return "-fpic"
@property
def fc_pic_flag(self):
return "-fpic"
required_libs = ['libpgc', 'libpgf90']

View File

@@ -70,7 +70,19 @@ def c11_flag(self):
'< 12.1')
@property
def pic_flag(self):
def cc_pic_flag(self):
return "-qpic"
@property
def cxx_pic_flag(self):
return "-qpic"
@property
def f77_pic_flag(self):
return "-qpic"
@property
def fc_pic_flag(self):
return "-qpic"
@property

View File

@@ -17,13 +17,13 @@
import spack.compilers.arm
import spack.compilers.cce
import spack.compilers.clang
import spack.compilers.fj
import spack.compilers.gcc
import spack.compilers.intel
import spack.compilers.nag
import spack.compilers.pgi
import spack.compilers.xl
import spack.compilers.xl_r
import spack.compilers.fj
from spack.compiler import Compiler
@@ -222,18 +222,53 @@ def supported_flag_test(flag, flag_value_ref, spec=None):
# Tests for UnsupportedCompilerFlag exceptions from default
# implementations of flags.
def test_default_flags():
supported_flag_test("cc_rpath_arg", "-Wl,-rpath,")
supported_flag_test("cxx_rpath_arg", "-Wl,-rpath,")
supported_flag_test("f77_rpath_arg", "-Wl,-rpath,")
supported_flag_test("fc_rpath_arg", "-Wl,-rpath,")
supported_flag_test("linker_arg", "-Wl,")
unsupported_flag_test("openmp_flag")
unsupported_flag_test("cxx11_flag")
unsupported_flag_test("cxx14_flag")
unsupported_flag_test("cxx17_flag")
supported_flag_test("cxx98_flag", "")
unsupported_flag_test("c99_flag")
unsupported_flag_test("c11_flag")
supported_flag_test("cc_pic_flag", "-fPIC")
supported_flag_test("cxx_pic_flag", "-fPIC")
supported_flag_test("f77_pic_flag", "-fPIC")
supported_flag_test("fc_pic_flag", "-fPIC")
# Verify behavior of particular compiler definitions.
def test_clang_flags():
# Common
supported_flag_test("pic_flag", "-fPIC", "gcc@4.0")
def test_arm_flags():
supported_flag_test("openmp_flag", "-fopenmp", "arm@1.0")
supported_flag_test("cxx11_flag", "-std=c++11", "arm@1.0")
supported_flag_test("cxx14_flag", "-std=c++14", "arm@1.0")
supported_flag_test("cxx17_flag", "-std=c++1z", "arm@1.0")
supported_flag_test("c99_flag", "-std=c99", "arm@1.0")
supported_flag_test("c11_flag", "-std=c11", "arm@1.0")
supported_flag_test("cc_pic_flag", "-fPIC", "arm@1.0")
supported_flag_test("cxx_pic_flag", "-fPIC", "arm@1.0")
supported_flag_test("f77_pic_flag", "-fPIC", "arm@1.0")
supported_flag_test("fc_pic_flag", "-fPIC", "arm@1.0")
def test_cce_flags():
supported_flag_test("openmp_flag", "-h omp", "cce@1.0")
supported_flag_test("cxx11_flag", "-h std=c++11", "cce@1.0")
unsupported_flag_test("c99_flag", "cce@8.0")
supported_flag_test("c99_flag", "-h c99,noconform,gnu", "cce@8.1")
supported_flag_test("c99_flag", "-h stc=c99,noconform,gnu", "cce@8.4")
unsupported_flag_test("c11_flag", "cce@8.4")
supported_flag_test("c11_flag", "-h std=c11,noconform,gnu", "cce@8.5")
supported_flag_test("cc_pic_flag", "-h PIC", "cce@1.0")
supported_flag_test("cxx_pic_flag", "-h PIC", "cce@1.0")
supported_flag_test("f77_pic_flag", "-h PIC", "cce@1.0")
supported_flag_test("fc_pic_flag", "-h PIC", "cce@1.0")
def test_clang_flags():
# Apple Clang.
supported_flag_test(
"openmp_flag", "-Xpreprocessor -fopenmp", "clang@2.0.0-apple")
@@ -244,6 +279,13 @@ def test_clang_flags():
supported_flag_test("cxx14_flag", "-std=c++14", "clang@6.1.0-apple")
unsupported_flag_test("cxx17_flag", "clang@6.0.0-apple")
supported_flag_test("cxx17_flag", "-std=c++1z", "clang@6.1.0-apple")
supported_flag_test("c99_flag", "-std=c99", "clang@6.1.0-apple")
unsupported_flag_test("c11_flag", "clang@6.0.0-apple")
supported_flag_test("c11_flag", "-std=c11", "clang@6.1.0-apple")
supported_flag_test("cc_pic_flag", "-fPIC", "clang@2.0.0-apple")
supported_flag_test("cxx_pic_flag", "-fPIC", "clang@2.0.0-apple")
supported_flag_test("f77_pic_flag", "-fPIC", "clang@2.0.0-apple")
supported_flag_test("fc_pic_flag", "-fPIC", "clang@2.0.0-apple")
# non-Apple Clang.
supported_flag_test("openmp_flag", "-fopenmp", "clang@3.3")
@@ -255,12 +297,26 @@ def test_clang_flags():
unsupported_flag_test("cxx17_flag", "clang@3.4")
supported_flag_test("cxx17_flag", "-std=c++1z", "clang@3.5")
supported_flag_test("cxx17_flag", "-std=c++17", "clang@5.0")
supported_flag_test("c99_flag", "-std=c99", "clang@3.3")
unsupported_flag_test("c11_flag", "clang@6.0.0")
supported_flag_test("c11_flag", "-std=c11", "clang@6.1.0")
supported_flag_test("cc_pic_flag", "-fPIC", "clang@3.3")
supported_flag_test("cxx_pic_flag", "-fPIC", "clang@3.3")
supported_flag_test("f77_pic_flag", "-fPIC", "clang@3.3")
supported_flag_test("fc_pic_flag", "-fPIC", "clang@3.3")
def test_cce_flags():
supported_flag_test("openmp_flag", "-h omp", "cce@1.0")
supported_flag_test("cxx11_flag", "-h std=c++11", "cce@1.0")
supported_flag_test("pic_flag", "-h PIC", "cce@1.0")
def test_fj_flags():
supported_flag_test("openmp_flag", "-Kopenmp", "fj@4.0.0")
supported_flag_test("cxx98_flag", "-std=c++98", "fj@4.0.0")
supported_flag_test("cxx11_flag", "-std=c++11", "fj@4.0.0")
supported_flag_test("cxx14_flag", "-std=c++14", "fj@4.0.0")
supported_flag_test("c99_flag", "-std=c99", "fj@4.0.0")
supported_flag_test("c11_flag", "-std=c11", "fj@4.0.0")
supported_flag_test("cc_pic_flag", "-KPIC", "fj@4.0.0")
supported_flag_test("cxx_pic_flag", "-KPIC", "fj@4.0.0")
supported_flag_test("f77_pic_flag", "-KPIC", "fj@4.0.0")
supported_flag_test("fc_pic_flag", "-KPIC", "fj@4.0.0")
def test_gcc_flags():
@@ -275,7 +331,17 @@ def test_gcc_flags():
supported_flag_test("cxx14_flag", "-std=c++14", "gcc@4.9")
supported_flag_test("cxx14_flag", "", "gcc@6.0")
unsupported_flag_test("cxx17_flag", "gcc@4.9")
supported_flag_test("pic_flag", "-fPIC", "gcc@4.0")
supported_flag_test("cxx17_flag", "-std=c++1z", "gcc@5.0")
supported_flag_test("cxx17_flag", "-std=c++17", "gcc@6.0")
unsupported_flag_test("c99_flag", "gcc@4.4")
supported_flag_test("c99_flag", "-std=c99", "gcc@4.5")
unsupported_flag_test("c11_flag", "gcc@4.6")
supported_flag_test("c11_flag", "-std=c11", "gcc@4.7")
supported_flag_test("cc_pic_flag", "-fPIC", "gcc@4.0")
supported_flag_test("cxx_pic_flag", "-fPIC", "gcc@4.0")
supported_flag_test("f77_pic_flag", "-fPIC", "gcc@4.0")
supported_flag_test("fc_pic_flag", "-fPIC", "gcc@4.0")
supported_flag_test("stdcxx_libs", ("-lstdc++",), "gcc@4.1")
def test_intel_flags():
@@ -287,43 +353,105 @@ def test_intel_flags():
unsupported_flag_test("cxx14_flag", "intel@14.0")
supported_flag_test("cxx14_flag", "-std=c++1y", "intel@15.0")
supported_flag_test("cxx14_flag", "-std=c++14", "intel@15.0.2")
supported_flag_test("pic_flag", "-fPIC", "intel@1.0")
unsupported_flag_test("c99_flag", "intel@11.0")
supported_flag_test("c99_flag", "-std=c99", "intel@12.0")
unsupported_flag_test("c11_flag", "intel@15.0")
supported_flag_test("c11_flag", "-std=c1x", "intel@16.0")
supported_flag_test("cc_pic_flag", "-fPIC", "intel@1.0")
supported_flag_test("cxx_pic_flag", "-fPIC", "intel@1.0")
supported_flag_test("f77_pic_flag", "-fPIC", "intel@1.0")
supported_flag_test("fc_pic_flag", "-fPIC", "intel@1.0")
supported_flag_test("stdcxx_libs", ("-cxxlib",), "intel@1.0")
def test_nag_flags():
supported_flag_test("openmp_flag", "-openmp", "nag@1.0")
supported_flag_test("cxx11_flag", "-std=c++11", "nag@1.0")
supported_flag_test("pic_flag", "-PIC", "nag@1.0")
supported_flag_test("cc_pic_flag", "-fPIC", "nag@1.0")
supported_flag_test("cxx_pic_flag", "-fPIC", "nag@1.0")
supported_flag_test("f77_pic_flag", "-PIC", "nag@1.0")
supported_flag_test("fc_pic_flag", "-PIC", "nag@1.0")
supported_flag_test("cc_rpath_arg", "-Wl,-rpath,", "nag@1.0")
supported_flag_test("cxx_rpath_arg", "-Wl,-rpath,", "nag@1.0")
supported_flag_test("f77_rpath_arg", "-Wl,-Wl,,-rpath,,", "nag@1.0")
supported_flag_test("fc_rpath_arg", "-Wl,-Wl,,-rpath,,", "nag@1.0")
supported_flag_test("linker_arg", "-Wl,-Wl,,", "nag@1.0")
def test_pgi_flags():
supported_flag_test("openmp_flag", "-mp", "pgi@1.0")
supported_flag_test("cxx11_flag", "-std=c++11", "pgi@1.0")
supported_flag_test("pic_flag", "-fpic", "pgi@1.0")
unsupported_flag_test("c99_flag", "pgi@12.9")
supported_flag_test("c99_flag", "-c99", "pgi@12.10")
unsupported_flag_test("c11_flag", "pgi@15.2")
supported_flag_test("c11_flag", "-c11", "pgi@15.3")
supported_flag_test("cc_pic_flag", "-fpic", "pgi@1.0")
supported_flag_test("cxx_pic_flag", "-fpic", "pgi@1.0")
supported_flag_test("f77_pic_flag", "-fpic", "pgi@1.0")
supported_flag_test("fc_pic_flag", "-fpic", "pgi@1.0")
def test_xl_flags():
supported_flag_test("openmp_flag", "-qsmp=omp", "xl@1.0")
unsupported_flag_test("cxx11_flag", "xl@13.0")
supported_flag_test("cxx11_flag", "-qlanglvl=extended0x", "xl@13.1")
supported_flag_test("pic_flag", "-qpic", "xl@1.0")
unsupported_flag_test("c99_flag", "xl@10.0")
supported_flag_test("c99_flag", "-qlanglvl=extc99", "xl@10.1")
supported_flag_test("c99_flag", "-std=gnu99", "xl@13.1.1")
unsupported_flag_test("c11_flag", "xl@12.0")
supported_flag_test("c11_flag", "-qlanglvl=extc1x", "xl@12.1")
supported_flag_test("c11_flag", "-std=gnu11", "xl@13.1.2")
supported_flag_test("cc_pic_flag", "-qpic", "xl@1.0")
supported_flag_test("cxx_pic_flag", "-qpic", "xl@1.0")
supported_flag_test("f77_pic_flag", "-qpic", "xl@1.0")
supported_flag_test("fc_pic_flag", "-qpic", "xl@1.0")
supported_flag_test("fflags", "-qzerosize", "xl@1.0")
def test_xl_r_flags():
supported_flag_test("openmp_flag", "-qsmp=omp", "xl_r@1.0")
unsupported_flag_test("cxx11_flag", "xl_r@13.0")
supported_flag_test("cxx11_flag", "-qlanglvl=extended0x", "xl_r@13.1")
supported_flag_test("pic_flag", "-qpic", "xl_r@1.0")
unsupported_flag_test("c99_flag", "xl_r@10.0")
supported_flag_test("c99_flag", "-qlanglvl=extc99", "xl_r@10.1")
supported_flag_test("c99_flag", "-std=gnu99", "xl_r@13.1.1")
unsupported_flag_test("c11_flag", "xl_r@12.0")
supported_flag_test("c11_flag", "-qlanglvl=extc1x", "xl_r@12.1")
supported_flag_test("c11_flag", "-std=gnu11", "xl_r@13.1.2")
supported_flag_test("cc_pic_flag", "-qpic", "xl_r@1.0")
supported_flag_test("cxx_pic_flag", "-qpic", "xl_r@1.0")
supported_flag_test("f77_pic_flag", "-qpic", "xl_r@1.0")
supported_flag_test("fc_pic_flag", "-qpic", "xl_r@1.0")
supported_flag_test("fflags", "-qzerosize", "xl_r@1.0")
def test_fj_flags():
supported_flag_test("openmp_flag", "-Kopenmp", "fj@4.0.0")
supported_flag_test("cxx98_flag", "-std=c++98", "fj@4.0.0")
supported_flag_test("cxx11_flag", "-std=c++11", "fj@4.0.0")
supported_flag_test("cxx14_flag", "-std=c++14", "fj@4.0.0")
supported_flag_test("c99_flag", "-std=c99", "fj@4.0.0")
supported_flag_test("c11_flag", "-std=c11", "fj@4.0.0")
supported_flag_test("pic_flag", "-KPIC", "fj@4.0.0")
@pytest.mark.parametrize('version_str,expected_version', [
('Arm C/C++/Fortran Compiler version 19.0 (build number 73) (based on LLVM 7.0.2)\n' # NOQA
'Target: aarch64--linux-gnu\n'
'Thread model: posix\n'
'InstalledDir:\n'
'/opt/arm/arm-hpc-compiler-19.0_Generic-AArch64_RHEL-7_aarch64-linux/bin\n', # NOQA
'19.0.0.73'),
('Arm C/C++/Fortran Compiler version 19.3.1 (build number 75) (based on LLVM 7.0.2)\n' # NOQA
'Target: aarch64--linux-gnu\n'
'Thread model: posix\n'
'InstalledDir:\n'
'/opt/arm/arm-hpc-compiler-19.0_Generic-AArch64_RHEL-7_aarch64-linux/bin\n', # NOQA
'19.3.1.75')
])
def test_arm_version_detection(version_str, expected_version):
version = spack.compilers.arm.Arm.extract_version_from_output(version_str)
assert version == expected_version
@pytest.mark.parametrize('version_str,expected_version', [
('Cray C : Version 8.4.6 Mon Apr 15, 2019 12:13:39\n', '8.4.6'),
('Cray C++ : Version 8.4.6 Mon Apr 15, 2019 12:13:45\n', '8.4.6'),
('Cray Fortran : Version 8.4.6 Mon Apr 15, 2019 12:13:55\n', '8.4.6')
])
def test_cce_version_detection(version_str, expected_version):
version = spack.compilers.cce.Cce.extract_version_from_output(version_str)
assert version == expected_version
@pytest.mark.regression('10191')
@@ -364,21 +492,23 @@ def test_clang_version_detection(version_str, expected_version):
@pytest.mark.parametrize('version_str,expected_version', [
('Arm C/C++/Fortran Compiler version 19.0 (build number 73) (based on LLVM 7.0.2)\n' # NOQA
'Target: aarch64--linux-gnu\n'
'Thread model: posix\n'
'InstalledDir:\n'
'/opt/arm/arm-hpc-compiler-19.0_Generic-AArch64_RHEL-7_aarch64-linux/bin\n', # NOQA
'19.0.0.73'),
('Arm C/C++/Fortran Compiler version 19.3.1 (build number 75) (based on LLVM 7.0.2)\n' # NOQA
'Target: aarch64--linux-gnu\n'
'Thread model: posix\n'
'InstalledDir:\n'
'/opt/arm/arm-hpc-compiler-19.0_Generic-AArch64_RHEL-7_aarch64-linux/bin\n', # NOQA
'19.3.1.75')
# C compiler
('fcc (FCC) 4.0.0 20190314\n'
'simulating gcc version 6.1\n'
'Copyright FUJITSU LIMITED 2019',
'4.0.0'),
# C++ compiler
('FCC (FCC) 4.0.0 20190314\n'
'simulating gcc version 6.1\n'
'Copyright FUJITSU LIMITED 2019',
'4.0.0'),
# Fortran compiler
('frt (FRT) 4.0.0 20190314\n'
'Copyright FUJITSU LIMITED 2019',
'4.0.0')
])
def test_arm_version_detection(version_str, expected_version):
version = spack.compilers.arm.Arm.extract_version_from_output(version_str)
def test_fj_version_detection(version_str, expected_version):
version = spack.compilers.fj.Fj.extract_version_from_output(version_str)
assert version == expected_version
@@ -454,37 +584,6 @@ def test_xl_version_detection(version_str, expected_version):
assert version == expected_version
@pytest.mark.parametrize('version_str,expected_version', [
('Cray C : Version 8.4.6 Mon Apr 15, 2019 12:13:39\n', '8.4.6'),
('Cray C++ : Version 8.4.6 Mon Apr 15, 2019 12:13:45\n', '8.4.6'),
('Cray Fortran : Version 8.4.6 Mon Apr 15, 2019 12:13:55\n', '8.4.6')
])
def test_cce_version_detection(version_str, expected_version):
version = spack.compilers.cce.Cce.extract_version_from_output(version_str)
assert version == expected_version
@pytest.mark.parametrize('version_str,expected_version', [
# C compiler
('fcc (FCC) 4.0.0 20190314\n'
'simulating gcc version 6.1\n'
'Copyright FUJITSU LIMITED 2019',
'4.0.0'),
# C++ compiler
('FCC (FCC) 4.0.0 20190314\n'
'simulating gcc version 6.1\n'
'Copyright FUJITSU LIMITED 2019',
'4.0.0'),
# Fortran compiler
('frt (FRT) 4.0.0 20190314\n'
'Copyright FUJITSU LIMITED 2019',
'4.0.0')
])
def test_fj_version_detection(version_str, expected_version):
version = spack.compilers.fj.Fj.extract_version_from_output(version_str)
assert version == expected_version
@pytest.mark.parametrize('compiler_spec,expected_result', [
('gcc@4.7.2', False), ('clang@3.3', False), ('clang@8.0.0', True)
])