bugfix: cc should not add -L or -Wl,-rpath in compile-only mode
- Adding -L and -Wl,-rpath to compile-only command lines ("cc mode" or "-c") causes clang (if not also other compilers) to emit warnings that confuse configure systems. - Clang will print warnings about unused command-line arguments. - This fix ensures that -L and -Wl,-rpath are not added if the compile line is just building an object file with -c - This also cleans up the cc script in several places.
This commit is contained in:
parent
683c7fbf3b
commit
c8fb9b5479
120
lib/spack/env/cc
vendored
120
lib/spack/env/cc
vendored
@ -137,10 +137,12 @@ esac
|
|||||||
# libraries.
|
# libraries.
|
||||||
if [[ -z $mode ]] || [[ $mode == ld ]]; then
|
if [[ -z $mode ]] || [[ $mode == ld ]]; then
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
if [[ $arg == -v || $arg == -V || $arg == --version || $arg == -dumpversion ]]; then
|
case $arg in
|
||||||
|
-v|-V|--version|-dumpversion)
|
||||||
mode=vcheck
|
mode=vcheck
|
||||||
break
|
break
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -164,7 +166,7 @@ fi
|
|||||||
# Set up rpath variable according to language.
|
# Set up rpath variable according to language.
|
||||||
eval rpath=\$SPACK_${comp}_RPATH_ARG
|
eval rpath=\$SPACK_${comp}_RPATH_ARG
|
||||||
|
|
||||||
# Dump the version and exit if we're in testing mode.
|
# Dump the mode and exit if the command is dump-mode.
|
||||||
if [[ $SPACK_TEST_COMMAND == dump-mode ]]; then
|
if [[ $SPACK_TEST_COMMAND == dump-mode ]]; then
|
||||||
echo "$mode"
|
echo "$mode"
|
||||||
exit
|
exit
|
||||||
@ -218,9 +220,12 @@ fi
|
|||||||
# It doesn't work with -rpath.
|
# It doesn't work with -rpath.
|
||||||
# This variable controls whether they are added.
|
# This variable controls whether they are added.
|
||||||
add_rpaths=true
|
add_rpaths=true
|
||||||
if [[ ($mode == ld || $mode == ccld) && "$SPACK_SHORT_SPEC" =~ "darwin" ]]; then
|
if [[ ($mode == ld || $mode == ccld) && "$SPACK_SHORT_SPEC" =~ "darwin" ]];
|
||||||
|
then
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
if [[ ($arg == -r && $mode == ld) || ($arg == -r && $mode == ccld) || ($arg == -Wl,-r && $mode == ccld) ]]; then
|
if [[ ($arg == -r && $mode == ld) ||
|
||||||
|
($arg == -r && $mode == ccld) ||
|
||||||
|
($arg == -Wl,-r && $mode == ccld) ]]; then
|
||||||
add_rpaths=false
|
add_rpaths=false
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
@ -232,16 +237,21 @@ input_command="$@"
|
|||||||
args=()
|
args=()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Parse the command line args, trying hard to keep
|
# Parse the command line arguments.
|
||||||
# non-rpath linker arguments in the proper order w.r.t. other command
|
|
||||||
# line arguments. This is important for things like groups.
|
|
||||||
#
|
#
|
||||||
# -l arguments are treated as 'other_args' to ensure that they stay in
|
# We extract -L, -I, and -Wl,-rpath arguments from the command line and
|
||||||
# any groups they are a part of. Dependency library -l statements are
|
# recombine them with Spack arguments later. We parse these out so that
|
||||||
# categorized as 'libs'
|
# we can make sure that system paths come last, that package arguments
|
||||||
|
# come first, and that Spack arguments are injected properly.
|
||||||
#
|
#
|
||||||
# The various categories will be recombined with compiler flags into
|
# All other arguments, including -l arguments, are treated as
|
||||||
# args variable later.
|
# 'other_args' and left in their original order. This ensures that
|
||||||
|
# --start-group, --end-group, and other order-sensitive flags continue to
|
||||||
|
# work as the caller expects.
|
||||||
|
#
|
||||||
|
# The libs variable is initialized here for completeness, and it is also
|
||||||
|
# used later to inject flags supplied via `ldlibs` on the command
|
||||||
|
# line. These come into the wrappers via SPACK_LDLIBS.
|
||||||
#
|
#
|
||||||
includes=()
|
includes=()
|
||||||
libdirs=()
|
libdirs=()
|
||||||
@ -316,7 +326,10 @@ while [ -n "$1" ]; do
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
# Prepend cppflags, cflags, cxxflags, fcflags, fflags, and ldflags
|
#
|
||||||
|
# Prepend flags from Spack's cppflags, cflags, cxxflags, fcflags, fflags,
|
||||||
|
# and ldflags.
|
||||||
|
#
|
||||||
|
|
||||||
# Add ldflags
|
# Add ldflags
|
||||||
case "$mode" in
|
case "$mode" in
|
||||||
@ -324,15 +337,16 @@ case "$mode" in
|
|||||||
args=(${SPACK_LDFLAGS[@]} "${args[@]}") ;;
|
args=(${SPACK_LDFLAGS[@]} "${args[@]}") ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Add compiler flags.
|
# Add C, C++, and Fortran flags
|
||||||
case "$mode" in
|
case "$mode" in
|
||||||
cc|ccld)
|
cc|ccld)
|
||||||
# Add c, cxx, fc, and f flags
|
|
||||||
case $lang_flags in
|
case $lang_flags in
|
||||||
C)
|
C)
|
||||||
args=(${SPACK_CFLAGS[@]} "${args[@]}") ;;
|
args=(${SPACK_CFLAGS[@]} "${args[@]}") ;;
|
||||||
CXX)
|
CXX)
|
||||||
args=(${SPACK_CXXFLAGS[@]} "${args[@]}") ;;
|
args=(${SPACK_CXXFLAGS[@]} "${args[@]}") ;;
|
||||||
|
F)
|
||||||
|
args=(${SPACK_FFLAGS[@]} "${args[@]}") ;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -343,30 +357,29 @@ case "$mode" in
|
|||||||
args=(${SPACK_CPPFLAGS[@]} "${args[@]}") ;;
|
args=(${SPACK_CPPFLAGS[@]} "${args[@]}") ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$mode" in cc|ccld)
|
# Include all -L's and prefix/whatever dirs in rpath
|
||||||
# Add fortran flags
|
case "$mode" in
|
||||||
case $lang_flags in
|
ld|ccld)
|
||||||
F)
|
$add_rpaths && rpaths+=("$SPACK_PREFIX/lib")
|
||||||
args=(${SPACK_FFLAGS[@]} "${args[@]}") ;;
|
$add_rpaths && rpaths+=("$SPACK_PREFIX/lib64")
|
||||||
esac
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Include all -L's and prefix/whatever dirs in rpath
|
|
||||||
$add_rpaths && rpaths+=("$SPACK_PREFIX/lib")
|
|
||||||
$add_rpaths && rpaths+=("$SPACK_PREFIX/lib64")
|
|
||||||
|
|
||||||
# Read spack dependencies from the path environment variable
|
# Read spack dependencies from the path environment variable
|
||||||
IFS=':' read -ra deps <<< "$SPACK_DEPENDENCIES"
|
IFS=':' read -ra deps <<< "$SPACK_DEPENDENCIES"
|
||||||
for dep in "${deps[@]}"; do
|
for dep in "${deps[@]}"; do
|
||||||
# Append include directories
|
# Append include directories
|
||||||
|
case "$mode" in
|
||||||
|
cpp|cc|as|ccld)
|
||||||
if [[ -d $dep/include ]]; then
|
if [[ -d $dep/include ]]; then
|
||||||
if [[ $mode == cpp || $mode == cc || $mode == as || $mode == ccld ]]; then
|
|
||||||
includes=("${includes[@]}" "$dep/include")
|
includes=("${includes[@]}" "$dep/include")
|
||||||
fi
|
fi
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
# Append lib and RPATH directories
|
# Append lib/lib64 and RPATH directories
|
||||||
|
case "$mode" in
|
||||||
|
ld|ccld)
|
||||||
if [[ -d $dep/lib ]]; then
|
if [[ -d $dep/lib ]]; then
|
||||||
if [[ $SPACK_RPATH_DEPS == *$dep* ]]; then
|
if [[ $SPACK_RPATH_DEPS == *$dep* ]]; then
|
||||||
$add_rpaths && rpaths=("${rpaths[@]}" "$dep/lib")
|
$add_rpaths && rpaths=("${rpaths[@]}" "$dep/lib")
|
||||||
@ -376,7 +389,6 @@ for dep in "${deps[@]}"; do
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Append lib64 and RPATH directories
|
|
||||||
if [[ -d $dep/lib64 ]]; then
|
if [[ -d $dep/lib64 ]]; then
|
||||||
if [[ $SPACK_RPATH_DEPS == *$dep* ]]; then
|
if [[ $SPACK_RPATH_DEPS == *$dep* ]]; then
|
||||||
$add_rpaths && rpaths+=("$dep/lib64")
|
$add_rpaths && rpaths+=("$dep/lib64")
|
||||||
@ -385,21 +397,24 @@ for dep in "${deps[@]}"; do
|
|||||||
libdirs+=("$dep/lib64")
|
libdirs+=("$dep/lib64")
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Set extra RPATHs
|
|
||||||
IFS=':' read -ra extra_rpaths <<< "$SPACK_COMPILER_EXTRA_RPATHS"
|
|
||||||
for extra_rpath in "${extra_rpaths[@]}"; do
|
|
||||||
$add_rpaths && rpaths+=("$extra_rpath")
|
|
||||||
libdirs+=("$extra_rpath")
|
|
||||||
done
|
|
||||||
|
|
||||||
# Add SPACK_LDLIBS to args
|
|
||||||
case "$mode" in
|
case "$mode" in
|
||||||
ld|ccld)
|
ld|ccld)
|
||||||
|
# Set extra RPATHs
|
||||||
|
IFS=':' read -ra extra_rpaths <<< "$SPACK_COMPILER_EXTRA_RPATHS"
|
||||||
|
for extra_rpath in "${extra_rpaths[@]}"; do
|
||||||
|
$add_rpaths && rpaths+=("$extra_rpath")
|
||||||
|
libdirs+=("$extra_rpath")
|
||||||
|
done
|
||||||
|
|
||||||
|
# Add SPACK_LDLIBS to args
|
||||||
for lib in ${SPACK_LDLIBS[@]}; do
|
for lib in ${SPACK_LDLIBS[@]}; do
|
||||||
libs+=("${lib#-l}")
|
libs+=("${lib#-l}")
|
||||||
done
|
done
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Filter system locations to the end of each sublist of args
|
# Filter system locations to the end of each sublist of args
|
||||||
@ -419,13 +434,18 @@ for sd in ${SPACK_SYSTEM_DIRS[@]}; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Put the arguments together into one list
|
# Put the arguments back together in one list
|
||||||
# Includes come first, then other args, library dirs, and rpaths
|
# Includes first
|
||||||
# rpaths get appropriate flag for ld vs ccld mode
|
for dir in "${includes[@]}"; do
|
||||||
for dir in "${includes[@]}"; do args+=("-I$dir"); done
|
args+=("-I$dir");
|
||||||
args+=("${other_args[@]}")
|
done
|
||||||
for dir in "${libdirs[@]}"; do args+=("-L$dir"); done
|
|
||||||
for lib in "${libs[@]}"; do args+=("-l$lib"); done
|
# Library search paths
|
||||||
|
for dir in "${libdirs[@]}"; do
|
||||||
|
args+=("-L$dir");
|
||||||
|
done
|
||||||
|
|
||||||
|
# RPATHs arguments
|
||||||
if [ "$mode" = ccld ]; then
|
if [ "$mode" = ccld ]; then
|
||||||
for dir in "${rpaths[@]}"; do
|
for dir in "${rpaths[@]}"; do
|
||||||
args+=("$rpath$dir")
|
args+=("$rpath$dir")
|
||||||
@ -436,10 +456,18 @@ elif [ "$mode" = ld ]; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Other arguments from the input command
|
||||||
|
args+=("${other_args[@]}")
|
||||||
|
|
||||||
|
# Inject SPACK_LDLIBS, if supplied
|
||||||
|
for lib in "${libs[@]}"; do
|
||||||
|
args+=("-l$lib");
|
||||||
|
done
|
||||||
|
|
||||||
full_command=("$command")
|
full_command=("$command")
|
||||||
full_command+=("${args[@]}")
|
full_command+=("${args[@]}")
|
||||||
|
|
||||||
# In test command mode, write out full command for Spack tests.
|
# dump the full command if the caller supplies SPACK_TEST_COMMAND=dump-args
|
||||||
if [[ $SPACK_TEST_COMMAND == dump-args ]]; then
|
if [[ $SPACK_TEST_COMMAND == dump-args ]]; then
|
||||||
echo "${full_command[@]}"
|
echo "${full_command[@]}"
|
||||||
exit
|
exit
|
||||||
|
Loading…
Reference in New Issue
Block a user