1 #include <linux/moduleloader.h>
3 #include <linux/vmalloc.h>
5 #include <linux/string.h>
6 #include <linux/kernel.h>
11 #define DEBUGP(fmt...)
14 void *module_alloc(unsigned long size
)
22 /* Free memory returned from module_alloc */
23 void module_free(struct module
*mod
, void *module_region
)
28 /* We don't need anything special. */
29 int module_frob_arch_sections(Elf_Ehdr
*hdr
,
37 int apply_relocate(Elf32_Shdr
*sechdrs
,
39 unsigned int symindex
,
44 Elf32_Rel
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
48 DEBUGP("Applying relocate section %u to %u\n", relsec
,
49 sechdrs
[relsec
].sh_info
);
50 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
51 /* This is where to make the change */
52 location
= (void *)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
54 /* This is the symbol it is referring to. Note that all
55 undefined symbols have been resolved. */
56 sym
= (Elf32_Sym
*)sechdrs
[symindex
].sh_addr
57 + ELF32_R_SYM(rel
[i
].r_info
);
59 switch (ELF32_R_TYPE(rel
[i
].r_info
)) {
61 /* We add the value into the location given */
62 *location
+= sym
->st_value
;
65 /* Add the value, subtract its postition */
66 *location
+= sym
->st_value
- (uint32_t)location
;
69 printk(KERN_ERR
"module %s: Unknown relocation: %u\n",
70 me
->name
, ELF32_R_TYPE(rel
[i
].r_info
));
77 int apply_relocate_add(Elf32_Shdr
*sechdrs
,
79 unsigned int symindex
,
84 Elf32_Rela
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
88 DEBUGP("Applying relocate_add section %u to %u\n", relsec
,
89 sechdrs
[relsec
].sh_info
);
90 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
91 /* This is where to make the change */
92 location
= (void *)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
94 /* This is the symbol it is referring to. Note that all
95 undefined symbols have been resolved. */
96 sym
= (Elf32_Sym
*)sechdrs
[symindex
].sh_addr
97 + ELF32_R_SYM(rel
[i
].r_info
);
99 switch (ELF32_R_TYPE(rel
[i
].r_info
)) {
101 /* We add the value into the location given */
102 *location
= rel
[i
].r_addend
+ sym
->st_value
;
105 /* Add the value, subtract its postition */
106 *location
= rel
[i
].r_addend
+ sym
->st_value
- (uint32_t)location
;
109 printk(KERN_ERR
"module %s: Unknown relocation: %u\n",
110 me
->name
, ELF32_R_TYPE(rel
[i
].r_info
));
117 int module_finalize(const Elf_Ehdr
*hdr
,
118 const Elf_Shdr
*sechdrs
,
124 void module_arch_cleanup(struct module
*mod
)