Lines Matching +full:core +full:- +full:module

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2014-2017 Linaro Ltd. <ard.biesheuvel@linaro.org>
9 #include <linux/module.h>
18 (PLT_ENT_STRIDE - 4))
21 (PLT_ENT_STRIDE - 8))
31 static bool in_init(const struct module *mod, unsigned long loc) in in_init()
33 return loc - (u32)mod->init_layout.base < mod->init_layout.size; in in_init()
40 if (!ARRAY_SIZE(fixed_plts) || pltsec->plt_count) in prealloc_fixed()
42 pltsec->plt_count = ARRAY_SIZE(fixed_plts); in prealloc_fixed()
44 for (i = 0; i < ARRAY_SIZE(plt->ldr); ++i) in prealloc_fixed()
45 plt->ldr[i] = PLT_ENT_LDR; in prealloc_fixed()
47 BUILD_BUG_ON(sizeof(fixed_plts) > sizeof(plt->lit)); in prealloc_fixed()
48 memcpy(plt->lit, fixed_plts, sizeof(fixed_plts)); in prealloc_fixed()
51 u32 get_module_plt(struct module *mod, unsigned long loc, Elf32_Addr val) in get_module_plt()
53 struct mod_plt_sec *pltsec = !in_init(mod, loc) ? &mod->arch.core : in get_module_plt()
54 &mod->arch.init; in get_module_plt()
58 /* cache the address, ELF header is available only during module load */ in get_module_plt()
59 if (!pltsec->plt_ent) in get_module_plt()
60 pltsec->plt_ent = (struct plt_entries *)pltsec->plt->sh_addr; in get_module_plt()
61 plt = pltsec->plt_ent; in get_module_plt()
66 if (plt->lit[idx] == val) in get_module_plt()
67 return (u32)&plt->ldr[idx]; in get_module_plt()
75 if (pltsec->plt_count > 0) { in get_module_plt()
76 plt += (pltsec->plt_count - 1) / PLT_ENT_COUNT; in get_module_plt()
77 idx = (pltsec->plt_count - 1) % PLT_ENT_COUNT; in get_module_plt()
79 if (plt->lit[idx] == val) in get_module_plt()
80 return (u32)&plt->ldr[idx]; in get_module_plt()
87 pltsec->plt_count++; in get_module_plt()
88 BUG_ON(pltsec->plt_count * PLT_ENT_SIZE > pltsec->plt->sh_size); in get_module_plt()
93 { [0 ... PLT_ENT_COUNT - 1] = PLT_ENT_LDR, }, in get_module_plt()
97 plt->lit[idx] = val; in get_module_plt()
99 return (u32)&plt->ldr[idx]; in get_module_plt()
102 #define cmp_3way(a,b) ((a) < (b) ? -1 : (a) > (b))
110 i = cmp_3way(ELF32_R_TYPE(x->r_info), ELF32_R_TYPE(y->r_info)); in cmp_rel()
112 i = cmp_3way(ELF32_R_SYM(x->r_info), ELF32_R_SYM(y->r_info)); in cmp_rel()
118 u32 *tval = (u32 *)(base + rel->r_offset); in is_zero_addend_relocation()
123 * Note that a zero-addend jump/call relocation is encoded taking the in is_zero_addend_relocation()
124 * PC bias into account, i.e., -8 for ARM and -4 for Thumb2. in is_zero_addend_relocation()
126 switch (ELF32_R_TYPE(rel->r_info)) { in is_zero_addend_relocation()
156 prev = rel + num - 1; in duplicate_rel()
188 if (s->st_shndx == dstidx) in count_plts()
192 * Jump relocations with non-zero addends against in count_plts()
199 * the addend is zero. (Note that calls into the core in count_plts()
200 * module via init PLT entries could involve section in count_plts()
201 * relative symbol references with non-zero addends, for in count_plts()
204 * region as soon as module loading completes.) in count_plts()
215 char *secstrings, struct module *mod) in module_frob_arch_sections()
219 Elf32_Shdr *s, *sechdrs_end = sechdrs + ehdr->e_shnum; in module_frob_arch_sections()
223 * To store the PLTs, we expand the .text section for core module code in module_frob_arch_sections()
227 if (strcmp(".plt", secstrings + s->sh_name) == 0) in module_frob_arch_sections()
228 mod->arch.core.plt = s; in module_frob_arch_sections()
229 else if (strcmp(".init.plt", secstrings + s->sh_name) == 0) in module_frob_arch_sections()
230 mod->arch.init.plt = s; in module_frob_arch_sections()
231 else if (s->sh_type == SHT_SYMTAB) in module_frob_arch_sections()
232 syms = (Elf32_Sym *)s->sh_addr; in module_frob_arch_sections()
235 if (!mod->arch.core.plt || !mod->arch.init.plt) { in module_frob_arch_sections()
236 pr_err("%s: module PLT section(s) missing\n", mod->name); in module_frob_arch_sections()
237 return -ENOEXEC; in module_frob_arch_sections()
240 pr_err("%s: module symtab section missing\n", mod->name); in module_frob_arch_sections()
241 return -ENOEXEC; in module_frob_arch_sections()
245 Elf32_Rel *rels = (void *)ehdr + s->sh_offset; in module_frob_arch_sections()
246 int numrels = s->sh_size / sizeof(Elf32_Rel); in module_frob_arch_sections()
247 Elf32_Shdr *dstsec = sechdrs + s->sh_info; in module_frob_arch_sections()
249 if (s->sh_type != SHT_REL) in module_frob_arch_sections()
252 /* ignore relocations that operate on non-exec sections */ in module_frob_arch_sections()
253 if (!(dstsec->sh_flags & SHF_EXECINSTR)) in module_frob_arch_sections()
259 if (strncmp(secstrings + dstsec->sh_name, ".init", 5) != 0) in module_frob_arch_sections()
260 core_plts += count_plts(syms, dstsec->sh_addr, rels, in module_frob_arch_sections()
261 numrels, s->sh_info); in module_frob_arch_sections()
263 init_plts += count_plts(syms, dstsec->sh_addr, rels, in module_frob_arch_sections()
264 numrels, s->sh_info); in module_frob_arch_sections()
267 mod->arch.core.plt->sh_type = SHT_NOBITS; in module_frob_arch_sections()
268 mod->arch.core.plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC; in module_frob_arch_sections()
269 mod->arch.core.plt->sh_addralign = L1_CACHE_BYTES; in module_frob_arch_sections()
270 mod->arch.core.plt->sh_size = round_up(core_plts * PLT_ENT_SIZE, in module_frob_arch_sections()
272 mod->arch.core.plt_count = 0; in module_frob_arch_sections()
273 mod->arch.core.plt_ent = NULL; in module_frob_arch_sections()
275 mod->arch.init.plt->sh_type = SHT_NOBITS; in module_frob_arch_sections()
276 mod->arch.init.plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC; in module_frob_arch_sections()
277 mod->arch.init.plt->sh_addralign = L1_CACHE_BYTES; in module_frob_arch_sections()
278 mod->arch.init.plt->sh_size = round_up(init_plts * PLT_ENT_SIZE, in module_frob_arch_sections()
280 mod->arch.init.plt_count = 0; in module_frob_arch_sections()
281 mod->arch.init.plt_ent = NULL; in module_frob_arch_sections()
284 mod->arch.core.plt->sh_size, mod->arch.init.plt->sh_size); in module_frob_arch_sections()