How can I make the LLVM IR of a function available to my program?

user2333829

I'm working on a library which I'd like certain introspection features to be available. Let's say I'm compiling with clang, so I have access to libtooling or whatever.

What I'd like specifically is for someone to be able to view the LLVM IR of an already-compiled function as part of the program. I know that, when compiling, I can use -emit-llvm to get the IR. But that saves it to a file. What I'd like is for the LLVM IR to be embedded in and retrievable from the program itself -- e.g. my_function_object.llvm_ir()

Is such a thing possible? Thanks!

Theodoros Chatzigiannakis

You're basically trying to have reflection to your program. Reflection requires the existence of metadata in your binary. This doesn't exist out of the box in LLVM, as far as I know.

To achieve an effect like this, you could create a global key-value dictionary in your program, exposed via an exported function - something like IRInstruction* retrieve_llvm_ir_stream(char* name).

This dictionary would map some kind of identifier (for example, the exported name) of a given function to an in-memory array that represents the IR stream of that function (each instruction represented as a custom IRInstruction struct, for example). The types and functions of the representation format (like the custom IRInstruction struct) will have to be included in your source.

At the step of the IR generation, this dictionary will be empty. Immediately after the IR generation step, you'll need to add a custom build step: open the IR file and populate the dictionary with the data - for each exported function of your program, inject its name as a key to the dictionary and its IR stream as a value. The IR stream would be generated from the definitions of your functions, as read by your custom build tool (which would leverage the LLVM API to read the generated IR and convert it to your format).

Then, proceed to the assembler and linker as before.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I make the LLVM IR of a function available to my program?

From Dev

How can I make my program faster?

From Dev

How can I make my webserver running on android publically available

From Dev

How do I make LLVM opt output an IR file when given an IR file?

From Dev

How can I make my recursive C program more efficient?

From Dev

How can I make a QTextEdit widget scroll from my program

From Dev

How can I make my Python program's executable file?

From Dev

How can i make my program reactive in swift with RxSwift

From Dev

How can I make my program run on startup by adding it to the registry?

From Dev

How to call C++ function in LLVM IR?

From Dev

How to call C++ function in LLVM IR?

From Dev

LLVM - How AST can be transformed to IR

From Dev

How can I make my tftp server visible/available on my local network?

From Dev

How to get the image base address of a program in LLVM IR

From Dev

How can I make my function run in constant time?

From Dev

How can I make my Rust function more generic & efficient?

From Dev

How can I make my function to run the moment the page is running?

From Dev

How can I make a prototype function to all my object properties?

From Dev

How can I make my IsItAHoliday function more efficient?

From Dev

how can i make my function inverse in r?

From Dev

How can I make my function accept different types of input?

From Dev

How can I make common search code available to all of my model classes?

From Dev

Can I make the local "this" available inside another function?

From Dev

How can i make this program work?

From Dev

How can i make this program faster and simple?

From Dev

instrument a call to function in LLVM IR

From Dev

How can I make the second instance of my program pass control back to the first instance?

From Java

How can i make the console app Exit if the user prints 'x' in my C# program?

From Dev

How can I make my program installable via the linux repositories (eg, using apt-get)?

Related Related

  1. 1

    How can I make the LLVM IR of a function available to my program?

  2. 2

    How can I make my program faster?

  3. 3

    How can I make my webserver running on android publically available

  4. 4

    How do I make LLVM opt output an IR file when given an IR file?

  5. 5

    How can I make my recursive C program more efficient?

  6. 6

    How can I make a QTextEdit widget scroll from my program

  7. 7

    How can I make my Python program's executable file?

  8. 8

    How can i make my program reactive in swift with RxSwift

  9. 9

    How can I make my program run on startup by adding it to the registry?

  10. 10

    How to call C++ function in LLVM IR?

  11. 11

    How to call C++ function in LLVM IR?

  12. 12

    LLVM - How AST can be transformed to IR

  13. 13

    How can I make my tftp server visible/available on my local network?

  14. 14

    How to get the image base address of a program in LLVM IR

  15. 15

    How can I make my function run in constant time?

  16. 16

    How can I make my Rust function more generic & efficient?

  17. 17

    How can I make my function to run the moment the page is running?

  18. 18

    How can I make a prototype function to all my object properties?

  19. 19

    How can I make my IsItAHoliday function more efficient?

  20. 20

    how can i make my function inverse in r?

  21. 21

    How can I make my function accept different types of input?

  22. 22

    How can I make common search code available to all of my model classes?

  23. 23

    Can I make the local "this" available inside another function?

  24. 24

    How can i make this program work?

  25. 25

    How can i make this program faster and simple?

  26. 26

    instrument a call to function in LLVM IR

  27. 27

    How can I make the second instance of my program pass control back to the first instance?

  28. 28

    How can i make the console app Exit if the user prints 'x' in my C# program?

  29. 29

    How can I make my program installable via the linux repositories (eg, using apt-get)?

HotTag

Archive