making libraries depend on external libraries?

How can I specify that LLVMInterpreter depends on ‘libffi’ in the Makefile? Modifying LD.Flags in Interpreter/Makefile doesn’t help since llvm-config doesn’t pick up on that, causing a linker error when building lli. I’d like “llvm-config --libs interpreter” return -lffi along with the LLVM libraries it lists.

You’d think there would be an example of this already, but I looked and didn’t find one.

Nick

Nick Lewycky wrote:

How can I specify that LLVMInterpreter depends on 'libffi' in the Makefile? Modifying LD.Flags in Interpreter/Makefile doesn't help since llvm-config doesn't pick up on that, causing a linker error when building lli. I'd like "llvm-config --libs interpreter" return -lffi along with the LLVM libraries it lists.

You'd think there would be an example of this already, but I looked and didn't find one.

So I dug through the code and it looks like we really don't support this.

What we do have is "llvm-config --ldflags" which lists all the system libraries we use, regardless of whether the tool you're compiling would really need them. The easiest thing for me to do would be to add -lffi in there. Sound reasonable for now?

Nick

PS. I looked into what it would take to do this properly. "llvm-config --libs" just rattles off the list of dependencies calculated by GenLibDeps, which in turn figures it out by running 'nm' over each llvm built library and seeing which library defines what symbol and builds a graph of using lib -> defining lib. I tried adding a switch to ask it to consider certain system libraries as defining some symbols, in the hopes that the rest of the calculation should just work as normal.

It turns out that a) we need some way to actually find the system library in order to run nm on it and Autoconf won't give us that. I used 'gcc -print-file-name=libffi.so'. b) Makefile.rules makes the assumption that every library printed by llvm-config --libs is something that LLVM will build, and adds them as make dependencies for the tool being built. This is where I gave up.

llvm-config-ffi.patch (6.99 KB)