Re: Create binary from GCJ generated assembly

Andrew Haley <[email protected]>
Newsgroups gmane.comp.gcc.java.devel
Message-ID <[email protected]>
isuru herath wrote:

 > I want to add two assembly instructions to my Java program. Earlier
 > I was doing it in C with "asm volatile". To get the same behavior in
 > Java I used JNI. I used GCJ with -fjni flat to crate the binary. It
 > executed and gave the correct output. But when I checked the memory
 > references between two assembly instructions it is very high
 > compared to the C program.  Thereafter I got the assembly version of
 > both C and Java codes with -S option. In C version, assembly
 > instructions are directly inserted in the proper places. But in Java
 > version library calls are placed in the places where assembly should
 > be inserted. I doubt this may be the case for larger memory
 > references. So my question is is there a way to edit the gcj
 > generated assembly and insert assembly instructions and compile it
 > to a binary. I tried two different ways(trial and error). Nothing
 > worked.
 >
 > [1]
 > gcj --main=new_shared_counter -o new_shared_counter new_shared_counter.s
 >
 > [2]
 > gcc shared_counter.s
 >

gcj can't handle inline asm.

There are a few ways to do this:

* Write the code with the asm in C++ using CNI.  This is the easiest
   way, and gives you results identical to using asm volatile in C.

* Add a compiler intrinsic.  This requires specialist knowledge.

* Post-process the assembler output from gcj to replace a call with
   some assembly instructions.  Nasty, but it'd work.  Again, this
   requires specialist knowledge.

 > Any help on how to compile a gcj generated assembly to binary would
 > be greatly appreciated.

Use the assembler, "as".

Andrew.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.