[llvm-dev] Creating and using "shared library" of LLVM IR
Tarun Prabhu via llvm-dev
llvm-dev at lists.llvm.org
Fri May 13 10:27:31 PDT 2016
I am trying to use LLVM to get the IR for a whole program. The program's
Makefile is somewhat complicated so I have written wrappers which emit LLVM
IR at every step in the process instead of ELF object files and
executables. My problem is that during linking, I get "multiple definition"
errors. Here is a small example:
file: a.c
---------
int f_a(int m) { return m + 1; }
file: b.c
----------
int f_a(int);
int f_b(int n) { return f_a(n); }
file: driver.c
--------------
int f_b(int);
int main(int argc, char *argv[]) {
return f_b(argc);
}
$ clang -flto -Wl,-plugin-opt=emit-llvm -shared -o libA.so a.c
$ clang -flto -Wl,-plugin-opt=emit-llvm -shared -o libB.so b.c -L. -lA
$ clang -flto -Wl,-plugin-opt=emit-llvm -o driver driver.c -L. -lA -lB
All the .so files here are obviously now bitcode files. The last command
fails with a "multiple definition" error because both libB.so and libA.so
contain a definition for f_a.
My question is: Is there a way to have the linker only import the
definitions from shared objects when linking the final executable and in
all other cases just use the declaration? Or, is there a way to get the
linker to pick one of several identical definitions?
Thanks,
Tarun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160513/11796cc0/attachment.html>
More information about the llvm-dev
mailing list