Repository navigation
Description
When setting ldlibs for a package or compiler, the link flags are injected by the wrapper script after the flags from the input command. This is different than all other injectable flags (e.g. cflags, cxxflags, ldflags, etc.) and can cause the wrong library to be used when the injected one is intended to override another library.
For example, below I want to install libxml2 while overriding functions from the standard libm with AMD's optimized versions, in libalm. However, -lalm is ordered after -lm; this causes functions in libm to be preferred, which is not what is intended.
Steps to reproduce the issue
$ spack install libxml2 %aocc ldlibs='-lalm'
...
$ ldd "$(spack location -i libxml2 %aocc ldlibs='-lalm')/lib/libxml2.so"
linux-vdso.so.1 (0x0000155555551000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000155554c97000)
libz.so.1 => /home/omor1/spack/opt/spack/linux-centos8-zen2/aocc-3.0.0/zlib-1.2.11-omq2fsz3fi4zex2xa2yj2lvluixsyk6x/lib/libz.so.1 (0x000015555538d000)
liblzma.so.5 => /home/omor1/spack/opt/spack/linux-centos8-zen2/aocc-3.0.0/xz-5.2.5-enj5mygu7xn3l4wdsuzmpqmwezveumh6/lib/liblzma.so.5 (0x0000155555364000)
libiconv.so.2 => /home/omor1/spack/opt/spack/linux-centos8-zen2/aocc-3.0.0/libiconv-1.16-x7c5xwvmdon6mhug7dwmu5eqlpzyicqe/lib/libiconv.so.2 (0x0000155554b9b000)
libm.so.6 => /lib64/libm.so.6 (0x0000155554e9b000)
libalm.so => /home/omor1/spack/opt/spack/linux-centos8-zen/gcc-8.3.1/aocc-3.0.0-4tflgtbenvsdjuq4nzlb5n2zmvlmxf6y/lib/libalm.so (0x000015555521d000)
libc.so.6 => /lib64/libc.so.6 (0x00001555547d8000)
/lib64/ld-linux-x86-64.so.2 (0x000015555532b000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00001555545b8000)Information on your system
$ spack debug report
* **Spack:** 0.16.1-2358-91845956ba
* **Python:** 3.9.4
* **Platform:** linux-centos8-zen2
* **Concretizer:** originalcompilers.yaml
compilers:
- compiler:
spec: gcc@8.3.1
paths:
cc: /usr/bin/gcc
cxx: /usr/bin/g++
f77: /usr/bin/gfortran
fc: /usr/bin/gfortran
flags:
cflags: -O2
cxxflags: -O2
fflags: -O2
operating_system: centos8
target: x86_64
modules: []
environment: {}
extra_rpaths: []
- compiler:
spec: aocc@3.0.0
paths:
cc: /home/omor1/spack/opt/spack/linux-centos8-zen/gcc-8.3.1/aocc-3.0.0-4tflgtbenvsdjuq4nzlb5n2zmvlmxf6y/bin/clang
cxx: /home/omor1/spack/opt/spack/linux-centos8-zen/gcc-8.3.1/aocc-3.0.0-4tflgtbenvsdjuq4nzlb5n2zmvlmxf6y/bin/clang++
f77: /home/omor1/spack/opt/spack/linux-centos8-zen/gcc-8.3.1/aocc-3.0.0-4tflgtbenvsdjuq4nzlb5n2zmvlmxf6y/bin/flang
fc: /home/omor1/spack/opt/spack/linux-centos8-zen/gcc-8.3.1/aocc-3.0.0-4tflgtbenvsdjuq4nzlb5n2zmvlmxf6y/bin/flang
flags:
cflags: -O2 -fveclib=AMDLIBM -Wno-unused-command-line-argument -mllvm -eliminate-similar-expr=false
cxxflags: -O2 -fveclib=AMDLIBM -Wno-unused-command-line-argument -mllvm -eliminate-similar-expr=false
fflags: -O2 -fveclib=AMDLIBM -Wno-unused-command-line-argument -mllvm -eliminate-similar-expr=false
ldlibs: -lalm -lm
operating_system: centos8
target: x86_64
modules: []
environment: {}
extra_rpaths: []Additional information
- I have run
spack debug reportand reported the version of Spack/Python/Platform - I have searched the issues of this repo and believe this is not a duplicate
- I have run the failing commands in debug mode and reported the output
Solutions
If this ordering is needed, passing the flags in ldflags instead of ldlibs might be sufficient. The proper solution is to inject SPACK_LDLIBS before the input flags in the cc script:
diff --git a/lib/spack/env/cc b/lib/spack/env/cc
index 4d8c4644cb..7ffac0c90c 100755
--- a/lib/spack/env/cc
+++ b/lib/spack/env/cc
@@ -545,14 +555,14 @@ case "$mode" in
;;
esac
-# Other arguments from the input command
-args+=("${other_args[@]}")
-
# Inject SPACK_LDLIBS, if supplied
for lib in "${libs[@]}"; do
args+=("-l$lib");
done
+# Other arguments from the input command
+args+=("${other_args[@]}")
+
full_command=("$command" "${args[@]}")However, I'm concerned this might cause other, hidden issues that might be hard to debug later—in some use cases, at least. Maybe providing an alternative override_ldlibs parameter might be useful for making this use case clear?
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTodo
Activity
omor1 commentedon Apr 30, 2021
As an alternative, it's possible to parse
other_argsand injectSPACK_LDLIBSright any of its own libs i.e. stop before any-largs in-other_args, injectSPACK_LDLIBS, and then resume adding the remainder ofother_args.