public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: JIT binary translation using libgccjit?
  2015-01-01  0:00 ` David Malcolm
@ 2015-01-01  0:00   ` Kaz Nishimura
  2015-01-01  0:00     ` Basile Starynkevitch
  0 siblings, 1 reply; 7+ messages in thread
From: Kaz Nishimura @ 2015-01-01  0:00 UTC (permalink / raw)
  Cc: jit

I am looking for a "light-weight" (that is not much slower than direct
instruction emulation) code generator.  If libgccjit is currently
invokes external tools to generate "host" code, I feel it is too heavy
for my plan.  Because binary code has no strict function structure, I
guess it will be tricky to translate "guest" code by a
function-oriented JIT code generator.  I already have looked at libjit
and since it is function-oriented, I am searching for an alternative
suitable for binary translation.


On Mon, Oct 19, 2015 at 11:09 PM, David Malcolm <dmalcolm@redhat.com> wrote:
> On Sat, 2015-10-17 at 20:10 +0900, Kaz Nishimura wrote:
>> I am looking for a JIT code generator for a runtime binary translator.
>> Is libgccjit suitable for such an application?
>
> Possibly.
>
> Note that libgccjit currently doesn't support cross-compilation: it can
> only generate host code (host == target).
>
>> I would like a
>> light-weight code generator that can emit target code even for
>> non-structured source (= binary) code in reasonable time.
>
> That depends on what you mean by "light-weight" and "reasonable time".
> libgccjit generates assembler internally, then calls out to external
> binaries to turn that assembler into a .o then a .so shared library, and
> dlopens it; typically that takes about 50ms on my box per compile.
>
> Dave
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: JIT binary translation using libgccjit?
  2015-01-01  0:00   ` Kaz Nishimura
@ 2015-01-01  0:00     ` Basile Starynkevitch
  2015-01-01  0:00       ` Kaz Nishimura
  0 siblings, 1 reply; 7+ messages in thread
From: Basile Starynkevitch @ 2015-01-01  0:00 UTC (permalink / raw)
  To: Kaz Nishimura; +Cc: jit

On 10/20/2015 01:08 AM, Kaz Nishimura wrote:
> I am looking for a "light-weight" (that is not much slower than direct
> instruction emulation) code generator.  If libgccjit is currently
> invokes external tools to generate "host" code, I feel it is too heavy
> for my plan.  Because binary code has no strict function structure, I
> guess it will be tricky to translate "guest" code by a
> function-oriented JIT code generator.


Yes, GCCJIT requires to have functions.

If you cannot afford functions (like C have them, and most ELF files also)
  then you cannot follow the common existing ABI. And you need
a target-specific JIT library. For x86-64 consider asmjit. 
https://github.com/kobalicek/asmjit


Notice also that without functions, you probably won't be able to get 
optimized code. Hence
to get a little bit of efficiency, you'll need to somehow deal yourself 
with things like register allocation and instruction scheduling. At the 
very least, you want to avoid emitting the store of a register into some 
call stack slot followed by the reload of the same register from the 
same slot (like e.g. TinyCC is doing).

Cheers

-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: JIT binary translation using libgccjit?
  2015-01-01  0:00       ` Kaz Nishimura
@ 2015-01-01  0:00         ` Basile Starynkevitch
  0 siblings, 0 replies; 7+ messages in thread
From: Basile Starynkevitch @ 2015-01-01  0:00 UTC (permalink / raw)
  To: Kaz Nishimura; +Cc: jit

On 10/20/2015 07:19 AM, Kaz Nishimura wrote:
> Since "guest" binary code can jump into another function (or
> subroutine) without a return due to compiler optimizations, I must
> synthesize a "function" from the sequence of instructions without any
> hint of program structure.  As I am looking for a portable JIT code
> generator, asmjit is not an option now.
>
> I also want redundant code elimination as the condition code can
> easily be overridden by the next instruction.  If such condition code
> computation could be automatically eliminated, translation would be
> much easier, I expect.  I felt libjit was the closest to what I
> wanted, but is still searching for an alternative.

I believe you won't find any alternative. The organization of an 
executable in functions is tightly tied
to ELF format and to any "compiler" like code emitter, so if you cannot 
have functions you are stuck
to a target specific JIT-ing library like asmjit and you certainly need 
to dive into the implementation
details of your target system. And you won't be able to leverage on any 
kind of serious optimizer.

Good luck.

-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***

^ permalink raw reply	[flat|nested] 7+ messages in thread

* JIT binary translation using libgccjit?
@ 2015-01-01  0:00 Kaz Nishimura
  2015-01-01  0:00 ` David Malcolm
  2015-01-01  0:00 ` Basile Starynkevitch
  0 siblings, 2 replies; 7+ messages in thread
From: Kaz Nishimura @ 2015-01-01  0:00 UTC (permalink / raw)
  To: jit

I am looking for a JIT code generator for a runtime binary translator.
Is libgccjit suitable for such an application?  I would like a
light-weight code generator that can emit target code even for
non-structured source (= binary) code in reasonable time.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: JIT binary translation using libgccjit?
  2015-01-01  0:00     ` Basile Starynkevitch
@ 2015-01-01  0:00       ` Kaz Nishimura
  2015-01-01  0:00         ` Basile Starynkevitch
  0 siblings, 1 reply; 7+ messages in thread
From: Kaz Nishimura @ 2015-01-01  0:00 UTC (permalink / raw)
  To: Basile Starynkevitch; +Cc: jit

Since "guest" binary code can jump into another function (or
subroutine) without a return due to compiler optimizations, I must
synthesize a "function" from the sequence of instructions without any
hint of program structure.  As I am looking for a portable JIT code
generator, asmjit is not an option now.

I also want redundant code elimination as the condition code can
easily be overridden by the next instruction.  If such condition code
computation could be automatically eliminated, translation would be
much easier, I expect.  I felt libjit was the closest to what I
wanted, but is still searching for an alternative.

On Tue, Oct 20, 2015 at 1:48 PM Basile Starynkevitch
<basile@starynkevitch.net> wrote:
>
> On 10/20/2015 01:08 AM, Kaz Nishimura wrote:
> > I am looking for a "light-weight" (that is not much slower than direct
> > instruction emulation) code generator.  If libgccjit is currently
> > invokes external tools to generate "host" code, I feel it is too heavy
> > for my plan.  Because binary code has no strict function structure, I
> > guess it will be tricky to translate "guest" code by a
> > function-oriented JIT code generator.
>
>
> Yes, GCCJIT requires to have functions.
>
> If you cannot afford functions (like C have them, and most ELF files also)
>   then you cannot follow the common existing ABI. And you need
> a target-specific JIT library. For x86-64 consider asmjit.
> https://github.com/kobalicek/asmjit
>
>
> Notice also that without functions, you probably won't be able to get
> optimized code. Hence
> to get a little bit of efficiency, you'll need to somehow deal yourself
> with things like register allocation and instruction scheduling. At the
> very least, you want to avoid emitting the store of a register into some
> call stack slot followed by the reload of the same register from the
> same slot (like e.g. TinyCC is doing).
>
> Cheers
>
> --
> Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
> email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
> 8, rue de la Faiencerie, 92340 Bourg La Reine, France
> *** opinions {are only mine, sont seulement les miennes} ***
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: JIT binary translation using libgccjit?
  2015-01-01  0:00 JIT binary translation using libgccjit? Kaz Nishimura
@ 2015-01-01  0:00 ` David Malcolm
  2015-01-01  0:00   ` Kaz Nishimura
  2015-01-01  0:00 ` Basile Starynkevitch
  1 sibling, 1 reply; 7+ messages in thread
From: David Malcolm @ 2015-01-01  0:00 UTC (permalink / raw)
  To: Kaz Nishimura; +Cc: jit

On Sat, 2015-10-17 at 20:10 +0900, Kaz Nishimura wrote:
> I am looking for a JIT code generator for a runtime binary translator.
> Is libgccjit suitable for such an application?  

Possibly.

Note that libgccjit currently doesn't support cross-compilation: it can
only generate host code (host == target).

> I would like a
> light-weight code generator that can emit target code even for
> non-structured source (= binary) code in reasonable time.

That depends on what you mean by "light-weight" and "reasonable time".
libgccjit generates assembler internally, then calls out to external
binaries to turn that assembler into a .o then a .so shared library, and
dlopens it; typically that takes about 50ms on my box per compile.

Dave

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: JIT binary translation using libgccjit?
  2015-01-01  0:00 JIT binary translation using libgccjit? Kaz Nishimura
  2015-01-01  0:00 ` David Malcolm
@ 2015-01-01  0:00 ` Basile Starynkevitch
  1 sibling, 0 replies; 7+ messages in thread
From: Basile Starynkevitch @ 2015-01-01  0:00 UTC (permalink / raw)
  To: Kaz Nishimura, jit

On 10/17/2015 01:10 PM, Kaz Nishimura wrote:
> I am looking for a JIT code generator for a runtime binary translator.
> Is libgccjit suitable for such an application?  I would like a
> light-weight code generator that can emit target code even for
> non-structured source (= binary) code in reasonable time.

I guess you think of translating some binary executable for one platform 
(e.g. ARM/Android)
into some binary on another platform (e.g. x86-64/Linux)

You could use GCCJIT for that, but be aware that the implicit model of 
GCCJIT is more C like ...
and that GCCJIT would produce efficient code, but with a translation 
time similar to that of GCC
(roughly speaking, GCCJIT -which use really want to use with -O1 
optimization level- will take some significant time to do the 
translation, but the produced machine code would be reasonably efficient).

If you care much more about a fast code generator and accept the 
produced machine code to be less efficient than what GCC do, then GCCJIT 
might not be the best approach. Consider lighter alternatives like GNU 
lightning, GNU libjit, or asmjit ....

In other words, GCCJIT (and LLVM) are probably less lightweight than 
what you believe.

Cheers.

-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-10-20  5:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-01  0:00 JIT binary translation using libgccjit? Kaz Nishimura
2015-01-01  0:00 ` David Malcolm
2015-01-01  0:00   ` Kaz Nishimura
2015-01-01  0:00     ` Basile Starynkevitch
2015-01-01  0:00       ` Kaz Nishimura
2015-01-01  0:00         ` Basile Starynkevitch
2015-01-01  0:00 ` Basile Starynkevitch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).