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 int apply_relocate(Elf32_Shdr *sechdrs,
16 unsigned int symindex,
21 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25 DEBUGP("Applying relocate section %u to %u\n", relsec,
26 sechdrs[relsec].sh_info);
27 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
28 /* This is where to make the change */
29 location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
31 /* This is the symbol it is referring to. Note that all
32 undefined symbols have been resolved. */
33 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
34 + ELF32_R_SYM(rel[i].r_info);
36 switch (ELF32_R_TYPE(rel[i].r_info)) {
38 /* We add the value into the location given */
39 *location += sym->st_value;
42 /* Add the value, subtract its postition */
43 *location += sym->st_value - (uint32_t)location;
46 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
47 me->name, ELF32_R_TYPE(rel[i].r_info));
54 int apply_relocate_add(Elf32_Shdr *sechdrs,
56 unsigned int symindex,
61 Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
65 DEBUGP("Applying relocate_add section %u to %u\n", relsec,
66 sechdrs[relsec].sh_info);
67 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
68 /* This is where to make the change */
69 location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
71 /* This is the symbol it is referring to. Note that all
72 undefined symbols have been resolved. */
73 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
74 + ELF32_R_SYM(rel[i].r_info);
76 switch (ELF32_R_TYPE(rel[i].r_info)) {
78 /* We add the value into the location given */
79 *location = rel[i].r_addend + sym->st_value;
82 /* Add the value, subtract its postition */
83 *location = rel[i].r_addend + sym->st_value - (uint32_t)location;
86 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
87 me->name, ELF32_R_TYPE(rel[i].r_info));