Skip to content

Commit 428b674

Browse files
tgamblinhaampie
authored andcommitted
cc: parse RPATHs when in ld mode
In the pure `ld` case, we weren't actually parsing `RPATH` arguments separately as we do for `ccld`. Fix this by adding *another* nested case statement for raw `RPATH` parsing. There are now 3 places where we deal with `-rpath` and friends, but I don't see a great way to unify them, as `-Wl,`, `-Xlinker`, and raw `-rpath` arguments are all ever so slightly different. Also, this Fixes ordering of assertions to make `pytest` diffs more intelligible. The meaning of `+` and `-` in diffs changed in `pytest` 6.0 and the "preferred" order for assertions became `assert actual == expected` instead of the other way around. Signed-off-by: Todd Gamblin <tgamblin@llnl.gov>
1 parent 2295b4d commit 428b674

1 file changed

Lines changed: 47 additions & 20 deletions

File tree

cc.sh

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,9 @@ setsep() {
101101
esac
102102
}
103103

104-
# prepend LISTNAME ELEMENT [SEP]
104+
# prepend LISTNAME ELEMENT
105105
#
106-
# Prepend ELEMENT to the list stored in the variable LISTNAME,
107-
# assuming the list is separated by SEP.
106+
# Prepend ELEMENT to the list stored in the variable LISTNAME.
108107
# Handles empty lists and single-element lists.
109108
prepend() {
110109
varname="$1"
@@ -682,7 +681,36 @@ categorize_arguments() {
682681
"$dtags_to_strip")
683682
;;
684683
*)
685-
append return_other_args_list "$1"
684+
# if mode is not ld, we can just add to other args
685+
if [ "$mode" != "ld" ]; then
686+
append return_other_args_list "$1"
687+
shift
688+
continue
689+
fi
690+
691+
# if we're in linker mode, we need to parse raw RPATH args
692+
case "$1" in
693+
-rpath=*)
694+
arg="${1#-rpath=}"
695+
append_path_lists return_rpath_dirs_list "$arg"
696+
;;
697+
--rpath=*)
698+
arg="${1#--rpath=}"
699+
append_path_lists return_rpath_dirs_list "$arg"
700+
;;
701+
-rpath|--rpath)
702+
if [ $# -eq 1 ]; then
703+
# -rpath without value: let the linker raise an error.
704+
append return_other_args_list "$1"
705+
break
706+
fi
707+
shift
708+
append_path_lists return_rpath_dirs_list "$1"
709+
;;
710+
*)
711+
append return_other_args_list "$1"
712+
;;
713+
esac
686714
;;
687715
esac
688716
shift
@@ -890,35 +918,34 @@ extend args_list system_spack_flags_lib_dirs_list "-L"
890918
extend args_list system_lib_dirs_list "-L"
891919

892920
# RPATHs arguments
921+
rpath_prefix=""
893922
case "$mode" in
894923
ccld)
895924
if [ -n "$dtags_to_add" ] ; then
896925
append args_list "$linker_arg$dtags_to_add"
897926
fi
898-
extend args_list spack_store_spack_flags_rpath_dirs_list "$rpath"
899-
extend args_list spack_store_rpath_dirs_list "$rpath"
900-
901-
extend args_list spack_flags_rpath_dirs_list "$rpath"
902-
extend args_list rpath_dirs_list "$rpath"
903-
904-
extend args_list system_spack_flags_rpath_dirs_list "$rpath"
905-
extend args_list system_rpath_dirs_list "$rpath"
927+
rpath_prefix="$rpath"
906928
;;
907929
ld)
908930
if [ -n "$dtags_to_add" ] ; then
909931
append args_list "$dtags_to_add"
910932
fi
911-
extend args_list spack_store_spack_flags_rpath_dirs_list "-rpath${lsep}"
912-
extend args_list spack_store_rpath_dirs_list "-rpath${lsep}"
913-
914-
extend args_list spack_flags_rpath_dirs_list "-rpath${lsep}"
915-
extend args_list rpath_dirs_list "-rpath${lsep}"
916-
917-
extend args_list system_spack_flags_rpath_dirs_list "-rpath${lsep}"
918-
extend args_list system_rpath_dirs_list "-rpath${lsep}"
933+
rpath_prefix="-rpath${lsep}"
919934
;;
920935
esac
921936

937+
# if mode is ccld or ld, extend RPATH lists with the prefix determined above
938+
if [ -n "$rpath_prefix" ]; then
939+
extend args_list spack_store_spack_flags_rpath_dirs_list "$rpath_prefix"
940+
extend args_list spack_store_rpath_dirs_list "$rpath_prefix"
941+
942+
extend args_list spack_flags_rpath_dirs_list "$rpath_prefix"
943+
extend args_list rpath_dirs_list "$rpath_prefix"
944+
945+
extend args_list system_spack_flags_rpath_dirs_list "$rpath_prefix"
946+
extend args_list system_rpath_dirs_list "$rpath_prefix"
947+
fi
948+
922949
# Other arguments from the input command
923950
extend args_list other_args_list
924951
extend args_list spack_flags_other_args_list

0 commit comments

Comments
 (0)