Inserting dead code in IR byte code

Hi all,

I am working on my Master’s project in security and for this I need to do following things :

  1. I have a IR bytecode of the main program. I want to insert dead code from other source files (e.g. cygwin files or the Linux files) in main program’s IR byte code.
  2. In order to insert code, I can try following two ways :
    (i) I have observed that these IR bytecode files are just like a text file and they have fixed format. Using file operations, we can modify IR byte code of the first file by inserting the IR byte code from other files.
    (ii) Second approach is to use LLC Tool to generate c++ code of second IR byte code. Then use generated c++ code and insert into the first IR byte code. Write the optimizer pass on first IR byte code and add the instructions from generated c++ code. Get the modified IR bytecode of the first program.

Which approach is better and are there any other ways which I can use?

Thanks,
Teja

Hi Teja,

I am working on my Master's project in security and for this I need to do
following things :

1. I have a IR bytecode of the main program. I want to insert dead code from
other source files (e.g. cygwin files or the Linux files) in main program's IR
byte code.

do you mean adding additional functions? Or do you mean adding extra
instructions to existing functions? In the first case why not use the
LLVM IR linker (llvm-link) to add in the extra bitcode?

Ciao, Duncan.

Hi Duncan,

I mean both. In order to generate random code, I have to add function definitions and also for robustness I have to call these functions from already existing functions. So, have to add calling type of instructions also in the existing function.
In future I also have to change instructions for simple substitution meaning

‘add a, b’ can be done using ‘sub a, 0’ and followed by ‘add a, b’ or something like that. So, have to modify / add instructions in the existing code.

I am not much aware of LLVM IR Linker (llvm-ld). I know that it takes multiple bitcode files and then link them together to generate one bitcode file. Is it possible to add functions and instructions using this tool ?

Thanks,
Teja

Did you get a chance to take a look at my response Duncan?

Thanks,
Teja