gcc - Linking in llvm -
i profiling few files in spec2k6 benchmark profiler written in llvm, , cannot understand right way link multiple .bc files.
for example, benchmark has concat.c, uses xmalloc method defined in xmalloc.c, uses xexit method xexit.c
i using next commands link multiple .bc files before profile them -
cflags='-d_gnu_source -d_xopen_source=600 -c -wall -pedantic -wno-long-long -g -o0 - i/net/x/silkyar/llvm/include -i/net/403.gcc/src' clang $cflags -emit-llvm -c 403.gcc/src/concat.c -o concat.bc clang $cflags -emit-llvm -c 403.gcc/src/xexit.c -o xexit.bc clang $cflags -emit-llvm -c 403.gcc/src/xmalloc.c -o xmalloc.bc llvm-link concat.bc xexit.bc xmalloc.bc -o a.bc llc a.bc -o a.s g++ -o final a.s ./final
but fails with, llvm-link: link error in 'xexit.bc': linking globals named 'xexit': symbol multiply defined! /tmp/cculdt0y.o:(.debug_info+0x1e): undefined reference .lline_table_start0' /tmp/cculdt0y.o:(.debug_info+0x42f): undefined reference to
.lline_table_start1' /tmp/cculdt0y.o:(.debug_info+0x4a0): undefined reference `.lline_table_start2' collect2: ld returned 1 exit status
could please guide me on how llvm-link works.
thanks.
in general, llvm-link
works fine. here's simple demonstration (with llvm built trunk few days ago):
$ cat lib.c int libfoo(int x) { homecoming x * 2; } $ cat user.c int libfoo(int); int bar(int a, int b) { homecoming + libfoo(b); } $ clang -emit-llvm -c user.c -o user.bc $ clang -emit-llvm -c lib.c -o lib.bc $ llvm-link lib.bc user.bc -o linked.bc $ llvm-dis linked.bc $ cat linked.ll ; moduleid = 'linked.bc' target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-s128" target triple = "x86_64-unknown-linux-gnu" define i32 @libfoo(i32 %x) nounwind uwtable { entry: %x.addr = alloca i32, align 4 store i32 %x, i32* %x.addr, align 4 %0 = load i32* %x.addr, align 4 %mul = mul nsw i32 %0, 2 ret i32 %mul } define i32 @bar(i32 %a, i32 %b) nounwind uwtable { entry: %a.addr = alloca i32, align 4 %b.addr = alloca i32, align 4 store i32 %a, i32* %a.addr, align 4 store i32 %b, i32* %b.addr, align 4 %0 = load i32* %a.addr, align 4 %1 = load i32* %b.addr, align 4 %call = phone call i32 @libfoo(i32 %1) %add = add together nsw i32 %0, %call ret i32 %add }
so have examine specific code symbol duplication, missing, etc.
gcc llvm clang llvm-gcc
No comments:
Post a Comment