https://sourceware.org/bugzilla/show_bug.cgi?id=33198
--- Comment #7 from Sam James <sam at gentoo dot org> ---
(In reply to H.J. Lu from comment #6)
> (In reply to Sam James from comment #4)
> > (In reply to H.J. Lu from comment #2)
> >
> > + if [info exists CLANG_FOR_TARGET] then {
> > + set llvm_plug_so [string trim [exec $CLANG_FOR_TARGET
> > -print-file-name=LLVMgold.so]]
> > + if { $llvm_plug_so ne "LLVMgold.so" } then {
> > + set llvm_plug_opt "--plugin $llvm_plug_so"
> > + }
> > + }
> >
> > This doesn't work for me:
> >
> > ```
> > $ clang -print-file-name=LLVMgold.so
> > LLVMgold.so
> >
> > $ ls -hal /usr/lib/llvm/20/lib64/LLVMgold.so
> > -rwxr-xr-x 1 root root 119K Jul 19 14:11 /usr/lib/llvm/20/lib64/LLVMgold.so
> > ```
> > => llvm_plug_opt is empty and then the test is UNTESTED unnecessarily.
> >
> > But we create the
> > /usr/x86_64-pc-linux-gnu/binutils-bin/lib/bfd-plugins/LLVMgold.so symlink to
> > /usr/lib/llvm/20/lib64/LLVMgold.so, so --plugin isn't needed.
> >
> > We can test it by creating a simple test program with clang -fuse-ld=bfd
> > foo.c. If it fails with:
> > ```
> > clang: error: no such file or directory:
> > '/usr/x86_64-pc-linux-gnu/binutils-bin/lib/bfd-plugins/LLVMgold.so'
> > ```
> >
> > Then --plugin is needed and we can use the existing test.
>
> Can you find a reliable way to locate LLVMgold.so from clang?
I don't think there's a way. We install LLVMgold.so to the default location its
CMake puts it and clang doesn't even look there. But it works because they pass
--plugin via some hardcoded CLANG_INSTALL_LIBDIR_BASENAME (which is not
queryable via clang, but you can get it with `llvm-config --libdir`):
```
const char *PluginPrefix = IsOSAIX ? "-bplugin:" : "";
const char *PluginName = IsOSAIX ? "/libLTO" : "/LLVMgold";
[...]
SmallString<1024> Plugin;
llvm::sys::path::native(Twine(D.Dir) +
"/../" CLANG_INSTALL_LIBDIR_BASENAME +
PluginName + Suffix,
Plugin);
```
I suggest:
1) Try `clang -print-file-name=libLLVM.so`. If it gives a path, use it.
2) Try build a test program with `clang -fuse-ld=bfd -flto main.c`. If the
plugin can't be found, it will error out.
3) Try `--plugin $(llvm-config --libdir)/LLVMgold.so` (I don't think we need
this step).
I will attach a patch.
--
You are receiving this mail because:
You are on the CC list for the bug.