1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* Kernel module help for powerpc. 3 Copyright (C) 2001, 2003 Rusty Russell IBM Corporation. 4 Copyright (C) 2008 Freescale Semiconductor, Inc. 5 6 */ 7 #include <linux/elf.h> 8 #include <linux/moduleloader.h> 9 #include <linux/err.h> 10 #include <linux/mm.h> 11 #include <linux/bug.h> 12 #include <asm/module.h> 13 #include <linux/uaccess.h> 14 #include <asm/firmware.h> 15 #include <linux/sort.h> 16 #include <asm/setup.h> 17 #include <asm/sections.h> 18 19 static LIST_HEAD(module_bug_list); 20 21 static const Elf_Shdr *find_section(const Elf_Ehdr *hdr, 22 const Elf_Shdr *sechdrs, 23 const char *name) 24 { 25 char *secstrings; 26 unsigned int i; 27 28 secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset; 29 for (i = 1; i < hdr->e_shnum; i++) 30 if (strcmp(secstrings+sechdrs[i].sh_name, name) == 0) 31 return &sechdrs[i]; 32 return NULL; 33 } 34 35 int module_finalize(const Elf_Ehdr *hdr, 36 const Elf_Shdr *sechdrs, struct module *me) 37 { 38 const Elf_Shdr *sect; 39 int rc; 40 41 rc = module_finalize_ftrace(me, sechdrs); 42 if (rc) 43 return rc; 44 45 /* Apply feature fixups */ 46 sect = find_section(hdr, sechdrs, "__ftr_fixup"); 47 if (sect != NULL) 48 do_feature_fixups(cur_cpu_spec->cpu_features, 49 (void *)sect->sh_addr, 50 (void *)sect->sh_addr + sect->sh_size); 51 52 sect = find_section(hdr, sechdrs, "__mmu_ftr_fixup"); 53 if (sect != NULL) 54 do_feature_fixups(cur_cpu_spec->mmu_features, 55 (void *)sect->sh_addr, 56 (void *)sect->sh_addr + sect->sh_size); 57 58 #ifdef CONFIG_PPC64 59 sect = find_section(hdr, sechdrs, "__fw_ftr_fixup"); 60 if (sect != NULL) 61 do_feature_fixups(powerpc_firmware_features, 62 (void *)sect->sh_addr, 63 (void *)sect->sh_addr + sect->sh_size); 64 #endif /* CONFIG_PPC64 */ 65 66 #ifdef CONFIG_PPC64_ELF_ABI_V1 67 sect = find_section(hdr, sechdrs, ".opd"); 68 if (sect != NULL) { 69 me->arch.start_opd = sect->sh_addr; 70 me->arch.end_opd = sect->sh_addr + sect->sh_size; 71 } 72 #endif /* CONFIG_PPC64_ELF_ABI_V1 */ 73 74 #ifdef CONFIG_PPC_BARRIER_NOSPEC 75 sect = find_section(hdr, sechdrs, "__spec_barrier_fixup"); 76 if (sect != NULL) 77 do_barrier_nospec_fixups_range(barrier_nospec_enabled, 78 (void *)sect->sh_addr, 79 (void *)sect->sh_addr + sect->sh_size); 80 #endif /* CONFIG_PPC_BARRIER_NOSPEC */ 81 82 sect = find_section(hdr, sechdrs, "__lwsync_fixup"); 83 if (sect != NULL) 84 do_lwsync_fixups(cur_cpu_spec->cpu_features, 85 (void *)sect->sh_addr, 86 (void *)sect->sh_addr + sect->sh_size); 87 88 return 0; 89 } 90