cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

hyouklee
Journeyman III

Extract LLVM IR from BIF

Hi.

I'm trying to extract LLVM IR from the binary generated by OpenCL offline compiler.

(http://developer.amd.com/support/KnowledgeBase/Lists/KnowledgeBase/DispForm.aspx?ID=115)

I tested with the clbinarygen.c given from the above link with the option (-fno-bin-exe -fno-bin-amdil),

and I could get the .llvmir section for a simple vector addition cl kernel.

But this output format is still not a pure LLVM bitcode and has other  BIF-related stuffs.

How could I easily get the LLVM IR for the kernel so that I can feed it into llvm-dis?

(The attached is the output from running clbinarygen.c with the above option.)

Thanks.

0 Likes
1 Solution

hyouklee,

The article still produces an ELF object as its result, you need to decompose the ELF object itself to get the LLVMIR. If you use readelf on the attached file, then you see that llvmir starts at offset 0xc8 and is 0x5bc bytes in size. So, your best bet is to write a program that takes in an elf file and offset and a size and strips that section and stores it into a seperate file.

Another thing you can do is use a binary editor and remove the first 0xc8 bytes and everything after byte 0xc8 + 0x5bc.

View solution in original post

0 Likes
2 Replies

hyouklee,

The article still produces an ELF object as its result, you need to decompose the ELF object itself to get the LLVMIR. If you use readelf on the attached file, then you see that llvmir starts at offset 0xc8 and is 0x5bc bytes in size. So, your best bet is to write a program that takes in an elf file and offset and a size and strips that section and stores it into a seperate file.

Another thing you can do is use a binary editor and remove the first 0xc8 bytes and everything after byte 0xc8 + 0x5bc.

0 Likes

Thanks Micah.

I could extract only the contents of a section using the offset and the size info from readelf.

0 Likes