Description
Describe the bug
When compiling a project using Clang, I am unable to use link-time optimization (LTO) due to the absence of /usr/lib/LLVMgold.so.
LLVMgold.so is a a linker plugin which is part of the LLVM/Clang project itself. It acts as "glue" between the Clang compiler driver and GNU gold
, which is used to perform the actual linking when LTO is enabled. More information here:
https://llvm.org/docs/GoldPlugin.html
LLVMgold.so appears to be missing from Mariner's clang
package. Based on my reading of the spec files and LLVM's CMake files, I believe this is because LLVM_BINUTILS_INCDIR is not being specified at the time LLVM/Clang is built.
Proposed fix:
- If it isn't already, list the
binutils
package (which provides GNU gold) as a build-time dependency of theclang
package (orllvm
package, not sure which?) - Update the build spec for
clang
and/orllvm
to specify LLVM_BINUTILS_INCDIR on the CMake command line
To Reproduce
Steps to reproduce the behavior:
$ cat <<EOF > test_lto.c
> #include <stdio.h>
> int main(void) {
> printf("hello, with lto\n");
> return 0;
> }
> EOF
$ clang -flto test_lto.c -o test_lto
/usr/bin/ld: /usr/bin/../lib/LLVMgold.so: error loading plugin: /usr/bin/../lib/LLVMgold.so: cannot open shared object file: No such file or directory
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
Expected behavior
Clang should compile and link the program without error, using LTO.
Next steps
Please advise whether the proposed fix above makes sense, or whether there is some additional context as to why this does not work.
If this seems okay, I am happy to submit a PR with these changes.