Author: mhorne
Date: Wed Oct  7 18:48:10 2020
New Revision: 366519
URL: https://svnweb.freebsd.org/changeset/base/366519

Log:
  Print symbol index for unsupported relocation types
  
  It is unlikely, but possible, that an unrecognized or unsupported
  relocation type is encountered while trying to load a kernel module. If
  this occurs we should offer the symbol index as a hint to the user.
  
  While here, fix some small style issues.
  
  Reviewed by:  markj, kib (amd64 part, in D26701)
  Sponsored by: NetApp, Inc.
  Sponsored by: Klara, Inc.

Modified:
  head/sys/amd64/amd64/elf_machdep.c
  head/sys/arm/arm/elf_machdep.c
  head/sys/arm64/arm64/elf_machdep.c
  head/sys/i386/i386/elf_machdep.c
  head/sys/mips/mips/elf_machdep.c
  head/sys/powerpc/powerpc/elf32_machdep.c
  head/sys/powerpc/powerpc/elf64_machdep.c
  head/sys/riscv/riscv/elf_machdep.c

Modified: head/sys/amd64/amd64/elf_machdep.c
==============================================================================
--- head/sys/amd64/amd64/elf_machdep.c  Wed Oct  7 17:46:49 2020        
(r366518)
+++ head/sys/amd64/amd64/elf_machdep.c  Wed Oct  7 18:48:10 2020        
(r366519)
@@ -309,11 +309,11 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                case R_X86_64_NONE:     /* none */
                        break;
 
-               case R_X86_64_64:               /* S + A */
+               case R_X86_64_64:       /* S + A */
                        error = lookup(lf, symidx, 1, &addr);
                        val = addr + addend;
                        if (error != 0)
-                               return -1;
+                               return (-1);
                        if (*where != val)
                                *where = val;
                        break;
@@ -325,7 +325,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                        where32 = (Elf32_Addr *)where;
                        val32 = (Elf32_Addr)(addr + addend - (Elf_Addr)where);
                        if (error != 0)
-                               return -1;
+                               return (-1);
                        if (*where32 != val32)
                                *where32 = val32;
                        break;
@@ -335,7 +335,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                        val32 = (Elf32_Addr)(addr + addend);
                        where32 = (Elf32_Addr *)where;
                        if (error != 0)
-                               return -1;
+                               return (-1);
                        if (*where32 != val32)
                                *where32 = val32;
                        break;
@@ -345,14 +345,15 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                         * There shouldn't be copy relocations in kernel
                         * objects.
                         */
-                       printf("kldload: unexpected R_COPY relocation\n");
+                       printf("kldload: unexpected R_COPY relocation, "
+                           "symbol index %ld\n", symidx);
                        return (-1);
 
                case R_X86_64_GLOB_DAT: /* S */
                case R_X86_64_JMP_SLOT: /* XXX need addend + offset */
                        error = lookup(lf, symidx, 1, &addr);
                        if (error != 0)
-                               return -1;
+                               return (-1);
                        if (*where != addr)
                                *where = addr;
                        break;
@@ -372,8 +373,8 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                        break;
 
                default:
-                       printf("kldload: unexpected relocation type %ld\n",
-                              rtype);
+                       printf("kldload: unexpected relocation type %ld, "
+                           "symbol index %ld\n", rtype, symidx);
                        return (-1);
        }
        return (0);

Modified: head/sys/arm/arm/elf_machdep.c
==============================================================================
--- head/sys/arm/arm/elf_machdep.c      Wed Oct  7 17:46:49 2020        
(r366518)
+++ head/sys/arm/arm/elf_machdep.c      Wed Oct  7 18:48:10 2020        
(r366519)
@@ -236,7 +236,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                case R_ARM_ABS32:
                        error = lookup(lf, symidx, 1, &addr);
                        if (error != 0)
-                               return -1;
+                               return (-1);
                        store_ptr(where, addr + load_ptr(where));
                        break;
 
@@ -245,8 +245,9 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                         * There shouldn't be copy relocations in kernel
                         * objects.
                         */
-                       printf("kldload: unexpected R_COPY relocation\n");
-                       return -1;
+                       printf("kldload: unexpected R_COPY relocation, "
+                           "symbol index %d\n", symidx);
+                       return (-1);
                        break;
 
                case R_ARM_JUMP_SLOT:
@@ -260,9 +261,9 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                        break;
 
                default:
-                       printf("kldload: unexpected relocation type %d\n",
-                              rtype);
-                       return -1;
+                       printf("kldload: unexpected relocation type %d, "
+                           "symbol index %d\n", rtype, symidx);
+                       return (-1);
        }
        return(0);
 }

Modified: head/sys/arm64/arm64/elf_machdep.c
==============================================================================
--- head/sys/arm64/arm64/elf_machdep.c  Wed Oct  7 17:46:49 2020        
(r366518)
+++ head/sys/arm64/arm64/elf_machdep.c  Wed Oct  7 18:48:10 2020        
(r366519)
@@ -227,7 +227,8 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                        *where = val;
                break;
        default:
-               printf("kldload: unexpected relocation type %d\n", rtype);
+               printf("kldload: unexpected relocation type %d, "
+                   "symbol index %d\n", rtype, symidx);
                return (-1);
        }
        return (error);

Modified: head/sys/i386/i386/elf_machdep.c
==============================================================================
--- head/sys/i386/i386/elf_machdep.c    Wed Oct  7 17:46:49 2020        
(r366518)
+++ head/sys/i386/i386/elf_machdep.c    Wed Oct  7 18:48:10 2020        
(r366519)
@@ -213,7 +213,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                case R_386_32:          /* S + A */
                        error = lookup(lf, symidx, 1, &addr);
                        if (error != 0)
-                               return -1;
+                               return (-1);
                        addr += addend;
                        if (*where != addr)
                                *where = addr;
@@ -222,7 +222,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                case R_386_PC32:        /* S + A - P */
                        error = lookup(lf, symidx, 1, &addr);
                        if (error != 0)
-                               return -1;
+                               return (-1);
                        addr += addend - (Elf_Addr)where;
                        if (*where != addr)
                                *where = addr;
@@ -233,14 +233,15 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                         * There shouldn't be copy relocations in kernel
                         * objects.
                         */
-                       printf("kldload: unexpected R_COPY relocation\n");
-                       return -1;
+                       printf("kldload: unexpected R_COPY relocation, "
+                           "symbol index %d\n", symidx);
+                       return (-1);
                        break;
 
                case R_386_GLOB_DAT:    /* S */
                        error = lookup(lf, symidx, 1, &addr);
                        if (error != 0)
-                               return -1;
+                               return (-1);
                        if (*where != addr)
                                *where = addr;
                        break;
@@ -255,9 +256,9 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                                *where = addr;
                        break;
                default:
-                       printf("kldload: unexpected relocation type %d\n",
-                              rtype);
-                       return -1;
+                       printf("kldload: unexpected relocation type %d, "
+                           "symbol index %d\n", rtype, symidx);
+                       return (-1);
        }
        return(0);
 }

Modified: head/sys/mips/mips/elf_machdep.c
==============================================================================
--- head/sys/mips/mips/elf_machdep.c    Wed Oct  7 17:46:49 2020        
(r366518)
+++ head/sys/mips/mips/elf_machdep.c    Wed Oct  7 18:48:10 2020        
(r366519)
@@ -454,12 +454,12 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                break;
 
        default:
-               printf("kldload: unexpected relocation type %d\n",
-                       rtype);
+               printf("kldload: unexpected relocation type %d, "
+                   "symbol index %d\n", rtype, symidx);
                return (-1);
        }
 
-       return(0);
+       return (0);
 }
 
 int

Modified: head/sys/powerpc/powerpc/elf32_machdep.c
==============================================================================
--- head/sys/powerpc/powerpc/elf32_machdep.c    Wed Oct  7 17:46:49 2020        
(r366518)
+++ head/sys/powerpc/powerpc/elf32_machdep.c    Wed Oct  7 18:48:10 2020        
(r366519)
@@ -262,14 +262,14 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
        case R_PPC_ADDR32: /* word32 S + A */
                error = lookup(lf, symidx, 1, &addr);
                if (error != 0)
-                       return -1;
+                       return (-1);
                *where = elf_relocaddr(lf, addr + addend);
                        break;
 
        case R_PPC_ADDR16_LO: /* #lo(S) */
                error = lookup(lf, symidx, 1, &addr);
                if (error != 0)
-                       return -1;
+                       return (-1);
                /*
                 * addend values are sometimes relative to sections
                 * (i.e. .rodata) in rela, where in reality they
@@ -284,7 +284,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
        case R_PPC_ADDR16_HA: /* #ha(S) */
                error = lookup(lf, symidx, 1, &addr);
                if (error != 0)
-                       return -1;
+                       return (-1);
                /*
                 * addend values are sometimes relative to sections
                 * (i.e. .rodata) in rela, where in reality they
@@ -311,7 +311,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                 */
                error = lookup(lf, symidx, 1, &addr);
                if (error != 0)
-                       return -1;
+                       return (-1);
                *where = elf_relocaddr(lf, addr + addend);
                break;
 
@@ -323,11 +323,11 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                break;
 
        default:
-               printf("kldload: unexpected relocation type %d\n",
-                   (int) rtype);
-               return -1;
+               printf("kldload: unexpected relocation type %d, "
+                   "symbol index %d\n", (int)rtype, symidx);
+               return (-1);
        }
-       return(0);
+       return (0);
 }
 
 void

Modified: head/sys/powerpc/powerpc/elf64_machdep.c
==============================================================================
--- head/sys/powerpc/powerpc/elf64_machdep.c    Wed Oct  7 17:46:49 2020        
(r366518)
+++ head/sys/powerpc/powerpc/elf64_machdep.c    Wed Oct  7 18:48:10 2020        
(r366519)
@@ -342,7 +342,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
        case R_PPC64_ADDR64:    /* doubleword64 S + A */
                error = lookup(lf, symidx, 1, &addr);
                if (error != 0)
-                       return -1;
+                       return (-1);
                addr += addend;
                *where = addr;
                break;
@@ -369,11 +369,11 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                break;
 
        default:
-               printf("kldload: unexpected relocation type %d\n",
-                   (int) rtype);
-               return -1;
+               printf("kldload: unexpected relocation type %d, "
+                   "symbol index %d\n", (int)rtype, symidx);
+               return (-1);
        }
-       return(0);
+       return (0);
 }
 
 void

Modified: head/sys/riscv/riscv/elf_machdep.c
==============================================================================
--- head/sys/riscv/riscv/elf_machdep.c  Wed Oct  7 17:46:49 2020        
(r366518)
+++ head/sys/riscv/riscv/elf_machdep.c  Wed Oct  7 18:48:10 2020        
(r366519)
@@ -479,7 +479,8 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbas
                break;
 
        default:
-               printf("kldload: unexpected relocation type %ld\n", rtype);
+               printf("kldload: unexpected relocation type %ld, "
+                   "symbol index %ld\n", rtype, symidx);
                return (-1);
        }
 
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to