[LLVMdev] Re:Re:Is there any way to modify basic block like adding junk code

Misha Brukman brukman at uiuc.edu
Tue Sep 21 14:33:17 PDT 2004


On Tue, Sep 21, 2004 at 02:25:32PM -0700, Zhang Qiuyu wrote:
> I did inserting function into code before using the way you mentioned,
> such as call a external function. But coud I insert some assemble
> instructions into *.bc ?

You cannot insert NATIVE assembly instructions at this time, but you can
insert LLVM assembly instructions into a .bc (LLVM bytecode) file.
 
> what I want to do is to implement polymorphic engine like ADM. It can
> change the binary code which looks like different but the
> functionality is exactly same. The simple way to do it is to add some
> junk code like NOP( 0x90) or dead code. But it is easy to identify the
> different binary codes by the above way which have same functionality.
> So there are some other ways to do it, however these are a little
> difficult. For example, after you analyse the a bunch of codes in one
> BB, if there are some independent code, we can shuffle those codes
> which will change the final binary code and keep same functionality.Or
> we can find some alternative codes to replace it......
> 
> Does llvm have the option for these? 

As Chris mentioned in his previous email, the links will point you to
ways you can modify the LLVM IR (which is the LLVM assembly language).

Perhaps some clarification is in order:

* LLVM bytecode contains a binary version of LLVM assembly instructions
  These files are usually with a .bc extension
* If you disassemble LLVM bytecode, you get an LLVM text assembly (.ll)
* The compiler IR is the SAME as the LLVM assembly instructions, there
  is a 1:1 mapping

These 3 ways of representing LLVM code all have a 1:1 mapping between
each other.

So when we say "you can modify the LLVM IR" what we're also saying is
that you can modify the LLVM assembly instructions, because they are the
same thing.  However, at this point in time, you cannot mix native
machine assembly with LLVM bytecode in the same file, if that is what
you're looking for.  Instead, what you could do is re-write LLVM
bytecode to have additional dead code, or "junk" code as you put it, or
reorganize the LLVM code as you wish.  You can then use one of our
native machine backends to generate code, statically (via LLC) or
dynamically (via LLI).

Hope that helps,
-- 
Misha Brukman :: http://misha.brukman.net :: http://llvm.cs.uiuc.edu




More information about the llvm-dev mailing list