libLLVMgold.so: could not load plugin library

Hi there,

I checked out the latest code from the repository, and wanna use the gold plugin, but I got the following:

libLLVMgold.so: could not load plugin library

Do you know why this is happening?

Also I noticed the name of the library is changed to LLVMgold.so, and I just renamed it to libLLVMgold.so when I copied it. Is this the right thing to do?

Thanks,
Guoliang

Hi there,

I checked out the latest code from the repository, and wanna use the gold
plugin, but I got the following:

libLLVMgold.so: could not load plugin library

Do you know why this is happening?

Also I noticed the name of the library is changed to LLVMgold.so, and I just
renamed it to libLLVMgold.so when I copied it. Is this the right thing to
do?

The library is now named LLVMgold.so, I probably forgot to update some
documentation, didn't I :frowning:

Copying it should cause no problems. just make sure libLTO.so is in a
place it can find. What happens if you run ldd on LLVMgold.so?

Thanks,
Guoliang

Cheers,

  Hi there,

I checked out the latest code from the repository, and wanna use the gold
plugin, but I got the following:

libLLVMgold.so: could not load plugin library

Do you know why this is happening?

Also I noticed the name of the library is changed to LLVMgold.so, and I just
renamed it to libLLVMgold.so when I copied it. Is this the right thing to
do?

The library is now named LLVMgold.so, I probably forgot to update some
documentation, didn't I :frowning:

So when I copy it to $PREFIX/libexec/gcc/x86_64-unknown-linux-gnu/4.2.1/ and $PREFIX/lib/bfd-plugins/, should I rename it to libLLVMgold.so? Any other copies I should make?

Copying it should cause no problems. just make sure libLTO.so is in a
place it can find. What happens if you run ldd on LLVMgold.so?

Here is the result:
ldd $LLVMPREFIX/lib/LLVMgold.so
     linux-gate.so.1 => (0x006fa000)
     libLTO.so => $LLVMPREFI/lib/libLTO.so (0x00f24000)
     libpthread.so.0 => /lib/libpthread.so.0 (0x00570000)
     libdl.so.2 => /lib/libdl.so.2 (0x00c4c000)
     libstdc++.so.6 => /s/gcc-4.3.1/i386_rhel5/lib/libstdc++.so.6 (0x001f0000)
     libm.so.6 => /lib/libm.so.6 (0x00153000)
     libgcc_s.so.1 => /s/gcc-4.3.1/i386_rhel5/lib/libgcc_s.so.1 (0x00675000)
     libc.so.6 => /lib/libc.so.6 (0x002db000)
     /lib/ld-linux.so.2 (0x00f07000)

So when I copy it to $PREFIX/libexec/gcc/x86_64-unknown-linux-gnu/4.2.1/ and
$PREFIX/lib/bfd-plugins/, should I rename it to libLLVMgold.so? Any other
copies I should make?

The copy in that directory can have any name you like. BFD will try
all. Note that
that is the copy that nm and ar will use. The linker (gold) requires you to pass
-plugin to it.

Copying it should cause no problems. just make sure libLTO.so is in a
place it can find. What happens if you run ldd on LLVMgold.so?

Here is the result:
ldd $LLVMPREFIX/lib/LLVMgold.so
linux-gate.so.1 => (0x006fa000)
libLTO.so => $LLVMPREFI/lib/libLTO.so (0x00f24000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00570000)
libdl.so.2 => /lib/libdl.so.2 (0x00c4c000)
libstdc++.so.6 => /s/gcc-4.3.1/i386_rhel5/lib/libstdc++.so.6 (0x001f0000)
libm.so.6 => /lib/libm.so.6 (0x00153000)
libgcc_s.so.1 => /s/gcc-4.3.1/i386_rhel5/lib/libgcc_s.so.1 (0x00675000)
libc.so.6 => /lib/libc.so.6 (0x002db000)
/lib/ld-linux.so.2 (0x00f07000)

Looks like it found libLTO. Another case I have seen is when the
plugin is linked with a different libstdc++ than gold. Is that the
case? You do have libstdc++ in an unusual location...

Cheers,

The linker (gold) requires you to pass -plugin to it.

I am using the command:
llvm-gcc a.c -emit-llvm -use-gold-plugin
and here is the output:
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld: error: $LLVMGCCPREFIX/libexec/gcc/i686-pc-linux-gnu/4.2.1/libLLVMgold.so: could not load plugin library
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld: error: /tmp/ccur7bJG.o:1:3: invalid character
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld: error: /tmp/ccur7bJG.o:1:3: syntax error, unexpected $end
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld: error: /tmp/ccur7bJG.o: not an object or archive
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld: /usr/lib/crt1.o:(.text+0x18): error: undefined reference to 'main'
collect2: ld returned 1 exit status

Did I use the wrong options?

Here is the result:
ldd $LLVMPREFIX/lib/LLVMgold.so
    linux-gate.so.1 => (0x006fa000)
    libLTO.so => $LLVMPREFI/lib/libLTO.so (0x00f24000)
    libpthread.so.0 => /lib/libpthread.so.0 (0x00570000)
    libdl.so.2 => /lib/libdl.so.2 (0x00c4c000)
    libstdc++.so.6 => /s/gcc-4.3.1/i386_rhel5/lib/libstdc++.so.6 (0x001f0000)
    libm.so.6 => /lib/libm.so.6 (0x00153000)
    libgcc_s.so.1 => /s/gcc-4.3.1/i386_rhel5/lib/libgcc_s.so.1 (0x00675000)
    libc.so.6 => /lib/libc.so.6 (0x002db000)
    /lib/ld-linux.so.2 (0x00f07000)

Looks like it found libLTO. Another case I have seen is when the
plugin is linked with a different libstdc++ than gold. Is that the
case? You do have libstdc++ in an unusual location...

ldd $LLVMGCCPREFIX/bin/ld
     linux-gate.so.1 => (0x0057c000)
     libdl.so.2 => /lib/libdl.so.2 (0x00bfa000)
     libz.so.1 => /usr/lib/libz.so.1 (0x00dae000)
     libstdc++.so.6 => /s/gcc-4.3.1/i386_rhel5/lib/libstdc++.so.6 (0x006c6000)
     libm.so.6 => /lib/libm.so.6 (0x00822000)
     libgcc_s.so.1 => /s/gcc-4.3.1/i386_rhel5/lib/libgcc_s.so.1 (0x004e0000)
     libc.so.6 => /lib/libc.so.6 (0x00110000)
     /lib/ld-linux.so.2 (0x0051a000)

So the gold and the LLVMgold are linked against the same libstdc++. I am using the gcc at /s/gcc-4.3.1/i386_rhel5/bin to compile the LLVM chain.

Thanks.

Did I use the wrong options?

That looks correct, the issues is really why gold is failing to load the plugin.

So the gold and the LLVMgold are linked against the same libstdc++. I am
using the gcc at /s/gcc-4.3.1/i386_rhel5/bin to compile the LLVM chain.

Can you run llvm-gcc again with -Wl,-debug? This will show the linker
line being used. You can then run gdb on it. Try to find what error is
dlopen reporting. I wonder if gold is calling perror or not when
dlopen fails (assuming it is dlopen that is failing).

Thanks.

Cheers,

The -Wl,-debug result is like this:
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld -plugin $LLVMGCCPREFIX/libexec/gcc/i686-pc-linux-gnu/4.2.1/libLLVMgold.so -plugin-opt=as=as --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o $LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/crtbegin.o -L$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1 -L$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../.. /tmp/ccnyauaa.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed $LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/crtend.o /usr/lib/crtn.o
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld: error: $LLVMGCCPREFIX/libexec/gcc/i686-pc-linux-gnu/4.2.1/libLLVMgold.so: could not load plugin library
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld: error: /tmp/ccnyauaa.o:1:3: invalid character
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld: error: /tmp/ccnyauaa.o:1:3: syntax error, unexpected $end
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld: error: /tmp/ccnyauaa.o: not an object or archive
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld: /usr/lib/crt1.o:(.text+0x18): error: undefined reference to 'main'

What should I do on gdb?

The -Wl,-debug result is like this:
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld
-plugin $LLVMGCCPREFIX/libexec/gcc/i686-pc-linux-gnu/4.2.1/libLLVMgold.so
-plugin-opt=as=as --eh-frame-hdr -m elf_i386 -dynamic-linker
/lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/crtbegin.o
-L$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1
-L$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../.. /tmp/ccnyauaa.o
-lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s
--no-as-needed $LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/crtend.o
/usr/lib/crtn.o
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld:
error: $LLVMGCCPREFIX/libexec/gcc/i686-pc-linux-gnu/4.2.1/libLLVMgold.so:
could not load plugin library
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld:
error: /tmp/ccnyauaa.o:1:3: invalid character
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld:
error: /tmp/ccnyauaa.o:1:3: syntax error, unexpected $end
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld:
error: /tmp/ccnyauaa.o: not an object or archive
$LLVMGCCPREFIX/lib/gcc/i686-pc-linux-gnu/4.2.1/../../../../i686-pc-linux-gnu/bin/ld:
/usr/lib/crt1.o:(.text+0x18): error: undefined reference to 'main'

What should I do on gdb?

Try to run just that ld command first. Same error message? Run in in
gdb and set a breakpoint just before gold tries to load the plugin.
Sorry, I am really out of ideas on what is going wrong here...

Cheers,

It is the same error message .

Can you tell me which gcc version are you using to compile the llvm chain, and also the binutils svn version number?

I noticed the dlopen is inside /lib/ld-linux.so.2, and my version of glibc is 2.5, is this too old?

Thanks.

It is the same error message .

Can you tell me which gcc version are you using to compile the llvm chain,
and also the binutils svn version number?

I have used both gcc 4.2 and 4.4.

I noticed the dlopen is inside /lib/ld-linux.so.2, and my version of glibc
is 2.5, is this too old?

I don't think that is the problem. I have just posted a patch to gold

http://sourceware.org/ml/binutils/2010-06/msg00310.html

That should print more complete error messages. Can you give that a
try? That is what I was going to ask you to try with gdb, but it is
probably easier to juts apply that patch and build gold.

Thanks.

Cheers,

The error msg is:
libLTO.so: cannot open shared object file: No such file or directory

I copied one into $PREFIX/libexec/gcc/x86_64-unknown-linux-gnu/4.2.1/ and it now works.

Thanks.