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.
8 #include <linux/moduleloader.h>
10 #include <linux/vmalloc.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>
18 static LIST_HEAD(module_bug_list
);
20 static const Elf_Shdr
*find_section(const Elf_Ehdr
*hdr
,
21 const Elf_Shdr
*sechdrs
,
27 secstrings
= (char *)hdr
+ sechdrs
[hdr
->e_shstrndx
].sh_offset
;
28 for (i
= 1; i
< hdr
->e_shnum
; i
++)
29 if (strcmp(secstrings
+sechdrs
[i
].sh_name
, name
) == 0)
34 int module_finalize(const Elf_Ehdr
*hdr
,
35 const Elf_Shdr
*sechdrs
, struct module
*me
)
40 rc
= module_finalize_ftrace(me
, sechdrs
);
44 /* Apply feature fixups */
45 sect
= find_section(hdr
, sechdrs
, "__ftr_fixup");
47 do_feature_fixups(cur_cpu_spec
->cpu_features
,
48 (void *)sect
->sh_addr
,
49 (void *)sect
->sh_addr
+ sect
->sh_size
);
51 sect
= find_section(hdr
, sechdrs
, "__mmu_ftr_fixup");
53 do_feature_fixups(cur_cpu_spec
->mmu_features
,
54 (void *)sect
->sh_addr
,
55 (void *)sect
->sh_addr
+ sect
->sh_size
);
58 sect
= find_section(hdr
, sechdrs
, "__fw_ftr_fixup");
60 do_feature_fixups(powerpc_firmware_features
,
61 (void *)sect
->sh_addr
,
62 (void *)sect
->sh_addr
+ sect
->sh_size
);
63 #endif /* CONFIG_PPC64 */
65 #ifdef PPC64_ELF_ABI_v1
66 sect
= find_section(hdr
, sechdrs
, ".opd");
68 me
->arch
.start_opd
= sect
->sh_addr
;
69 me
->arch
.end_opd
= sect
->sh_addr
+ sect
->sh_size
;
71 #endif /* PPC64_ELF_ABI_v1 */
73 #ifdef CONFIG_PPC_BARRIER_NOSPEC
74 sect
= find_section(hdr
, sechdrs
, "__spec_barrier_fixup");
76 do_barrier_nospec_fixups_range(barrier_nospec_enabled
,
77 (void *)sect
->sh_addr
,
78 (void *)sect
->sh_addr
+ sect
->sh_size
);
79 #endif /* CONFIG_PPC_BARRIER_NOSPEC */
81 sect
= find_section(hdr
, sechdrs
, "__lwsync_fixup");
83 do_lwsync_fixups(cur_cpu_spec
->cpu_features
,
84 (void *)sect
->sh_addr
,
85 (void *)sect
->sh_addr
+ sect
->sh_size
);