[LLVMdev] Re:RE: Question about inserting instructions

Misha Brukman brukman at uiuc.edu
Wed May 11 13:40:20 PDT 2005


On Wed, May 11, 2005 at 01:30:29PM -0700, Qiuyu Zhang wrote:
[snip]
>                 push %eax
>                 das
>                 clc
>  
> all of them are legal one-byte x86 machine instructions. 
[snip]
> If there is a way to be able to get that,   I am supposed that like
> the following,
> 
> 1. generate some dummy BB on IR level ( working on *.bc by writing a pass)
> 2. llc *.bc ( generate machine code)
> 3. as -o *.s *o ( generate object file, or use gcc )
> 4. ld -o *.out *.o ( generate executable file)     
> 
> during step 2, we read *.bc code and find dummy BB and put some
> meaningless machinecode, here, we cannot put some illegal machince
> code, otherwise, step 3 goes to fail.  

Yes, you are correct -- if you want to create illegal code you need to
not use system as.  What you need is the ability for llc to create
object files with native code directly, without using the system
assembler.  I think someone is working on it, but I'm not sure as to the
status.  Otherwise, you will just have some random one-byte
instructions.

> So is it possible to do that for inserting any machine code into BB?
> if so, how could we chang llc?  I take a look at MachineInstr.c
> CodeGenerator.c etc, but I still don't know how to do it.

The CodeEmitter would have to be enhanced to allow outputting standard
format object files that ld can process.  If you are interested in doing
this, someone can point you in the right direction as to what needs to
be done.

-- 
Misha Brukman :: http://misha.brukman.net :: http://llvm.cs.uiuc.edu




More information about the llvm-dev mailing list