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))
35 if (!ARRAY_SIZE(fixed_plts) || pltsec->plt_count) in prealloc_fixed()
37 pltsec->plt_count = ARRAY_SIZE(fixed_plts); in prealloc_fixed()
39 for (i = 0; i < ARRAY_SIZE(plt->ldr); ++i) in prealloc_fixed()
40 plt->ldr[i] = PLT_ENT_LDR; in prealloc_fixed()
42 BUILD_BUG_ON(sizeof(fixed_plts) > sizeof(plt->lit)); in prealloc_fixed()
43 memcpy(plt->lit, fixed_plts, sizeof(fixed_plts)); in prealloc_fixed()
46 u32 get_module_plt(struct module *mod, unsigned long loc, Elf32_Addr val) in get_module_plt()
49 &mod->arch.core : &mod->arch.init; in get_module_plt()
53 /* cache the address, ELF header is available only during module load */ in get_module_plt()
54 if (!pltsec->plt_ent) in get_module_plt()
55 pltsec->plt_ent = (struct plt_entries *)pltsec->plt->sh_addr; in get_module_plt()
56 plt = pltsec->plt_ent; in get_module_plt()
61 if (plt->lit[idx] == val) in get_module_plt()
62 return (u32)&plt->ldr[idx]; in get_module_plt()
70 if (pltsec->plt_count > 0) { in get_module_plt()
71 plt += (pltsec->plt_count - 1) / PLT_ENT_COUNT; in get_module_plt()
72 idx = (pltsec->plt_count - 1) % PLT_ENT_COUNT; in get_module_plt()
74 if (plt->lit[idx] == val) in get_module_plt()
75 return (u32)&plt->ldr[idx]; in get_module_plt()
82 pltsec->plt_count++; in get_module_plt()
83 BUG_ON(pltsec->plt_count * PLT_ENT_SIZE > pltsec->plt->sh_size); in get_module_plt()
88 { [0 ... PLT_ENT_COUNT - 1] = PLT_ENT_LDR, }, in get_module_plt()
92 plt->lit[idx] = val; in get_module_plt()
94 return (u32)&plt->ldr[idx]; in get_module_plt()
97 #define cmp_3way(a,b) ((a) < (b) ? -1 : (a) > (b))
105 i = cmp_3way(ELF32_R_TYPE(x->r_info), ELF32_R_TYPE(y->r_info)); in cmp_rel()
107 i = cmp_3way(ELF32_R_SYM(x->r_info), ELF32_R_SYM(y->r_info)); in cmp_rel()
113 u32 *tval = (u32 *)(base + rel->r_offset); in is_zero_addend_relocation()
118 * Note that a zero-addend jump/call relocation is encoded taking the in is_zero_addend_relocation()
119 * PC bias into account, i.e., -8 for ARM and -4 for Thumb2. in is_zero_addend_relocation()
121 switch (ELF32_R_TYPE(rel->r_info)) { in is_zero_addend_relocation()
151 prev = rel + num - 1; in duplicate_rel()
183 if (s->st_shndx == dstidx) in count_plts()
187 * Jump relocations with non-zero addends against in count_plts()
194 * the addend is zero. (Note that calls into the core in count_plts()
195 * module via init PLT entries could involve section in count_plts()
196 * relative symbol references with non-zero addends, for in count_plts()
199 * region as soon as module loading completes.) in count_plts()
210 char *secstrings, struct module *mod) in module_frob_arch_sections()
214 Elf32_Shdr *s, *sechdrs_end = sechdrs + ehdr->e_shnum; in module_frob_arch_sections()
218 * To store the PLTs, we expand the .text section for core module code in module_frob_arch_sections()
222 if (strcmp(".plt", secstrings + s->sh_name) == 0) in module_frob_arch_sections()
223 mod->arch.core.plt = s; in module_frob_arch_sections()
224 else if (strcmp(".init.plt", secstrings + s->sh_name) == 0) in module_frob_arch_sections()
225 mod->arch.init.plt = s; in module_frob_arch_sections()
226 else if (s->sh_type == SHT_SYMTAB) in module_frob_arch_sections()
227 syms = (Elf32_Sym *)s->sh_addr; in module_frob_arch_sections()
230 if (!mod->arch.core.plt || !mod->arch.init.plt) { in module_frob_arch_sections()
231 pr_err("%s: module PLT section(s) missing\n", mod->name); in module_frob_arch_sections()
232 return -ENOEXEC; in module_frob_arch_sections()
235 pr_err("%s: module symtab section missing\n", mod->name); in module_frob_arch_sections()
236 return -ENOEXEC; in module_frob_arch_sections()
240 Elf32_Rel *rels = (void *)ehdr + s->sh_offset; in module_frob_arch_sections()
241 int numrels = s->sh_size / sizeof(Elf32_Rel); in module_frob_arch_sections()
242 Elf32_Shdr *dstsec = sechdrs + s->sh_info; in module_frob_arch_sections()
244 if (s->sh_type != SHT_REL) in module_frob_arch_sections()
247 /* ignore relocations that operate on non-exec sections */ in module_frob_arch_sections()
248 if (!(dstsec->sh_flags & SHF_EXECINSTR)) in module_frob_arch_sections()
254 if (!module_init_layout_section(secstrings + dstsec->sh_name)) in module_frob_arch_sections()
255 core_plts += count_plts(syms, dstsec->sh_addr, rels, in module_frob_arch_sections()
256 numrels, s->sh_info); in module_frob_arch_sections()
258 init_plts += count_plts(syms, dstsec->sh_addr, rels, in module_frob_arch_sections()
259 numrels, s->sh_info); in module_frob_arch_sections()
262 mod->arch.core.plt->sh_type = SHT_NOBITS; in module_frob_arch_sections()
263 mod->arch.core.plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC; in module_frob_arch_sections()
264 mod->arch.core.plt->sh_addralign = L1_CACHE_BYTES; in module_frob_arch_sections()
265 mod->arch.core.plt->sh_size = round_up(core_plts * PLT_ENT_SIZE, in module_frob_arch_sections()
267 mod->arch.core.plt_count = 0; in module_frob_arch_sections()
268 mod->arch.core.plt_ent = NULL; in module_frob_arch_sections()
270 mod->arch.init.plt->sh_type = SHT_NOBITS; in module_frob_arch_sections()
271 mod->arch.init.plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC; in module_frob_arch_sections()
272 mod->arch.init.plt->sh_addralign = L1_CACHE_BYTES; in module_frob_arch_sections()
273 mod->arch.init.plt->sh_size = round_up(init_plts * PLT_ENT_SIZE, in module_frob_arch_sections()
275 mod->arch.init.plt_count = 0; in module_frob_arch_sections()
276 mod->arch.init.plt_ent = NULL; in module_frob_arch_sections()
279 mod->arch.core.plt->sh_size, mod->arch.init.plt->sh_size); in module_frob_arch_sections()
285 struct module *mod; in in_module_plt()
290 ret = mod && (loc - (u32)mod->arch.core.plt_ent < mod->arch.core.plt_count * PLT_ENT_SIZE || in in_module_plt()
291 loc - (u32)mod->arch.init.plt_ent < mod->arch.init.plt_count * PLT_ENT_SIZE); in in_module_plt()