Ejemplo n.º 1
0
int _jit_block_record_label(jit_block_t block)
{
	jit_builder_t builder = block->func->builder;
	jit_label_t num;
	jit_block_t *blocks;
	if(block->label >= builder->max_label_blocks)
	{
		num = builder->max_label_blocks;
		if(num < 64)
		{
			num = 64;
		}
		while(num <= block->label)
		{
			num *= 2;
		}
		blocks = (jit_block_t *)jit_realloc
			(builder->label_blocks, num * sizeof(jit_block_t));
		if(!blocks)
		{
			return 0;
		}
		jit_memzero(blocks + builder->max_label_blocks,
					sizeof(jit_block_t) * (num - builder->max_label_blocks));
		builder->label_blocks = blocks;
		builder->max_label_blocks = num;
	}
	builder->label_blocks[block->label] = block;
	return 1;
}
Ejemplo n.º 2
0
/*
 * Add an entry to the dynamic linking information section.
 */
static int add_dyn_info
	(jit_writeelf_t writeelf, int type, Elf_Addr value, int modify_existing)
{
	jit_section_t section;
	Elf_Dyn dyn;

	/* Get or create the ".dynamic" section */
	section = get_section(writeelf, ".dynamic", SHT_DYNAMIC,
						  SHF_WRITE | SHF_ALLOC,
						  sizeof(Elf_Dyn), sizeof(Elf_Dyn));
	if(!section)
	{
		return 0;
	}

	/* See if we already have this entry, and modify it as appropriate */
	if(modify_existing)
	{
		Elf_Dyn *existing = (Elf_Dyn *)(section->data);
		unsigned int num = section->data_len / sizeof(Elf_Dyn);
		while(num > 0)
		{
			if(existing->d_tag == type)
			{
				existing->d_un.d_ptr = value;
				return 1;
			}
			++existing;
			--num;
		}
	}

	/* Format the dynamic entry */
	jit_memzero(&dyn, sizeof(dyn));
	dyn.d_tag = type;
	dyn.d_un.d_ptr = value;

	/* Add the entry to the section's contents */
	return add_to_section(section, &dyn, sizeof(dyn));
}
Ejemplo n.º 3
0
/*
 * Get or add a section.
 */
static jit_section_t get_section
	(jit_writeelf_t writeelf, const char *name, jit_int type,
	 Elf_Word flags, Elf_Word entry_size, Elf_Word alignment)
{
	int index;
	jit_section_t section;

	/* Search the section table for an existing section by this name */
	for(index = 0; index < writeelf->num_sections; ++index)
	{
		section = &(writeelf->sections[index]);
		if(!jit_strcmp(get_string(writeelf, section->shdr.sh_name), name))
		{
			return section;
		}
	}

	/* Create a new section and clear it */
	section = (jit_section_t)jit_realloc
		(writeelf->sections,
		 (writeelf->num_sections + 1) * sizeof(struct jit_section));
	if(!section)
	{
		return 0;
	}
	writeelf->sections = section;
	section += writeelf->num_sections;
	jit_memzero(section, sizeof(struct jit_section));

	/* Set the section's name.  If this is the first section created,
	   then it is the string table itself, and we have to add the
	   name to the section itself to start the ball rolling */
	if(writeelf->regular_string_section < 0)
	{
		section->data = (char *)jit_malloc(jit_strlen(name) + 2);
		if(!(section->data))
		{
			return 0;
		}
		section->data_len = jit_strlen(name) + 2;
		section->data[0] = '\0';	/* Empty string is always first */
		jit_strcpy(section->data + 1, name);
		section->shdr.sh_name = 1;
		writeelf->regular_string_section = writeelf->num_sections;
	}
	else
	{
		section->shdr.sh_name = add_string(writeelf, name);
		if(!(section->shdr.sh_name))
		{
			return 0;
		}
	}

	/* Set the other section properties */
	section->shdr.sh_type = (Elf_Word)type;
	section->shdr.sh_flags = flags;
	section->shdr.sh_entsize = entry_size;
	section->shdr.sh_addralign = alignment;

	/* Increase the section count and return */
	++(writeelf->num_sections);
	return section;
}