Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7523e4dc authored by Rusty Russell's avatar Rusty Russell Committed by Jiri Kosina
Browse files

module: use a structure to encapsulate layout.



Makes it easier to handle init vs core cleanly, though the change is
fairly invasive across random architectures.

It simplifies the rbtree code immediately, however, while keeping the
core data together in the same cachline (now iff the rbtree code is
enabled).

Acked-by: default avatarPeter Zijlstra <peterz@infradead.org>
Reviewed-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent c65abf35
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,

	/* The small sections were sorted to the end of the segment.
	   The following should definitely cover them.  */
	gp = (u64)me->module_core + me->core_size - 0x8000;
	gp = (u64)me->core_layout.base + me->core_layout.size - 0x8000;
	got = sechdrs[me->arch.gotsecindex].sh_addr;

	for (i = 0; i < n; i++) {
+2 −2
Original line number Diff line number Diff line
@@ -372,8 +372,8 @@ void *unwind_add_table(struct module *module, const void *table_start,
		return NULL;

	init_unwind_table(table, module->name,
			  module->module_core, module->core_size,
			  module->module_init, module->init_size,
			  module->core_layout.base, module->core_layout.size,
			  module->init_layout.base, module->init_layout.size,
			  table_start, table_size,
			  NULL, 0);

+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ struct plt_entries {

static bool in_init(const struct module *mod, u32 addr)
{
	return addr - (u32)mod->module_init < mod->init_size;
	return addr - (u32)mod->init_layout.base < mod->init_layout.size;
}

u32 get_module_plt(struct module *mod, unsigned long loc, Elf32_Addr val)
+6 −6
Original line number Diff line number Diff line
@@ -118,9 +118,9 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
	 * Increase core size to make room for GOT and set start
	 * offset for GOT.
	 */
	module->core_size = ALIGN(module->core_size, 4);
	module->arch.got_offset = module->core_size;
	module->core_size += module->arch.got_size;
	module->core_layout.size = ALIGN(module->core_layout.size, 4);
	module->arch.got_offset = module->core_layout.size;
	module->core_layout.size += module->arch.got_size;

	return 0;

@@ -177,7 +177,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, const char *strtab,
			if (!info->got_initialized) {
				Elf32_Addr *gotent;

				gotent = (module->module_core
				gotent = (module->core_layout.base
					  + module->arch.got_offset
					  + info->got_offset);
				*gotent = relocation;
@@ -255,8 +255,8 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, const char *strtab,
			 */
			pr_debug("GOTPC: PC=0x%x, got_offset=0x%lx, core=0x%p\n",
				 relocation, module->arch.got_offset,
				 module->module_core);
			relocation -= ((unsigned long)module->module_core
				 module->core_layout.base);
			relocation -= ((unsigned long)module->core_layout.base
				       + module->arch.got_offset);
			*location = relocation;
			break;
+7 −7
Original line number Diff line number Diff line
@@ -486,13 +486,13 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
static inline int
in_init (const struct module *mod, uint64_t addr)
{
	return addr - (uint64_t) mod->module_init < mod->init_size;
	return addr - (uint64_t) mod->init_layout.base < mod->init_layout.size;
}

static inline int
in_core (const struct module *mod, uint64_t addr)
{
	return addr - (uint64_t) mod->module_core < mod->core_size;
	return addr - (uint64_t) mod->core_layout.base < mod->core_layout.size;
}

static inline int
@@ -675,7 +675,7 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
		break;

	      case RV_BDREL:
		val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
		val -= (uint64_t) (in_init(mod, val) ? mod->init_layout.base : mod->core_layout.base);
		break;

	      case RV_LTV:
@@ -810,15 +810,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
		 *     addresses have been selected...
		 */
		uint64_t gp;
		if (mod->core_size > MAX_LTOFF)
		if (mod->core_layout.size > MAX_LTOFF)
			/*
			 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
			 * at the end of the module.
			 */
			gp = mod->core_size - MAX_LTOFF / 2;
			gp = mod->core_layout.size - MAX_LTOFF / 2;
		else
			gp = mod->core_size / 2;
		gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
			gp = mod->core_layout.size / 2;
		gp = (uint64_t) mod->core_layout.base + ((gp + 7) & -8);
		mod->arch.gp = gp;
		DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
	}
Loading