* 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.
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);
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);
+ }
}
}
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++)
{
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);
+ }
}
}