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 int apply_relocate(Elf32_Shdr
*sechdrs
,
24 unsigned int symindex
,
29 Elf32_Rel
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
33 DEBUGP("Applying relocate section %u to %u\n", relsec
,
34 sechdrs
[relsec
].sh_info
);
35 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
36 /* This is where to make the change */
37 location
= (void *)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
39 /* This is the symbol it is referring to. Note that all
40 undefined symbols have been resolved. */
41 sym
= (Elf32_Sym
*)sechdrs
[symindex
].sh_addr
42 + ELF32_R_SYM(rel
[i
].r_info
);
44 switch (ELF32_R_TYPE(rel
[i
].r_info
)) {
46 /* We add the value into the location given */
47 *location
+= sym
->st_value
;
50 /* Add the value, subtract its position */
51 *location
+= sym
->st_value
- (uint32_t)location
;
54 printk(KERN_ERR
"module %s: Unknown relocation: %u\n",
55 me
->name
, ELF32_R_TYPE(rel
[i
].r_info
));
62 int apply_relocate_add(Elf32_Shdr
*sechdrs
,
64 unsigned int symindex
,
69 Elf32_Rela
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
73 DEBUGP("Applying relocate_add section %u to %u\n", relsec
,
74 sechdrs
[relsec
].sh_info
);
75 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
76 /* This is where to make the change */
77 location
= (void *)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
79 /* This is the symbol it is referring to. Note that all
80 undefined symbols have been resolved. */
81 sym
= (Elf32_Sym
*)sechdrs
[symindex
].sh_addr
82 + ELF32_R_SYM(rel
[i
].r_info
);
84 switch (ELF32_R_TYPE(rel
[i
].r_info
)) {
86 /* We add the value into the location given */
87 *location
= rel
[i
].r_addend
+ sym
->st_value
;
90 /* Add the value, subtract its position */
91 *location
= rel
[i
].r_addend
+ sym
->st_value
- (uint32_t)location
;
94 printk(KERN_ERR
"module %s: Unknown relocation: %u\n",
95 me
->name
, ELF32_R_TYPE(rel
[i
].r_info
));
102 int module_finalize(const Elf_Ehdr
*hdr
,
103 const Elf_Shdr
*sechdrs
,
106 module_fixup(mod
, mod
->arch
.fixup_start
, mod
->arch
.fixup_end
);
110 #endif /* CONFIG_MODULES */
112 void module_fixup(struct module
*mod
, struct m68k_fixup_info
*start
,
113 struct m68k_fixup_info
*end
)
116 struct m68k_fixup_info
*fixup
;
118 for (fixup
= start
; fixup
< end
; fixup
++) {
119 switch (fixup
->type
) {
120 case m68k_fixup_memoffset
:
121 *(u32
*)fixup
->addr
= m68k_memoffset
;
123 case m68k_fixup_vnode_shift
:
124 *(u16
*)fixup
->addr
+= m68k_virt_to_node_shift
;