[LLVMdev] llvm-ar llvm-link

188 views
Skip to first unread message

ankur deshwal

unread,
Feb 21, 2013, 12:53:53 PM2/21/13
to llv...@cs.uiuc.edu, ankur deshwal
Hi,

I tried to build an llvm archive and link it against an llvm bc file. However, it fails. Following is the procedure I followed ( abc.c is file which calls a function whose definition is present in bcd.c)

 $ clang -c -emit-llvm abc.c 
 $  clang -c -emit-llvm bcd.c 
 $  llvm-ar cr bsd.ar bcd.o 
 $  llvm-link abc.o bsd.ar

llvm-link: bsd.ar:1:2: error: expected integer
!<arch>
 ^
llvm-link: error loading file 'bsd.ar'

What am I missing here ? 

Regards,
Ankur

Hassan, Ahmad

unread,
Feb 21, 2013, 1:21:42 PM2/21/13
to ankur deshwal, llv...@cs.uiuc.edu

Hi Ankur,

 

 

Why do you need archive in this case? The other way of doing this is to merge all bitcode files into single file:

 

 $ clang -c -emit-llvm abc.c –o abc.bc

 $  clang -c -emit-llvm bcd.c –o bcd.bc

llvm-link bcd.bc abc.bc –o merged.bc

 

Cheers,

Ahmad

ankur deshwal

unread,
Feb 21, 2013, 8:12:21 PM2/21/13
to Hassan, Ahmad, llv...@cs.uiuc.edu
Hi Ahmad,

Yes, merging works good. 

However, my problem is like this - I have a C library which consists of 1000's of functions spread through various files. The functions do not have dependency amoung each other. I want to link only relavant files( files which have functions called from my application). Since ar has a global symbol table, I believe it should be faster to look for a symol in the table and pull out and link the file to .bc of my application.

Is my understand regarding llvm-ar correct? Or is there a better way to achieve it? 

One not-so-great solution I can think of is compile the library into separate .bc files and write llvm pass which has a predefined hash mapping of the names of functions these bc files. So while compiling, I look for only relavant files and link them using code form llvm-link. 

OR. rather than linking the files, only extract the function from the library .bc file and insert it into module of application .bc. 

Does any of the idea make sense ? Which one will be doable+preferable? 


Thanks a lot,
Ankur 



   

ankur deshwal

unread,
Feb 22, 2013, 9:45:12 AM2/22/13
to Hassan, Ahmad, llv...@cs.uiuc.edu
Please help with the foreseeable shortcoming of the techniques discussed/ better alternate technique. These context for the problem is opencl builtin libs.

Thanks,
Ankur
Reply all
Reply to author
Forward
0 new messages