diff options
Diffstat (limited to 'arch/arm/kernel/module.c')
-rw-r--r-- | arch/arm/kernel/module.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c index bac03c81489d..f28c5e9c51ea 100644 --- a/arch/arm/kernel/module.c +++ b/arch/arm/kernel/module.c | |||
@@ -102,6 +102,7 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, | |||
102 | unsigned long loc; | 102 | unsigned long loc; |
103 | Elf32_Sym *sym; | 103 | Elf32_Sym *sym; |
104 | s32 offset; | 104 | s32 offset; |
105 | u32 upper, lower, sign, j1, j2; | ||
105 | 106 | ||
106 | offset = ELF32_R_SYM(rel->r_info); | 107 | offset = ELF32_R_SYM(rel->r_info); |
107 | if (offset < 0 || offset > (symsec->sh_size / sizeof(Elf32_Sym))) { | 108 | if (offset < 0 || offset > (symsec->sh_size / sizeof(Elf32_Sym))) { |
@@ -184,6 +185,58 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, | |||
184 | (offset & 0x0fff); | 185 | (offset & 0x0fff); |
185 | break; | 186 | break; |
186 | 187 | ||
188 | case R_ARM_THM_CALL: | ||
189 | case R_ARM_THM_JUMP24: | ||
190 | upper = *(u16 *)loc; | ||
191 | lower = *(u16 *)(loc + 2); | ||
192 | |||
193 | /* | ||
194 | * 25 bit signed address range (Thumb-2 BL and B.W | ||
195 | * instructions): | ||
196 | * S:I1:I2:imm10:imm11:0 | ||
197 | * where: | ||
198 | * S = upper[10] = offset[24] | ||
199 | * I1 = ~(J1 ^ S) = offset[23] | ||
200 | * I2 = ~(J2 ^ S) = offset[22] | ||
201 | * imm10 = upper[9:0] = offset[21:12] | ||
202 | * imm11 = lower[10:0] = offset[11:1] | ||
203 | * J1 = lower[13] | ||
204 | * J2 = lower[11] | ||
205 | */ | ||
206 | sign = (upper >> 10) & 1; | ||
207 | j1 = (lower >> 13) & 1; | ||
208 | j2 = (lower >> 11) & 1; | ||
209 | offset = (sign << 24) | ((~(j1 ^ sign) & 1) << 23) | | ||
210 | ((~(j2 ^ sign) & 1) << 22) | | ||
211 | ((upper & 0x03ff) << 12) | | ||
212 | ((lower & 0x07ff) << 1); | ||
213 | if (offset & 0x01000000) | ||
214 | offset -= 0x02000000; | ||
215 | offset += sym->st_value - loc; | ||
216 | |||
217 | /* only Thumb addresses allowed (no interworking) */ | ||
218 | if (!(offset & 1) || | ||
219 | offset <= (s32)0xff000000 || | ||
220 | offset >= (s32)0x01000000) { | ||
221 | printk(KERN_ERR | ||
222 | "%s: relocation out of range, section " | ||
223 | "%d reloc %d sym '%s'\n", module->name, | ||
224 | relindex, i, strtab + sym->st_name); | ||
225 | return -ENOEXEC; | ||
226 | } | ||
227 | |||
228 | sign = (offset >> 24) & 1; | ||
229 | j1 = sign ^ (~(offset >> 23) & 1); | ||
230 | j2 = sign ^ (~(offset >> 22) & 1); | ||
231 | *(u16 *)loc = (u16)((upper & 0xf800) | (sign << 10) | | ||
232 | ((offset >> 12) & 0x03ff)); | ||
233 | *(u16 *)(loc + 2) = (u16)((lower & 0xd000) | | ||
234 | (j1 << 13) | (j2 << 11) | | ||
235 | ((offset >> 1) & 0x07ff)); | ||
236 | upper = *(u16 *)loc; | ||
237 | lower = *(u16 *)(loc + 2); | ||
238 | break; | ||
239 | |||
187 | default: | 240 | default: |
188 | printk(KERN_ERR "%s: unknown relocation: %u\n", | 241 | printk(KERN_ERR "%s: unknown relocation: %u\n", |
189 | module->name, ELF32_R_TYPE(rel->r_info)); | 242 | module->name, ELF32_R_TYPE(rel->r_info)); |