ARM: improve module relocation fixup diagnostics
authorRussell King <rmk+kernel@arm.linux.org.uk>
Tue, 11 Jan 2011 19:57:14 +0000 (19:57 +0000)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Wed, 23 Feb 2011 17:24:14 +0000 (17:24 +0000)
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: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/kernel/module.c

index 2cfe8161b47838ee407bac9a433e1d9117cfd707..980fe20a376e33308ad1385ae4e8037c345eca36 100644 (file)
@@ -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++) {
                unsigned long loc;
                Elf32_Sym *sym;
+               const char *symname;
                s32 offset;
 #ifdef CONFIG_THUMB2_KERNEL
                u32 upper, lower, sign, j1, j2;
@@ -82,18 +83,18 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
 
                offset = ELF32_R_SYM(rel->r_info);
                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);
                        return -ENOEXEC;
                }
 
                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)) {
-                       printk(KERN_ERR "%s: out of bounds relocation, "
-                               "section %d reloc %d offset %d size %d\n",
-                               module->name, relindex, i, rel->r_offset,
-                               dstsec->sh_size);
+                       pr_err("%s: section %u reloc %u sym '%s': out of bounds relocation, offset %d size %u\n",
+                              module->name, relindex, i, symname,
+                              rel->r_offset, dstsec->sh_size);
                        return -ENOEXEC;
                }
 
@@ -119,10 +120,10 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
                        if (offset & 3 ||
                            offset <= (s32)0xfe000000 ||
                            offset >= (s32)0x02000000) {
-                               printk(KERN_ERR
-                                      "%s: relocation out of range, section "
-                                      "%d reloc %d sym '%s'\n", module->name,
-                                      relindex, i, strtab + sym->st_name);
+                               pr_err("%s: section %u reloc %u sym '%s': relocation %u out of range (%#lx -> %#x)\n",
+                                      module->name, relindex, i, symname,
+                                      ELF32_R_TYPE(rel->r_info), loc,
+                                      sym->st_value);
                                return -ENOEXEC;
                        }
 
@@ -195,10 +196,10 @@ apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
                        if (!(offset & 1) ||
                            offset <= (s32)0xff000000 ||
                            offset >= (s32)0x01000000) {
-                               printk(KERN_ERR
-                                      "%s: relocation out of range, section "
-                                      "%d reloc %d sym '%s'\n", module->name,
-                                      relindex, i, strtab + sym->st_name);
+                               pr_err("%s: section %u reloc %u sym '%s': relocation %u out of range (%#lx -> %#x)\n",
+                                      module->name, relindex, i, symname,
+                                      ELF32_R_TYPE(rel->r_info), loc,
+                                      sym->st_value);
                                return -ENOEXEC;
                        }