diff options
author | Harmen Stoppels <me@harmenstoppels.nl> | 2024-04-26 09:19:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-26 09:19:03 +0200 |
commit | d946c37cbb7a41acbb2b34fc98078acc96533705 (patch) | |
tree | f77b60d589ed51631eccc7c16c1b1c5b9b1e0b0f | |
parent | 47a9f0bdf712b2d2c36d867b016bf871dd6fa77f (diff) | |
download | spack-d946c37cbb7a41acbb2b34fc98078acc96533705.tar.gz spack-d946c37cbb7a41acbb2b34fc98078acc96533705.tar.bz2 spack-d946c37cbb7a41acbb2b34fc98078acc96533705.tar.xz spack-d946c37cbb7a41acbb2b34fc98078acc96533705.zip |
ldflags=* are compiler flags, not linker flags (#43820)
We run `extend spack_flags_list SPACK_LDFLAGS` for `$mode in ld|ccld`.
That's problematic, cause `ccld` needs `-Wl,--flag` whereas `ld` needs
`--flag` directly. Only `-L` and `-l` are common to compiler & linker.
In all build systems `LDFLAGS` is for the compiler not the linker, cause
any linker flag `-x` can be passed as a compiler flag `-Wl,-x`, and there
are many compiler flags that affect the linker invocation, like `-fopenmp`,
`-fuse-ld=`, `-fsanitize=` etc.
So don't pass `LDFLAGS` to the linker directly.
This way users can set `ldflags: -Wl,--allow-shlib-undefined` in compilers.yaml
to work around an issue where the linker tries to resolve the `libcuda.so.1`
stub lib which cannot be located by design in `cuda`.
-rwxr-xr-x | lib/spack/env/cc | 2 | ||||
-rw-r--r-- | lib/spack/spack/test/cc.py | 12 |
2 files changed, 8 insertions, 6 deletions
diff --git a/lib/spack/env/cc b/lib/spack/env/cc index 11b08f4752..ffaa9944df 100755 --- a/lib/spack/env/cc +++ b/lib/spack/env/cc @@ -755,7 +755,7 @@ esac # Linker flags case "$mode" in - ld|ccld) + ccld) extend spack_flags_list SPACK_LDFLAGS ;; esac diff --git a/lib/spack/spack/test/cc.py b/lib/spack/spack/test/cc.py index 4bd7bf5c3d..dfff73811a 100644 --- a/lib/spack/spack/test/cc.py +++ b/lib/spack/spack/test/cc.py @@ -127,7 +127,7 @@ spack_cppflags = ["-g", "-O1", "-DVAR=VALUE"] spack_cflags = ["-Wall"] spack_cxxflags = ["-Werror"] spack_fflags = ["-w"] -spack_ldflags = ["-L", "foo"] +spack_ldflags = ["-Wl,--gc-sections", "-L", "foo"] spack_ldlibs = ["-lfoo"] lheaderpad = ["-Wl,-headerpad_max_install_names"] @@ -279,7 +279,6 @@ def test_ld_flags(wrapper_environment, wrapper_flags): test_args, ["ld"] + test_include_paths - + [spack_ldflags[i] + spack_ldflags[i + 1] for i in range(0, len(spack_ldflags), 2)] + test_library_paths + ["--disable-new-dtags"] + test_rpaths @@ -307,13 +306,14 @@ def test_cc_flags(wrapper_environment, wrapper_flags): [real_cc] + target_args + test_include_paths - + [spack_ldflags[i] + spack_ldflags[i + 1] for i in range(0, len(spack_ldflags), 2)] + + ["-Lfoo"] + test_library_paths + ["-Wl,--disable-new-dtags"] + test_wl_rpaths + test_args_without_paths + spack_cppflags + spack_cflags + + ["-Wl,--gc-sections"] + spack_ldlibs, ) @@ -325,12 +325,13 @@ def test_cxx_flags(wrapper_environment, wrapper_flags): [real_cc] + target_args + test_include_paths - + [spack_ldflags[i] + spack_ldflags[i + 1] for i in range(0, len(spack_ldflags), 2)] + + ["-Lfoo"] + test_library_paths + ["-Wl,--disable-new-dtags"] + test_wl_rpaths + test_args_without_paths + spack_cppflags + + ["-Wl,--gc-sections"] + spack_ldlibs, ) @@ -342,13 +343,14 @@ def test_fc_flags(wrapper_environment, wrapper_flags): [real_cc] + target_args + test_include_paths - + [spack_ldflags[i] + spack_ldflags[i + 1] for i in range(0, len(spack_ldflags), 2)] + + ["-Lfoo"] + test_library_paths + ["-Wl,--disable-new-dtags"] + test_wl_rpaths + test_args_without_paths + spack_fflags + spack_cppflags + + ["-Wl,--gc-sections"] + spack_ldlibs, ) |