Commit 68e6fad4 authored by Russell King's avatar Russell King

ARM: improve module relocation fixup diagnostics

Current diagnostics are rather poor when things go wrong:
  ipv6: relocation out of range, section 2 reloc 0 sym 'snmp_mib_free'

Let's include a little more information about the problem:
  ipv6: section 2 reloc 0 sym 'snmp_mib_free': relocation 28 out of range (0xbf0000a4 -> 0xc11b4858)

so that we show exactly what the problem is - not only what type of
relocation but also the offending address range too.
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent a65d2922
...@@ -75,6 +75,7 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, ...@@ -75,6 +75,7 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
for (i = 0; i < relsec->sh_size / sizeof(Elf32_Rel); i++, rel++) { for (i = 0; i < relsec->sh_size / sizeof(Elf32_Rel); i++, rel++) {
unsigned long loc; unsigned long loc;
Elf32_Sym *sym; Elf32_Sym *sym;
const char *symname;
s32 offset; s32 offset;
#ifdef CONFIG_THUMB2_KERNEL #ifdef CONFIG_THUMB2_KERNEL
u32 upper, lower, sign, j1, j2; u32 upper, lower, sign, j1, j2;
...@@ -82,18 +83,18 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, ...@@ -82,18 +83,18 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
offset = ELF32_R_SYM(rel->r_info); offset = ELF32_R_SYM(rel->r_info);
if (offset < 0 || offset > (symsec->sh_size / sizeof(Elf32_Sym))) { if (offset < 0 || offset > (symsec->sh_size / sizeof(Elf32_Sym))) {
printk(KERN_ERR "%s: bad relocation, section %d reloc %d\n", pr_err("%s: section %u reloc %u: bad relocation sym offset\n",
module->name, relindex, i); module->name, relindex, i);
return -ENOEXEC; return -ENOEXEC;
} }
sym = ((Elf32_Sym *)symsec->sh_addr) + offset; sym = ((Elf32_Sym *)symsec->sh_addr) + offset;
symname = strtab + sym->st_name;
if (rel->r_offset < 0 || rel->r_offset > dstsec->sh_size - sizeof(u32)) { if (rel->r_offset < 0 || rel->r_offset > dstsec->sh_size - sizeof(u32)) {
printk(KERN_ERR "%s: out of bounds relocation, " pr_err("%s: section %u reloc %u sym '%s': out of bounds relocation, offset %d size %u\n",
"section %d reloc %d offset %d size %d\n", module->name, relindex, i, symname,
module->name, relindex, i, rel->r_offset, rel->r_offset, dstsec->sh_size);
dstsec->sh_size);
return -ENOEXEC; return -ENOEXEC;
} }
...@@ -119,10 +120,10 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, ...@@ -119,10 +120,10 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
if (offset & 3 || if (offset & 3 ||
offset <= (s32)0xfe000000 || offset <= (s32)0xfe000000 ||
offset >= (s32)0x02000000) { offset >= (s32)0x02000000) {
printk(KERN_ERR pr_err("%s: section %u reloc %u sym '%s': relocation %u out of range (%#lx -> %#x)\n",
"%s: relocation out of range, section " module->name, relindex, i, symname,
"%d reloc %d sym '%s'\n", module->name, ELF32_R_TYPE(rel->r_info), loc,
relindex, i, strtab + sym->st_name); sym->st_value);
return -ENOEXEC; return -ENOEXEC;
} }
...@@ -195,10 +196,10 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex, ...@@ -195,10 +196,10 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
if (!(offset & 1) || if (!(offset & 1) ||
offset <= (s32)0xff000000 || offset <= (s32)0xff000000 ||
offset >= (s32)0x01000000) { offset >= (s32)0x01000000) {
printk(KERN_ERR pr_err("%s: section %u reloc %u sym '%s': relocation %u out of range (%#lx -> %#x)\n",
"%s: relocation out of range, section " module->name, relindex, i, symname,
"%d reloc %d sym '%s'\n", module->name, ELF32_R_TYPE(rel->r_info), loc,
relindex, i, strtab + sym->st_name); sym->st_value);
return -ENOEXEC; return -ENOEXEC;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment