Reserve some empty memory space after each basic block

Hello!

I am going to do a research project that inserts instructions (e.g.,
JMP) after each code basic block at runtime of a program (when the
program is already loaded into memory).

I believe first I should allocate (reserve) more memory space (could
be filled with "NOP" instructions) after each basic block during
compilation in order to put the extra instructions thereafter.

Could anyone tell me how to implement it in LLVM for 32-bit x86
platform? E.g., which functions or data structures or materials of
LLVM I should look at or refer to.

I really appreciate your kind help.

Best,
Yue

Dear Yue,

The easiest thing to do is to write an LLVM pass that inserts some inline assembly code at the end of each basic block (right before the terminator instruction) that contains NOP instructions.

To learn to do that, you should read the "Writing an LLVM Pass" document, the "LLVM Programmer's Manual," and be prepared to look at the doxygen documentation for creating inline assembly statements.

Regards,

John Criswell