Alien-LibJIT

 view release on metacpan or  search on metacpan

libjit/ChangeLog  view on Meta::CPAN

	dpas/dpas-parser.y, jit/jit-interp.cpp, jit/jit-interp.h,
	jit/jit-opcode.c, jit/jit-rules-interp.c: execute the "main"
	method once a Dynamic Pascal program has been compiled;
	fix some calling convention problems with "call_external".

	* dpas/dpas-builtin.c, dpas/dpas-scanner.l: add the "Flush"
	and "Terminate" builtins; fix a small bug in string scanning.

	* include/jit/jit-elf.h, jit/Makefile.am, jit/jit-context.c,
	jit/jit-elf-read.c, jit/jit-internal.h, jit/jit-symbol.c:
	implement symbol relocations for the ELF binary reader.

	* dpas/dpas-parser.y: code generation for "for" loops.

2004-05-06  Rhys Weatherley  <rweather@southern-storm.com.au>

	* dpas/Makefile.am, dpas/dpas-builtin.c, dpas/dpas-function.c,
	dpas/dpas-internal.h, dpas/dpas-main.c, dpas/dpas-parser.y,
	dpas/dpas-scope.c, dpas/dpas-scope.h, dpas/dpas-semantics.h,
	dpas/dpas-types.c, dpas/dpas-types.h, include/jit/jit-block.h,
	include/jit/jit-insn.h, include/jit/jit-plus.h, jit/jit-block.c,

libjit/jit/jit-elf-defs.h  view on Meta::CPAN

#define DT_SONAME	14		/* Name of shared object */
#define DT_RPATH	15		/* Library search path (deprecated) */
#define DT_SYMBOLIC	16		/* Start symbol search here */
#define DT_REL		17		/* Address of Rel relocs */
#define DT_RELSZ	18		/* Total size of Rel relocs */
#define DT_RELENT	19		/* Size of one Rel reloc */
#define DT_PLTREL	20		/* Type of reloc in PLT */
#define DT_DEBUG	21		/* For debugging; unspecified */
#define DT_TEXTREL	22		/* Reloc might modify .text */
#define DT_JMPREL	23		/* Address of PLT relocs */
#define	DT_BIND_NOW	24		/* Process relocations of object */
#define	DT_INIT_ARRAY	25		/* Array with addresses of init fct */
#define	DT_FINI_ARRAY	26		/* Array with addresses of fini fct */
#define	DT_INIT_ARRAYSZ	27		/* Size in bytes of DT_INIT_ARRAY */
#define	DT_FINI_ARRAYSZ	28		/* Size in bytes of DT_FINI_ARRAY */
#define DT_RUNPATH	29		/* Library search path */
#define DT_FLAGS	30		/* Flags for the object being loaded */
#define DT_ENCODING	32		/* Start of encoded range */
#define DT_PREINIT_ARRAY 32		/* Array with addresses of preinit fct*/
#define DT_PREINIT_ARRAYSZ 33		/* size in bytes of DT_PREINIT_ARRAY */
#define	DT_NUM		34		/* Number used */

libjit/jit/jit-elf-defs.h  view on Meta::CPAN

/* Sun added these machine-independent extensions in the "processor-specific"
   range.  Be compatible.  */
#define DT_AUXILIARY    0x7ffffffd      /* Shared object to load before self */
#define DT_FILTER       0x7fffffff      /* Shared object to get values from */
#define DT_EXTRATAGIDX(tag)	((Elf32_Word)-((Elf32_Sword) (tag) <<1>>1)-1)
#define DT_EXTRANUM	3

/* Values of `d_un.d_val' in the DT_FLAGS entry.  */
#define DF_ORIGIN	0x00000001	/* Object may use DF_ORIGIN */
#define DF_SYMBOLIC	0x00000002	/* Symbol resolutions starts here */
#define DF_TEXTREL	0x00000004	/* Object contains text relocations */
#define DF_BIND_NOW	0x00000008	/* No lazy binding for this object */

/* State flags selectable in the `d_un.d_val' element of the DT_FLAGS_1
   entry in the dynamic section.  */
#define DF_1_NOW	0x00000001	/* Set RTLD_NOW for this object.  */
#define DF_1_GLOBAL	0x00000002	/* Set RTLD_GLOBAL for this object.  */
#define DF_1_GROUP	0x00000004	/* Set RTLD_GROUP for this object.  */
#define DF_1_NODELETE	0x00000008	/* Set RTLD_NODELETE for this object.*/
#define DF_1_LOADFLTR	0x00000010	/* Trigger filtee loading at runtime.*/
#define DF_1_INITFIRST	0x00000020	/* Set RTLD_INITFIRST for this object*/

libjit/jit/jit-elf-defs.h  view on Meta::CPAN

#define DT_MIPS_UNREFEXTNO   0x70000012	/* First external DYNSYM */
#define DT_MIPS_GOTSYM	     0x70000013	/* First GOT entry in DYNSYM */
#define DT_MIPS_HIPAGENO     0x70000014	/* Number of GOT page table entries */
#define DT_MIPS_RLD_MAP	     0x70000016	/* Address of run time loader map.  */
#define DT_MIPS_DELTA_CLASS  0x70000017	/* Delta C++ class definition.  */
#define DT_MIPS_DELTA_CLASS_NO    0x70000018 /* Number of entries in
						DT_MIPS_DELTA_CLASS.  */
#define DT_MIPS_DELTA_INSTANCE    0x70000019 /* Delta C++ class instances.  */
#define DT_MIPS_DELTA_INSTANCE_NO 0x7000001a /* Number of entries in
						DT_MIPS_DELTA_INSTANCE.  */
#define DT_MIPS_DELTA_RELOC  0x7000001b /* Delta relocations.  */
#define DT_MIPS_DELTA_RELOC_NO 0x7000001c /* Number of entries in
					     DT_MIPS_DELTA_RELOC.  */
#define DT_MIPS_DELTA_SYM    0x7000001d /* Delta symbols that Delta
					   relocations refer to.  */
#define DT_MIPS_DELTA_SYM_NO 0x7000001e /* Number of entries in
					   DT_MIPS_DELTA_SYM.  */
#define DT_MIPS_DELTA_CLASSSYM 0x70000020 /* Delta symbols that hold the
					     class declaration.  */
#define DT_MIPS_DELTA_CLASSSYM_NO 0x70000021 /* Number of entries in
						DT_MIPS_DELTA_CLASSSYM.  */
#define DT_MIPS_CXX_FLAGS    0x70000022 /* Flags indicating for C++ flavor.  */
#define DT_MIPS_PIXIE_INIT   0x70000023
#define DT_MIPS_SYMBOL_LIB   0x70000024
#define DT_MIPS_LOCALPAGE_GOTIDX 0x70000025

libjit/jit/jit-elf-defs.h  view on Meta::CPAN

#define R_PARISC_PCREL17R	11	/* Right 17 bits of rel. address.  */
#define R_PARISC_PCREL17F	12	/* 17 bits of rel. address.  */
#define R_PARISC_PCREL14R	14	/* Right 14 bits of rel. address.  */
#define R_PARISC_DPREL21L	18	/* Left 21 bits of rel. address.  */
#define R_PARISC_DPREL14R	22	/* Right 14 bits of rel. address.  */
#define R_PARISC_GPREL21L	26	/* GP-relative, left 21 bits.  */
#define R_PARISC_GPREL14R	30	/* GP-relative, right 14 bits.  */
#define R_PARISC_LTOFF21L	34	/* LT-relative, left 21 bits.  */
#define R_PARISC_LTOFF14R	38	/* LT-relative, right 14 bits.  */
#define R_PARISC_SECREL32	41	/* 32 bits section rel. address.  */
#define R_PARISC_SEGBASE	48	/* No relocation, set segment base.  */
#define R_PARISC_SEGREL32	49	/* 32 bits segment rel. address.  */
#define R_PARISC_PLTOFF21L	50	/* PLT rel. address, left 21 bits.  */
#define R_PARISC_PLTOFF14R	54	/* PLT rel. address, right 14 bits.  */
#define R_PARISC_LTOFF_FPTR32	57	/* 32 bits LT-rel. function pointer. */
#define R_PARISC_LTOFF_FPTR21L	58	/* LT-rel. fct ptr, left 21 bits. */
#define R_PARISC_LTOFF_FPTR14R	62	/* LT-rel. fct ptr, right 14 bits. */
#define R_PARISC_FPTR64		64	/* 64 bits function address.  */
#define R_PARISC_PLABEL32	65	/* 32 bits function address.  */
#define R_PARISC_PCREL64	72	/* 64 bits PC-rel. address.  */
#define R_PARISC_PCREL22F	74	/* 22 bits PC-rel. address.  */

libjit/jit/jit-elf-defs.h  view on Meta::CPAN

#define R_PARISC_PLTOFF16F	117	/* 16 bits LT-rel. address.  */
#define R_PARISC_PLTOFF16WF	118	/* 16 bits PLT-rel. address.  */
#define R_PARISC_PLTOFF16DF	119	/* 16 bits PLT-rel. address.  */
#define R_PARISC_LTOFF_FPTR64	120	/* 64 bits LT-rel. function ptr.  */
#define R_PARISC_LTOFF_FPTR14WR	123	/* LT-rel. fct. ptr., right 14 bits. */
#define R_PARISC_LTOFF_FPTR14DR	124	/* LT-rel. fct. ptr., right 14 bits. */
#define R_PARISC_LTOFF_FPTR16F	125	/* 16 bits LT-rel. function ptr.  */
#define R_PARISC_LTOFF_FPTR16WF	126	/* 16 bits LT-rel. function ptr.  */
#define R_PARISC_LTOFF_FPTR16DF	127	/* 16 bits LT-rel. function ptr.  */
#define R_PARISC_LORESERVE	128
#define R_PARISC_COPY		128	/* Copy relocation.  */
#define R_PARISC_IPLT		129	/* Dynamic reloc, imported PLT */
#define R_PARISC_EPLT		130	/* Dynamic reloc, exported PLT */
#define R_PARISC_TPREL32	153	/* 32 bits TP-rel. address.  */
#define R_PARISC_TPREL21L	154	/* TP-rel. address, left 21 bits.  */
#define R_PARISC_TPREL14R	158	/* TP-rel. address, right 14 bits.  */
#define R_PARISC_LTOFF_TP21L	162	/* LT-TP-rel. address, left 21 bits. */
#define R_PARISC_LTOFF_TP14R	166	/* LT-TP-rel. address, right 14 bits.*/
#define R_PARISC_LTOFF_TP14F	167	/* 14 bits LT-TP-rel. address.  */
#define R_PARISC_TPREL64	216	/* 64 bits TP-rel. address.  */
#define R_PARISC_TPREL14WR	219	/* TP-rel. address, right 14 bits.  */

libjit/jit/jit-elf-defs.h  view on Meta::CPAN

/* Keep this the last entry.  */
#define R_ALPHA_NUM		28


/* PowerPC specific declarations */

/* Values for Elf32/64_Ehdr.e_flags.  */
#define EF_PPC_EMB		0x80000000	/* PowerPC embedded flag */

/* Cygnus local bits below */
#define EF_PPC_RELOCATABLE	0x00010000	/* PowerPC -mrelocatable flag*/
#define EF_PPC_RELOCATABLE_LIB	0x00008000	/* PowerPC -mrelocatable-lib
						   flag */

/* PowerPC relocations defined by the ABIs */
#define R_PPC_NONE		0
#define R_PPC_ADDR32		1	/* 32bit absolute address */
#define R_PPC_ADDR24		2	/* 26bit address, 2 bits ignored.  */
#define R_PPC_ADDR16		3	/* 16bit absolute address */
#define R_PPC_ADDR16_LO		4	/* lower 16bit of absolute address */
#define R_PPC_ADDR16_HI		5	/* high 16bit of absolute address */
#define R_PPC_ADDR16_HA		6	/* adjusted high 16bit */
#define R_PPC_ADDR14		7	/* 16bit address, 2 bits ignored */
#define R_PPC_ADDR14_BRTAKEN	8
#define R_PPC_ADDR14_BRNTAKEN	9

libjit/jit/jit-elf-defs.h  view on Meta::CPAN

#define R_PPC_EMB_SDA2REL	108
#define R_PPC_EMB_SDA21		109	/* 16 bit offset in SDA */
#define R_PPC_EMB_MRKREF	110
#define R_PPC_EMB_RELSEC16	111
#define R_PPC_EMB_RELST_LO	112
#define R_PPC_EMB_RELST_HI	113
#define R_PPC_EMB_RELST_HA	114
#define R_PPC_EMB_BIT_FLD	115
#define R_PPC_EMB_RELSDA	116	/* 16 bit relative offset in SDA */

/* Diab tool relocations.  */
#define R_PPC_DIAB_SDA21_LO	180	/* like EMB_SDA21, but lower 16 bit */
#define R_PPC_DIAB_SDA21_HI	181	/* like EMB_SDA21, but high 16 bit */
#define R_PPC_DIAB_SDA21_HA	182	/* like EMB_SDA21, adjusted high 16 */
#define R_PPC_DIAB_RELSDA_LO	183	/* like EMB_RELSDA, but lower 16 bit */
#define R_PPC_DIAB_RELSDA_HI	184	/* like EMB_RELSDA, but high 16 bit */
#define R_PPC_DIAB_RELSDA_HA	185	/* like EMB_RELSDA, adjusted high 16 */

/* This is a phony reloc to handle any old fashioned TOC16 references
   that may still be in object files.  */
#define R_PPC_TOC16		255

libjit/jit/jit-elf-defs.h  view on Meta::CPAN

#define SHT_IA_64_UNWIND	(SHT_LOPROC + 1) /* unwind bits */

/* Processor specific flags for the Shdr sh_flags field.  */
#define SHF_IA_64_SHORT		0x10000000	/* section near gp */
#define SHF_IA_64_NORECOV	0x20000000	/* spec insns w/o recovery */

/* Processor specific values for the Dyn d_tag field.  */
#define DT_IA_64_PLT_RESERVE	(DT_LOPROC + 0)
#define DT_IA_64_NUM		1

/* IA-64 relocations.  */
#define R_IA64_NONE		0x00	/* none */
#define R_IA64_IMM14		0x21	/* symbol + addend, add imm14 */
#define R_IA64_IMM22		0x22	/* symbol + addend, add imm22 */
#define R_IA64_IMM64		0x23	/* symbol + addend, mov imm64 */
#define R_IA64_DIR32MSB		0x24	/* symbol + addend, data4 MSB */
#define R_IA64_DIR32LSB		0x25	/* symbol + addend, data4 LSB */
#define R_IA64_DIR64MSB		0x26	/* symbol + addend, data8 MSB */
#define R_IA64_DIR64LSB		0x27	/* symbol + addend, data8 LSB */
#define R_IA64_GPREL22		0x2a	/* @gprel(sym + add), add imm22 */
#define R_IA64_GPREL64I		0x2b	/* @gprel(sym + add), mov imm64 */

libjit/jit/jit-elf-defs.h  view on Meta::CPAN

#define R_IA64_REL64LSB		0x6f	/* data 8 + REL */
#define R_IA64_LTV32MSB		0x74	/* symbol + addend, data4 MSB */
#define R_IA64_LTV32LSB		0x75	/* symbol + addend, data4 LSB */
#define R_IA64_LTV64MSB		0x76	/* symbol + addend, data8 MSB */
#define R_IA64_LTV64LSB		0x77	/* symbol + addend, data8 LSB */
#define R_IA64_PCREL21BI	0x79	/* @pcrel(sym + add), 21bit inst */
#define R_IA64_PCREL22		0x7a	/* @pcrel(sym + add), 22bit inst */
#define R_IA64_PCREL64I		0x7b	/* @pcrel(sym + add), 64bit inst */
#define R_IA64_IPLTMSB		0x80	/* dynamic reloc, imported PLT, MSB */
#define R_IA64_IPLTLSB		0x81	/* dynamic reloc, imported PLT, LSB */
#define R_IA64_COPY		0x84	/* copy relocation */
#define R_IA64_SUB		0x85	/* Addend and symbol difference */
#define R_IA64_LTOFF22X		0x86	/* LTOFF22, relaxable.  */
#define R_IA64_LDXMOV		0x87	/* Use of LTOFF22X.  */
#define R_IA64_TPREL14		0x91	/* @tprel(sym + add), imm14 */
#define R_IA64_TPREL22		0x92	/* @tprel(sym + add), imm22 */
#define R_IA64_TPREL64I		0x93	/* @tprel(sym + add), imm64 */
#define R_IA64_TPREL64MSB	0x96	/* @tprel(sym + add), data8 MSB */
#define R_IA64_TPREL64LSB	0x97	/* @tprel(sym + add), data8 LSB */
#define R_IA64_LTOFF_TPREL22	0x9a	/* @ltoff(@tprel(s+a)), imm2 */
#define R_IA64_DTPMOD64MSB	0xa6	/* @dtpmod(sym + add), data8 MSB */

libjit/jit/jit-elf-defs.h  view on Meta::CPAN

#define R_390_GOTPCDBL	21	       /* 32 bit PC rel. GOT shifted by 1.  */
#define R_390_64	22	       /* Direct 64 bit.  */
#define R_390_PC64	23	       /* PC relative 64 bit.  */
#define R_390_GOT64	24	       /* 64 bit GOT offset.  */
#define R_390_PLT64	25	       /* 64 bit PC relative PLT address.  */
#define R_390_GOTENT	26	       /* 32 bit PC rel. to GOT entry >> 1. */

/* Keep this the last entry.  */
#define R_390_NUM	27

/* CRIS relocations.  */
#define R_CRIS_NONE		0
#define R_CRIS_8		1
#define R_CRIS_16		2
#define R_CRIS_32		3
#define R_CRIS_8_PCREL		4
#define R_CRIS_16_PCREL		5
#define R_CRIS_32_PCREL		6
#define R_CRIS_GNU_VTINHERIT	7
#define R_CRIS_GNU_VTENTRY	8
#define R_CRIS_COPY		9

libjit/jit/jit-elf-defs.h  view on Meta::CPAN

#define R_CRIS_16_GOT		13
#define R_CRIS_32_GOT		14
#define R_CRIS_16_GOTPLT	15
#define R_CRIS_32_GOTPLT	16
#define R_CRIS_32_GOTREL	17
#define R_CRIS_32_PLT_GOTREL	18
#define R_CRIS_32_PLT_PCREL	19

#define R_CRIS_NUM		20

/* AMD x86-64 relocations.  */
#define R_X86_64_NONE		0	/* No reloc */
#define R_X86_64_64		1	/* Direct 64 bit  */
#define R_X86_64_PC32		2	/* PC relative 32 bit signed */
#define R_X86_64_GOT32		3	/* 32 bit GOT entry */
#define R_X86_64_PLT32		4	/* 32 bit PLT address */
#define R_X86_64_COPY		5	/* Copy symbol at runtime */
#define R_X86_64_GLOB_DAT	6	/* Create GOT entry */
#define R_X86_64_JUMP_SLOT	7	/* Create PLT entry */
#define R_X86_64_RELATIVE	8	/* Adjust by program base */
#define R_X86_64_GOTPCREL	9	/* 32 bit signed pc relative

libjit/jit/jit-elf-read.c  view on Meta::CPAN

	#define sys_open		open
	#define	sys_close		close
	#define	sys_read		read
	#define	sys_lseek		lseek
#endif
#ifndef O_BINARY
	#define	O_BINARY		0
#endif

/*
 * Define the relocation function type.
 */
typedef int (*jit_reloc_func)(jit_readelf_t readelf, void *address,
							  int type, jit_nuint value, int has_addend,
							  jit_nuint addend);

/*
 * Get the relocation function for a particular machine type.
 */
static jit_reloc_func get_reloc(unsigned int machine);

/*
 * Structure of an ELF binary once it has been loaded into memory.
 */
struct jit_readelf
{
	jit_readelf_t	next;
	int				resolved;

libjit/jit/jit-elf-read.c  view on Meta::CPAN

					   index,
				       get_string(readelf, shdr->sh_name),
				       (int)(shdr->sh_type),
				       (int)(shdr->sh_flags & ~JIT_ELF_IS_MALLOCED),
				           (long)(shdr->sh_addr),
				       (long)(shdr->sh_size));
			}
		}
	}

	/* Get the relocation function for this machine type */
	readelf->reloc_func = get_reloc((unsigned int)(ehdr.e_machine));

	/* Load useful values from the dynamic section that we want to cache */
	load_dynamic_section(readelf, flags);

	/* The ELF binary is loaded and ready to go */
	*_readelf = readelf;
	return JIT_READELF_OK;
}

libjit/jit/jit-elf-read.c  view on Meta::CPAN

			return context->registered_symbols[index]->value;
		}
	}

	/* If we get here, then we could not resolve the symbol */
	printf("%s: could not resolve `%s'\n", name, symbol_name);
	return 0;
}

/*
 * Perform a DT_REL style relocation on an ELF binary.
 */
static int perform_rel
	(jit_context_t context, jit_readelf_t readelf, 
	 int print_failures, const char *name, Elf_Rel *reloc)
{
	void *address;
	void *value;

	/* Get the address to apply the relocation at */
	address = jit_readelf_map_vaddr(readelf, (jit_nuint)(reloc->r_offset));
	if(!address)
	{
		if(print_failures)
		{
			printf("%s: cannot map virtual address 0x%lx\n",
				   name, (long)(reloc->r_offset));
		}
		return 0;
	}

	/* Resolve the designated symbol to its actual value */
	value = resolve_symbol
		(context, readelf, print_failures, name,
		 (jit_nuint)ELF_R_SYM(reloc->r_info));
	if(!value)
	{
		return 0;
	}

	/* Perform the relocation */
	if(!(*(readelf->reloc_func))
		(readelf, address, (int)(ELF_R_TYPE(reloc->r_info)),
		 (jit_nuint)value, 0, 0))
	{
		if(print_failures)
		{
			printf("%s: relocation type %d was not recognized\n",
				   name, (int)(ELF_R_TYPE(reloc->r_info)));
		}
		return 0;
	}
	return 1;
}

/*
 * Perform a DT_RELA style relocation on an ELF binary.
 */
static int perform_rela
	(jit_context_t context, jit_readelf_t readelf,
	 int print_failures, const char *name, Elf_Rela *reloc)
{
	void *address;
	void *value;

	/* Get the address to apply the relocation at */
	address = jit_readelf_map_vaddr(readelf, (jit_nuint)(reloc->r_offset));
	if(!address)
	{
		if(print_failures)
		{
			printf("%s: cannot map virtual address 0x%lx\n",
				   name, (long)(reloc->r_offset));
		}
		return 0;
	}

	/* Resolve the designated symbol to its actual value */
	value = resolve_symbol
		(context, readelf, print_failures, name,
		 (jit_nuint)ELF_R_SYM(reloc->r_info));
	if(!value)
	{
		return 0;
	}

	/* Perform the relocation */
	if(!(*(readelf->reloc_func))
		(readelf, address, (int)(ELF_R_TYPE(reloc->r_info)),
		 (jit_nuint)value, 1, (jit_nuint)(reloc->r_addend)))
	{
		if(print_failures)
		{
			printf("%s: relocation type %d was not recognized\n",
				   name, (int)(ELF_R_TYPE(reloc->r_info)));
		}
		return 0;
	}
	return 1;
}

/*
 * Perform relocations on an ELF binary.  Returns zero on failure.
 */
static int perform_relocations
	(jit_context_t context, jit_readelf_t readelf, int print_failures)
{
	Elf_Addr address;
	Elf_Addr table_size;
	Elf_Addr entry_size;
	unsigned char *table;
	const char *name;
	int ok = 1;

	/* Get the library name, for printing diagnostic messages */
	name = jit_readelf_get_name(readelf);
	if(!name)
	{
		name = "unknown-elf-binary";
	}

	/* Bail out if we don't know how to perform relocations */
	if(!(readelf->reloc_func))
	{
		if(print_failures)
		{
			printf("%s: do not know how to perform relocations\n", name);
		}
		return 0;
	}

	/* Apply the "Rel" relocations in the dynamic section */
	if(dynamic_for_type(readelf, DT_REL, &address) &&
	   dynamic_for_type(readelf, DT_RELSZ, &table_size) &&
	   dynamic_for_type(readelf, DT_RELENT, &entry_size) && entry_size)
	{
		table = (unsigned char *)jit_readelf_map_vaddr
			(readelf, (jit_nuint)address);
		while(table && table_size >= entry_size)
		{
			if(!perform_rel(context, readelf, print_failures, name,
					        (Elf_Rel *)table))
			{
				ok = 0;
			}
			table += (jit_nuint)entry_size;
			table_size -= entry_size;
		}
	}

	/* Apply the "Rela" relocations in the dynamic section */
	if(dynamic_for_type(readelf, DT_RELA, &address) &&
	   dynamic_for_type(readelf, DT_RELASZ, &table_size) &&
	   dynamic_for_type(readelf, DT_RELAENT, &entry_size) && entry_size)
	{
		table = (unsigned char *)jit_readelf_map_vaddr
			(readelf, (jit_nuint)address);
		while(table && table_size >= entry_size)
		{
			if(!perform_rela(context, readelf, print_failures, name,
					         (Elf_Rela *)table))
			{
				ok = 0;
			}
			table += (jit_nuint)entry_size;
			table_size -= entry_size;
		}
	}

	/* Apply the "PLT" relocations in the dynamic section, which
	   may be either DT_REL or DT_RELA style relocations */
	if(dynamic_for_type(readelf, DT_JMPREL, &address) &&
	   dynamic_for_type(readelf, DT_PLTRELSZ, &table_size) &&
	   dynamic_for_type(readelf, DT_PLTREL, &entry_size))
	{
		if(entry_size == DT_REL)
		{
			if(dynamic_for_type(readelf, DT_RELENT, &entry_size) && entry_size)
			{
				table = (unsigned char *)jit_readelf_map_vaddr
					(readelf, (jit_nuint)address);

libjit/jit/jit-elf-read.c  view on Meta::CPAN

	}

	_jit_memory_lock(context);

	readelf = context->elf_binaries;
	while(readelf != 0)
	{
		if(!(readelf->resolved))
		{
			readelf->resolved = 1;
			if(!perform_relocations(context, readelf, print_failures))
			{
				ok = 0;
			}
		}
		readelf = readelf->next;
	}

	_jit_memory_unlock(context);
	return ok;
}

libjit/jit/jit-elf-read.c  view on Meta::CPAN

	new_list[(context->num_registered_symbols)++] = sym;
	context->registered_symbols = new_list;
	return 1;
}

/************************************************************************

		             Warning!  Warning!  Warning!

The following code is very system-dependent, as every ELF target has its
own peculiar mechanism for performing relocations.  Consult your target's
documentation for the precise details.

To make things a little easier, you only need to support the relocation
types that you intend to use in the JIT's ELF writer.  And many types
only pertain to ELF executable or object files, which we don't use.

************************************************************************/

#if defined(__i386) || defined(__i386__) || defined(_M_IX86)

/*
 * Apply relocations for i386 platforms.
 */
static int i386_reloc(jit_readelf_t readelf, void *address, int type,
					  jit_nuint value, int has_addend, jit_nuint addend)
{
	if(type == R_386_32)
	{
		if(has_addend)
		{
			*((jit_nuint *)address) = value + addend;
		}

libjit/jit/jit-elf-read.c  view on Meta::CPAN

		return 1;
	}
	return 0;
}

#endif /* i386 */

#if defined(__arm) || defined(__arm__)

/*
 * Apply relocations for ARM platforms.
 */
static int arm_reloc(jit_readelf_t readelf, void *address, int type,
					 jit_nuint value, int has_addend, jit_nuint addend)
{
	if(type == R_ARM_PC24)
	{
		value -= (jit_nuint)address;
		if(has_addend)
		{
			*((jit_nuint *)address) =

libjit/jit/jit-elf-read.c  view on Meta::CPAN

			*((jit_nuint *)address) += value;
		}
		return 1;
	}
	return 0;
}

#endif /* arm */

/*
 * Apply relocations for the interpreted platform.
 */
static int interp_reloc(jit_readelf_t readelf, void *address, int type,
						jit_nuint value, int has_addend, jit_nuint addend)
{
	/* We only have one type of relocation for the interpreter: direct */
	if(type == 1)
	{
		*((jit_nuint *)address) = value;
		return 1;
	}
	else
	{
		return 0;
	}
}

/*
 * Get the relocation function for a particular machine type.
 */
static jit_reloc_func get_reloc(unsigned int machine)
{
#if defined(__i386) || defined(__i386__) || defined(_M_IX86)
	if(machine == EM_386)
	{
		return i386_reloc;
	}
#endif
#if defined(__arm) || defined(__arm__)

libjit/jit/jit-rules-x86.ins  view on Meta::CPAN

	}
	[=freg, lreg] -> {
		x86_push_reg(inst, %2);
		x86_push_reg(inst, $2);
		x86_fild_membase(inst, X86_ESP, 0, 1);
		x86_alu_reg_imm(inst, X86_ADD, X86_ESP, sizeof(jit_long));
	}

JIT_OP_ULONG_TO_FLOAT32, JIT_OP_ULONG_TO_FLOAT64, JIT_OP_ULONG_TO_NFLOAT: more_space
	[=freg, lreg] -> {
		/* TODO: review wrt relocation for elf pre-compilation */
		static float f2pow64;
		static int inited;
		unsigned char *patch;
		if(!inited)
		{
			f2pow64 = jit_float32_pow(2.0, 64);
			inited = 1;
		}
		x86_push_reg(inst, %2);
		x86_push_reg(inst, $2);



( run in 1.759 second using v1.01-cache-2.11-cpan-71847e10f99 )