2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file COPYING in the main directory of this archive
7 #include <linux/moduleloader.h>
9 #include <linux/vmalloc.h>
11 #include <linux/string.h>
12 #include <linux/kernel.h>
17 #define DEBUGP(fmt...)
22 void *module_alloc(unsigned long size)
30 /* Free memory returned from module_alloc */
31 void module_free(struct module *mod, void *module_region)
34 /* FIXME: If module_region == mod->init_region, trim exception
38 /* We don't need anything special. */
39 int module_frob_arch_sections(Elf_Ehdr *hdr,
47 int apply_relocate(Elf32_Shdr *sechdrs,
49 unsigned int symindex,
54 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
58 DEBUGP("Applying relocate section %u to %u\n", relsec,
59 sechdrs[relsec].sh_info);
60 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
61 /* This is where to make the change */
62 location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
64 /* This is the symbol it is referring to. Note that all
65 undefined symbols have been resolved. */
66 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
67 + ELF32_R_SYM(rel[i].r_info);
69 switch (ELF32_R_TYPE(rel[i].r_info)) {
71 /* We add the value into the location given */
72 *location += sym->st_value;
75 /* Add the value, subtract its postition */
76 *location += sym->st_value - (uint32_t)location;
79 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
80 me->name, ELF32_R_TYPE(rel[i].r_info));
87 int apply_relocate_add(Elf32_Shdr *sechdrs,
89 unsigned int symindex,
94 Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
98 DEBUGP("Applying relocate_add section %u to %u\n", relsec,
99 sechdrs[relsec].sh_info);
100 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
101 /* This is where to make the change */
102 location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
104 /* This is the symbol it is referring to. Note that all
105 undefined symbols have been resolved. */
106 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
107 + ELF32_R_SYM(rel[i].r_info);
109 switch (ELF32_R_TYPE(rel[i].r_info)) {
111 /* We add the value into the location given */
112 *location = rel[i].r_addend + sym->st_value;
115 /* Add the value, subtract its postition */
116 *location = rel[i].r_addend + sym->st_value - (uint32_t)location;
119 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
120 me->name, ELF32_R_TYPE(rel[i].r_info));
127 int module_finalize(const Elf_Ehdr *hdr,
128 const Elf_Shdr *sechdrs,
131 module_fixup(mod, mod->arch.fixup_start, mod->arch.fixup_end);
136 void module_arch_cleanup(struct module *mod)
140 #endif /* CONFIG_MODULES */
142 void module_fixup(struct module *mod, struct m68k_fixup_info *start,
143 struct m68k_fixup_info *end)
145 struct m68k_fixup_info *fixup;
147 for (fixup = start; fixup < end; fixup++) {
148 switch (fixup->type) {
149 case m68k_fixup_memoffset:
150 *(u32 *)fixup->addr = m68k_memoffset;
152 case m68k_fixup_vnode_shift:
153 *(u16 *)fixup->addr += m68k_virt_to_node_shift;