1 #include <linux/moduleloader.h>
3 #include <linux/vmalloc.h>
5 #include <linux/string.h>
6 #include <linux/kernel.h>
8 int apply_relocate_add(Elf32_Shdr
*sechdrs
,
10 unsigned int symindex
,
15 Elf32_Rela
*rela
= (void *)sechdrs
[relsec
].sh_addr
;
17 pr_debug("Applying relocate section %u to %u\n", relsec
,
18 sechdrs
[relsec
].sh_info
);
19 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rela
); i
++) {
20 /* This is where to make the change */
22 (uint32_t *)(sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
24 /* This is the symbol it is referring to. Note that all
25 undefined symbols have been resolved. */
26 Elf32_Sym
*sym
= (Elf32_Sym
*)sechdrs
[symindex
].sh_addr
27 + ELF32_R_SYM(rela
[i
].r_info
);
28 uint32_t v
= sym
->st_value
+ rela
[i
].r_addend
;
30 switch (ELF32_R_TYPE(rela
[i
].r_info
)) {
32 loc
= (uint32_t *)((uint32_t)loc
- 1);
33 *loc
= (*loc
& 0xff000000) | ((*loc
& 0xffffff) + v
);
36 if (ELF32_R_SYM(rela
[i
].r_info
))
44 v
-= (unsigned long)loc
+ 2;
45 if ((Elf32_Sword
)v
> 0x7fff ||
46 (Elf32_Sword
)v
< -(Elf32_Sword
)0x8000)
49 *(unsigned short *)loc
= v
;
52 v
-= (unsigned long)loc
+ 1;
53 if ((Elf32_Sword
)v
> 0x7f ||
54 (Elf32_Sword
)v
< -(Elf32_Sword
)0x80)
57 *(unsigned char *)loc
= v
;
60 pr_err("module %s: Unknown relocation: %u\n",
61 me
->name
, ELF32_R_TYPE(rela
[i
].r_info
));
67 pr_err("module %s: relocation offset overflow: %08x\n",
68 me
->name
, rela
[i
].r_offset
);