Problem compiling with clang + gold plugin: no archive symbol table

I build llvm with gold plugin, clang and the binutils(and it’s put into the PATH) with plugins is renamed to ld. A quick test of clang -flto -O0 hello.c can succeed.
But when I try to export CC=“clang -v -flto” and compile MySQL, it failed in the linking with the following error message:

“/home/ryan/binutils/bin/ld” -export-dynamic -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ -o factorial /usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5/…/…/…/…/i386-linux-gnu/crt1.o /usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5/…/…/…/…/i386-linux-gnu/crti.o /usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5/crtbegin.o -L/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5 -L/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5/…/…/…/…/i386-linux-gnu -L/lib/i386-linux-gnu -L/usr/lib/i386-linux-gnu -L/usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5/…/…/…/… -L/lib -L/usr/lib -plugin /home/ryan/llvm-build/Debug+Asserts/bin/…/lib/ my_main.o factorial.o libdbug.a …/mysys/libmysys.a …/strings/libmystrings.a -lpthread -lcrypt -lnsl -lm -lpthread -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5/crtend.o /usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5/…/…/…/…/i386-linux-gnu/crtn.o
/home/ryan/binutils/bin/ld: error: libdbug.a: no archive symbol table (run ranlib)
/home/ryan/binutils/bin/ld: error: …/strings/libmystrings.a: no archive symbol table (run ranlib)
my_main.c:23: error: undefined reference to ‘my_thread_global_init’

This does not seem to be specific on MySQL, tested on httpd, also emit similar error messages:

/home/ryan/binutils/bin/ld: error: /tmp/httpd-2.2.22/srclib/pcre/.libs/libpcre.a: no archive symbol table (run ranlib)

It looks like ar didn’t run with gold plugin. Actually I did alias ar=“ar --plugin /path/to/” and also similarly to
nm. Still didn’t help. If I export AR=“ar --plugin /path/to/”, it will complain:

/home/ryan/binutils/bin/ar: no operation specified

which I found a related bug report to binutils on .

Does anyone have some clue on what’s going on ?

Thanks very much!


Does anyone have some clue on what's going on ?

You don't need to pass command line options to ar and nm if the plugin
is installed in the correct directories. A guess is that the build
system is running ranlib on the .a files and that is destroying the
index created by nm.

If you put the plugins in the bfd-plugins directory nm, ar and ranlib
will use them.

Thanks very much!



Thanks for replying!
I didn’t install the new binutils to system directory in case it messes thing up.
For ranlib, from the error message, it seems to be the reason. But even I export
RANLIB=/bin/true, clean the code and rebuild, it still fails with the same message.
I created a symlink in /usr/lib/bfd-plugins as suggested in
Still it doesn’t work…
Really have no idea what to try next.

Best regards,

I tried some other configurations. Now with llvm 3.0 + clang 3.0, and expoert CC to be clang -flto -use-gold-plugin,
and other ENV variables.

Good news is the “no archive symbol error message” is gone, but bad news is new error messages appear

/path/to/ld: error: …/mysys/libmysys.a: member at 8758 is not an ELF object
/path/to/ld: error: …/mysys/libmysys.a: member at 817850 is not an ELF object
/path/to/ld: error: …/mysys/libmysys.a: member at 827534 is not an ELF object

Searched a related thread(where the failed test case have similar error message) in:
I’m wondering if that issue has been resolved?

Best regards,

Why are you using outdated llvm and clang?

I’m trying to enumerate different combinations to get a workable solution.
At least this combination passed the previously failed step, but got stuck in later ones.
Also my GCC is still 4.5, so llvm 3.0 is not that outdated?


It's much easier to build clang and llvm from sources that gcc, and seem to do it already :slight_smile: