summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlib/spack/env/cc67
-rw-r--r--lib/spack/spack/test/cc.py39
2 files changed, 85 insertions, 21 deletions
diff --git a/lib/spack/env/cc b/lib/spack/env/cc
index 44f8b9316a..88969d3f30 100755
--- a/lib/spack/env/cc
+++ b/lib/spack/env/cc
@@ -101,10 +101,9 @@ setsep() {
esac
}
-# prepend LISTNAME ELEMENT [SEP]
+# prepend LISTNAME ELEMENT
#
-# Prepend ELEMENT to the list stored in the variable LISTNAME,
-# assuming the list is separated by SEP.
+# Prepend ELEMENT to the list stored in the variable LISTNAME.
# Handles empty lists and single-element lists.
prepend() {
varname="$1"
@@ -682,7 +681,36 @@ categorize_arguments() {
"$dtags_to_strip")
;;
*)
- append return_other_args_list "$1"
+ # if mode is not ld, we can just add to other args
+ if [ "$mode" != "ld" ]; then
+ append return_other_args_list "$1"
+ shift
+ continue
+ fi
+
+ # if we're in linker mode, we need to parse raw RPATH args
+ case "$1" in
+ -rpath=*)
+ arg="${1#-rpath=}"
+ append_path_lists return_rpath_dirs_list "$arg"
+ ;;
+ --rpath=*)
+ arg="${1#--rpath=}"
+ append_path_lists return_rpath_dirs_list "$arg"
+ ;;
+ -rpath|--rpath)
+ if [ $# -eq 1 ]; then
+ # -rpath without value: let the linker raise an error.
+ append return_other_args_list "$1"
+ break
+ fi
+ shift
+ append_path_lists return_rpath_dirs_list "$1"
+ ;;
+ *)
+ append return_other_args_list "$1"
+ ;;
+ esac
;;
esac
shift
@@ -890,35 +918,34 @@ extend args_list system_spack_flags_lib_dirs_list "-L"
extend args_list system_lib_dirs_list "-L"
# RPATHs arguments
+rpath_prefix=""
case "$mode" in
ccld)
if [ -n "$dtags_to_add" ] ; then
append args_list "$linker_arg$dtags_to_add"
fi
- extend args_list spack_store_spack_flags_rpath_dirs_list "$rpath"
- extend args_list spack_store_rpath_dirs_list "$rpath"
-
- extend args_list spack_flags_rpath_dirs_list "$rpath"
- extend args_list rpath_dirs_list "$rpath"
-
- extend args_list system_spack_flags_rpath_dirs_list "$rpath"
- extend args_list system_rpath_dirs_list "$rpath"
+ rpath_prefix="$rpath"
;;
ld)
if [ -n "$dtags_to_add" ] ; then
append args_list "$dtags_to_add"
fi
- extend args_list spack_store_spack_flags_rpath_dirs_list "-rpath${lsep}"
- extend args_list spack_store_rpath_dirs_list "-rpath${lsep}"
-
- extend args_list spack_flags_rpath_dirs_list "-rpath${lsep}"
- extend args_list rpath_dirs_list "-rpath${lsep}"
-
- extend args_list system_spack_flags_rpath_dirs_list "-rpath${lsep}"
- extend args_list system_rpath_dirs_list "-rpath${lsep}"
+ rpath_prefix="-rpath${lsep}"
;;
esac
+# if mode is ccld or ld, extend RPATH lists with the prefix determined above
+if [ -n "$rpath_prefix" ]; then
+ extend args_list spack_store_spack_flags_rpath_dirs_list "$rpath_prefix"
+ extend args_list spack_store_rpath_dirs_list "$rpath_prefix"
+
+ extend args_list spack_flags_rpath_dirs_list "$rpath_prefix"
+ extend args_list rpath_dirs_list "$rpath_prefix"
+
+ extend args_list system_spack_flags_rpath_dirs_list "$rpath_prefix"
+ extend args_list system_rpath_dirs_list "$rpath_prefix"
+fi
+
# Other arguments from the input command
extend args_list other_args_list
extend args_list spack_flags_other_args_list
diff --git a/lib/spack/spack/test/cc.py b/lib/spack/spack/test/cc.py
index 4a394680f4..f65bef9b01 100644
--- a/lib/spack/spack/test/cc.py
+++ b/lib/spack/spack/test/cc.py
@@ -199,7 +199,7 @@ def check_args(cc, args, expected):
"""
with set_env(SPACK_TEST_COMMAND="dump-args"):
cc_modified_args = cc(*args, output=str).strip().split("\n")
- assert expected == cc_modified_args
+ assert cc_modified_args == expected
def check_args_contents(cc, args, must_contain, must_not_contain):
@@ -272,6 +272,43 @@ def test_ld_mode(wrapper_environment):
assert dump_mode(ld, ["foo.o", "bar.o", "baz.o", "-o", "foo", "-Wl,-rpath,foo"]) == "ld"
+def test_ld_unterminated_rpath(wrapper_environment):
+ check_args(
+ ld,
+ ["foo.o", "bar.o", "baz.o", "-o", "foo", "-rpath"],
+ ["ld", "--disable-new-dtags", "foo.o", "bar.o", "baz.o", "-o", "foo", "-rpath"],
+ )
+
+
+def test_xlinker_unterminated_rpath(wrapper_environment):
+ check_args(
+ cc,
+ ["foo.o", "bar.o", "baz.o", "-o", "foo", "-Xlinker", "-rpath"],
+ [real_cc]
+ + target_args
+ + [
+ "-Wl,--disable-new-dtags",
+ "foo.o",
+ "bar.o",
+ "baz.o",
+ "-o",
+ "foo",
+ "-Xlinker",
+ "-rpath",
+ ],
+ )
+
+
+def test_wl_unterminated_rpath(wrapper_environment):
+ check_args(
+ cc,
+ ["foo.o", "bar.o", "baz.o", "-o", "foo", "-Wl,-rpath"],
+ [real_cc]
+ + target_args
+ + ["-Wl,--disable-new-dtags", "foo.o", "bar.o", "baz.o", "-o", "foo", "-Wl,-rpath"],
+ )
+
+
def test_ld_flags(wrapper_environment, wrapper_flags):
check_args(
ld,