RE:RE: Question about inserting instructions

Hi,

One more thing I just realized for the method Chris mentioned.

Actually that’s not true. You can make instructions with an asmstring of:

“.byte 123\n .byte 56\n .byte 86” and those bytes will get emitted to
the code stream.

It seems to work on generating binary file since it uses asmstring, right?

There are two steps related with binary file operation,

  1. opt -load passname < *.bc > *.bc which is the first one.
  2. the second one is ‘as’ or ‘gcc’
    as -o *.o *.s
    gcc -c *.s -o *.o

Is it true the method you mention should work on the first one?

Another question, when emitting the asmstring to the code stream ( binary code string,right), we need adjust some instruction operation like jmp jne call, for example

jmp/jne 0xxxx ( address of memory or offset). If we put asmstring in code stream, we should adjust the value/offset of such instruction, it makes complicated. So that is why I am trying find a way to insert meaningless code when generating assemble code by llc. ( assemble code generated work on label for those instruction).

Actually, I think I can write a code which read assemble file generated by ‘LLC’ and find the tag of the dummy BB and put some meanless assemble code like ‘push %eax’ etc. I am supposed that it should work well. However, I prefer to implement the whole thing within LLVM.

Anyway, I do appreciate if you can give me some hint about how to emit asmstring to code

Thanks