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>
8 #include <linux/module.h>
21 (PLT_ENT_STRIDE - 4))
24 (PLT_ENT_STRIDE - 8))
32 static bool in_init(const struct module *mod, unsigned long loc) in in_init()
34 return loc - (u32)mod->init_layout.base < mod->init_layout.size; in in_init()
37 u32 get_module_plt(struct module *mod, unsigned long loc, Elf32_Addr val) in get_module_plt()
39 struct mod_plt_sec *pltsec = !in_init(mod, loc) ? &mod->arch.core : in get_module_plt()
40 &mod->arch.init; in get_module_plt()
42 struct plt_entries *plt = (struct plt_entries *)pltsec->plt->sh_addr; in get_module_plt()
50 if (pltsec->plt_count > 0) { in get_module_plt()
51 plt += (pltsec->plt_count - 1) / PLT_ENT_COUNT; in get_module_plt()
52 idx = (pltsec->plt_count - 1) % PLT_ENT_COUNT; in get_module_plt()
54 if (plt->lit[idx] == val) in get_module_plt()
55 return (u32)&plt->ldr[idx]; in get_module_plt()
62 pltsec->plt_count++; in get_module_plt()
63 BUG_ON(pltsec->plt_count * PLT_ENT_SIZE > pltsec->plt->sh_size); in get_module_plt()
68 { [0 ... PLT_ENT_COUNT - 1] = PLT_ENT_LDR, }, in get_module_plt()
72 plt->lit[idx] = val; in get_module_plt()
74 return (u32)&plt->ldr[idx]; in get_module_plt()
77 #define cmp_3way(a,b) ((a) < (b) ? -1 : (a) > (b))
85 i = cmp_3way(ELF32_R_TYPE(x->r_info), ELF32_R_TYPE(y->r_info)); in cmp_rel()
87 i = cmp_3way(ELF32_R_SYM(x->r_info), ELF32_R_SYM(y->r_info)); in cmp_rel()
93 u32 *tval = (u32 *)(base + rel->r_offset); in is_zero_addend_relocation()
98 * Note that a zero-addend jump/call relocation is encoded taking the in is_zero_addend_relocation()
99 * PC bias into account, i.e., -8 for ARM and -4 for Thumb2. in is_zero_addend_relocation()
101 switch (ELF32_R_TYPE(rel->r_info)) { in is_zero_addend_relocation()
131 prev = rel + num - 1; in duplicate_rel()
163 if (s->st_shndx == dstidx) in count_plts()
167 * Jump relocations with non-zero addends against in count_plts()
174 * the addend is zero. (Note that calls into the core in count_plts()
175 * module via init PLT entries could involve section in count_plts()
176 * relative symbol references with non-zero addends, for in count_plts()
179 * region as soon as module loading completes.) in count_plts()
190 char *secstrings, struct module *mod) in module_frob_arch_sections()
194 Elf32_Shdr *s, *sechdrs_end = sechdrs + ehdr->e_shnum; in module_frob_arch_sections()
198 * To store the PLTs, we expand the .text section for core module code in module_frob_arch_sections()
202 if (strcmp(".plt", secstrings + s->sh_name) == 0) in module_frob_arch_sections()
203 mod->arch.core.plt = s; in module_frob_arch_sections()
204 else if (strcmp(".init.plt", secstrings + s->sh_name) == 0) in module_frob_arch_sections()
205 mod->arch.init.plt = s; in module_frob_arch_sections()
206 else if (s->sh_type == SHT_SYMTAB) in module_frob_arch_sections()
207 syms = (Elf32_Sym *)s->sh_addr; in module_frob_arch_sections()
210 if (!mod->arch.core.plt || !mod->arch.init.plt) { in module_frob_arch_sections()
211 pr_err("%s: module PLT section(s) missing\n", mod->name); in module_frob_arch_sections()
212 return -ENOEXEC; in module_frob_arch_sections()
215 pr_err("%s: module symtab section missing\n", mod->name); in module_frob_arch_sections()
216 return -ENOEXEC; in module_frob_arch_sections()
220 Elf32_Rel *rels = (void *)ehdr + s->sh_offset; in module_frob_arch_sections()
221 int numrels = s->sh_size / sizeof(Elf32_Rel); in module_frob_arch_sections()
222 Elf32_Shdr *dstsec = sechdrs + s->sh_info; in module_frob_arch_sections()
224 if (s->sh_type != SHT_REL) in module_frob_arch_sections()
227 /* ignore relocations that operate on non-exec sections */ in module_frob_arch_sections()
228 if (!(dstsec->sh_flags & SHF_EXECINSTR)) in module_frob_arch_sections()
234 if (strncmp(secstrings + dstsec->sh_name, ".init", 5) != 0) in module_frob_arch_sections()
235 core_plts += count_plts(syms, dstsec->sh_addr, rels, in module_frob_arch_sections()
236 numrels, s->sh_info); in module_frob_arch_sections()
238 init_plts += count_plts(syms, dstsec->sh_addr, rels, in module_frob_arch_sections()
239 numrels, s->sh_info); in module_frob_arch_sections()
242 mod->arch.core.plt->sh_type = SHT_NOBITS; in module_frob_arch_sections()
243 mod->arch.core.plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC; in module_frob_arch_sections()
244 mod->arch.core.plt->sh_addralign = L1_CACHE_BYTES; in module_frob_arch_sections()
245 mod->arch.core.plt->sh_size = round_up(core_plts * PLT_ENT_SIZE, in module_frob_arch_sections()
247 mod->arch.core.plt_count = 0; in module_frob_arch_sections()
249 mod->arch.init.plt->sh_type = SHT_NOBITS; in module_frob_arch_sections()
250 mod->arch.init.plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC; in module_frob_arch_sections()
251 mod->arch.init.plt->sh_addralign = L1_CACHE_BYTES; in module_frob_arch_sections()
252 mod->arch.init.plt->sh_size = round_up(init_plts * PLT_ENT_SIZE, in module_frob_arch_sections()
254 mod->arch.init.plt_count = 0; in module_frob_arch_sections()
257 mod->arch.core.plt->sh_size, mod->arch.init.plt->sh_size); in module_frob_arch_sections()