2 Replies Latest reply on Mar 10, 2012 12:09 AM by hyouklee

    Extract LLVM IR from BIF




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


      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.)


        • Re: Extract LLVM IR from BIF


          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.