]> git.unchartedbackwaters.co.uk Git - francis/libjit.git/commitdiff
add POSITION_INDEPENDENT context option
authorAleksey Demakov <ademakov@gmail.com>
Sun, 26 Nov 2006 20:42:01 +0000 (20:42 +0000)
committerAleksey Demakov <ademakov@gmail.com>
Sun, 26 Nov 2006 20:42:01 +0000 (20:42 +0000)
ChangeLog
include/jit/jit-context.h
jit/jit-context.c
jit/jit-function.c
jit/jit-internal.h
jit/jit-rules-x86.ins

index e92ee7c469395611f2b1bb26ef095caf8c31d332..33c63f01977be1beed49456795008b32e977d19f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-11-27  Aleksey Demakov  <ademakov@gmail.com>
+
+       * include/jit/jit-context.h: add JIT_OPTION_POSITION_INDEPENDENT
+       option.
+       * jit/jit-internal.h (struct _jit_builder): add position_independent
+       field.
+       * jit/jit-function.c (_jit_function_ensure_builder): initialize
+       position_independent field.
+
 2006-11-26  Kirill Kononenko  <Kirill.Kononenko@gmail.com>
 
        * jit/jit-rules-x86.ins: if JIT_USE_SIGNALS is defined do not emit
index 33ff8ed125c8f98ab6ed8cb11a6bf42075b42e7a..03159b69597475902bbfb51619db773895ed3aa2 100644 (file)
@@ -49,6 +49,7 @@ void jit_context_free_meta(jit_context_t context, int type) JIT_NOTHROW;
 #define        JIT_OPTION_CACHE_PAGE_SIZE      10001
 #define        JIT_OPTION_PRE_COMPILE          10002
 #define        JIT_OPTION_DONT_FOLD            10003
+#define JIT_OPTION_POSITION_INDEPENDENT        10004
 
 #ifdef __cplusplus
 };
index 4856d11e8bb0634580791ec13bbc2820ed2a0c01..d80ed06ee1ccb87cc15d251797be0b1697ee96a6 100644 (file)
@@ -213,6 +213,12 @@ int jit_context_set_meta
  * A numeric option that disables constant folding when it is set to a
  * non-zero value.  This is useful for debugging, as it forces @code{libjit} to
  * always execute constant expressions at run time, instead of at compile time.
+ *
+ * @vindex JIT_OPTION_POSITION_INDEPENDENT
+ * @item JIT_OPTION_POSITION_INDEPENDENT
+ * A numeric option that forces generation of position-independent code (PIC)
+ * if it is set to a non-zero value. This may be mainly useful for pre-compiled
+ * contexts.
  * @end table
  *
  * Metadata type values of 10000 or greater are reserved for internal use.
index fd2896a74125a4666a1a1cf0acdab0170c927a9c..4f618fd03c93e20dcafe7d4d5c672887e971583c 100644 (file)
@@ -180,6 +180,11 @@ int _jit_function_ensure_builder(jit_function_t func)
                return 0;
        }
 
+       /* Cache the value of the JIT_OPTION_POSITION_INDEPENDENT option */
+       func->builder->position_independent
+               = jit_context_get_meta_numeric(
+                       func->context, JIT_OPTION_POSITION_INDEPENDENT);
+
        /* Initialize the function builder */
        jit_memory_pool_init(&(func->builder->value_pool), struct _jit_value);
        jit_memory_pool_init(&(func->builder->insn_pool), struct _jit_insn);
index 4ad7183fba5064b0369660f3eb312285014143ad..34f6f5eef88f0764e64afaa5eaa4bd93fca8414e 100644 (file)
@@ -322,6 +322,9 @@ struct _jit_builder
        /* Flag that indicates that the current function contains a tail call */
        int                                     has_tail_call : 1;
 
+       /* Generate position-independent code */
+       int                                     position_independent : 1;
+
        /* List of all instructions in this function */
        jit_insn_t                 *insns;
        int                                     num_insns;
index 3a3bf479ebd9d50f61c0fa7e1eb709add0a11d28..54257be8cba70e478b4f5932e386a5a0dbd863ae 100644 (file)
@@ -1700,15 +1700,23 @@ JIT_OP_CALL_FILTER_RETURN: manual
 JIT_OP_ADDRESS_OF_LABEL:
        [=reg] -> {
                block = jit_block_from_label(func, (jit_label_t)(insn->value1));
-               if(block->address)
+               if(func->builder->position_independent)
                {
-                       x86_mov_reg_imm(inst, $1, block->address);
+                       /* TODO */
+                       TODO();
                }
                else
                {
-                       /* Output a placeholder and record on the block's fixup list */
-                       x86_mov_reg_imm(inst, $1, (int)(block->fixup_absolute_list));
-                       block->fixup_absolute_list = (void *)(inst - 4);
+                       if(block->address)
+                       {
+                               x86_mov_reg_imm(inst, $1, block->address);
+                       }
+                       else
+                       {
+                               /* Output a placeholder and record on the block's fixup list */
+                               x86_mov_reg_imm(inst, $1, (int)(block->fixup_absolute_list));
+                               block->fixup_absolute_list = (void *)(inst - 4);
+                       }
                }
        }
 
@@ -2395,15 +2403,23 @@ JIT_OP_JUMP_TABLE: ternary
                patch_fall_through = inst;
                x86_branch32(inst, X86_CC_GE, 0, 1);
 
-               patch_jump_table = inst;
-               x86_jump_memindex(inst, X86_NOBASEREG, 0, $1, 2);
-               while(((jit_nint) inst & (sizeof(void*) - 1)) != 0)
+               if(func->builder->position_independent)
                {
-                       x86_nop(inst);
+                       /* TODO */
+                       TODO();
                }
+               else
+               {
+                       patch_jump_table = inst;
+                       x86_jump_memindex(inst, X86_NOBASEREG, 0, $1, 2);
+                       while(((jit_nint) inst & (sizeof(void*) - 1)) != 0)
+                       {
+                               x86_nop(inst);
+                       }
 
-               // displacement goes after opcode. ModR/M, and SIB bytes
-               *((void **)(patch_jump_table + 3)) = inst;
+                       // displacement goes after opcode. ModR/M, and SIB bytes
+                       *((void **)(patch_jump_table + 3)) = inst;
+               }
 
                for(index = 0; index < num_labels; index++)
                {
@@ -2413,15 +2429,23 @@ JIT_OP_JUMP_TABLE: ternary
                                return;
                        }
 
-                       if(block->address)
+                       if(func->builder->position_independent)
                        {
-                               x86_imm_emit32(inst, block->address);
+                               /* TODO */
+                               TODO();
                        }
                        else
                        {
-                               /* Output a placeholder and record on the block's fixup list */
-                               x86_imm_emit32(inst, (int)(block->fixup_absolute_list));
-                               block->fixup_absolute_list = (void *)(inst - 4);
+                               if(block->address)
+                               {
+                                       x86_imm_emit32(inst, block->address);
+                               }
+                               else
+                               {
+                                       /* Output a placeholder and record on the block's fixup list */
+                                       x86_imm_emit32(inst, (int)(block->fixup_absolute_list));
+                                       block->fixup_absolute_list = (void *)(inst - 4);
+                               }
                        }
                }