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.
This commit is contained in:
parent
194ddc011a
commit
8481aab1ac
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=366519
@ -309,11 +309,11 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
case R_X86_64_NONE: /* none */
|
case R_X86_64_NONE: /* none */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R_X86_64_64: /* S + A */
|
case R_X86_64_64: /* S + A */
|
||||||
error = lookup(lf, symidx, 1, &addr);
|
error = lookup(lf, symidx, 1, &addr);
|
||||||
val = addr + addend;
|
val = addr + addend;
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return -1;
|
return (-1);
|
||||||
if (*where != val)
|
if (*where != val)
|
||||||
*where = val;
|
*where = val;
|
||||||
break;
|
break;
|
||||||
@ -325,7 +325,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
where32 = (Elf32_Addr *)where;
|
where32 = (Elf32_Addr *)where;
|
||||||
val32 = (Elf32_Addr)(addr + addend - (Elf_Addr)where);
|
val32 = (Elf32_Addr)(addr + addend - (Elf_Addr)where);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return -1;
|
return (-1);
|
||||||
if (*where32 != val32)
|
if (*where32 != val32)
|
||||||
*where32 = val32;
|
*where32 = val32;
|
||||||
break;
|
break;
|
||||||
@ -335,7 +335,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
val32 = (Elf32_Addr)(addr + addend);
|
val32 = (Elf32_Addr)(addr + addend);
|
||||||
where32 = (Elf32_Addr *)where;
|
where32 = (Elf32_Addr *)where;
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return -1;
|
return (-1);
|
||||||
if (*where32 != val32)
|
if (*where32 != val32)
|
||||||
*where32 = val32;
|
*where32 = val32;
|
||||||
break;
|
break;
|
||||||
@ -345,14 +345,15 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
* There shouldn't be copy relocations in kernel
|
* There shouldn't be copy relocations in kernel
|
||||||
* objects.
|
* objects.
|
||||||
*/
|
*/
|
||||||
printf("kldload: unexpected R_COPY relocation\n");
|
printf("kldload: unexpected R_COPY relocation, "
|
||||||
|
"symbol index %ld\n", symidx);
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
case R_X86_64_GLOB_DAT: /* S */
|
case R_X86_64_GLOB_DAT: /* S */
|
||||||
case R_X86_64_JMP_SLOT: /* XXX need addend + offset */
|
case R_X86_64_JMP_SLOT: /* XXX need addend + offset */
|
||||||
error = lookup(lf, symidx, 1, &addr);
|
error = lookup(lf, symidx, 1, &addr);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return -1;
|
return (-1);
|
||||||
if (*where != addr)
|
if (*where != addr)
|
||||||
*where = addr;
|
*where = addr;
|
||||||
break;
|
break;
|
||||||
@ -372,8 +373,8 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("kldload: unexpected relocation type %ld\n",
|
printf("kldload: unexpected relocation type %ld, "
|
||||||
rtype);
|
"symbol index %ld\n", rtype, symidx);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -236,7 +236,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
case R_ARM_ABS32:
|
case R_ARM_ABS32:
|
||||||
error = lookup(lf, symidx, 1, &addr);
|
error = lookup(lf, symidx, 1, &addr);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return -1;
|
return (-1);
|
||||||
store_ptr(where, addr + load_ptr(where));
|
store_ptr(where, addr + load_ptr(where));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -245,8 +245,9 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
* There shouldn't be copy relocations in kernel
|
* There shouldn't be copy relocations in kernel
|
||||||
* objects.
|
* objects.
|
||||||
*/
|
*/
|
||||||
printf("kldload: unexpected R_COPY relocation\n");
|
printf("kldload: unexpected R_COPY relocation, "
|
||||||
return -1;
|
"symbol index %d\n", symidx);
|
||||||
|
return (-1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R_ARM_JUMP_SLOT:
|
case R_ARM_JUMP_SLOT:
|
||||||
@ -260,9 +261,9 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("kldload: unexpected relocation type %d\n",
|
printf("kldload: unexpected relocation type %d, "
|
||||||
rtype);
|
"symbol index %d\n", rtype, symidx);
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,8 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
*where = val;
|
*where = val;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("kldload: unexpected relocation type %d\n", rtype);
|
printf("kldload: unexpected relocation type %d, "
|
||||||
|
"symbol index %d\n", rtype, symidx);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
return (error);
|
return (error);
|
||||||
|
@ -213,7 +213,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
case R_386_32: /* S + A */
|
case R_386_32: /* S + A */
|
||||||
error = lookup(lf, symidx, 1, &addr);
|
error = lookup(lf, symidx, 1, &addr);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return -1;
|
return (-1);
|
||||||
addr += addend;
|
addr += addend;
|
||||||
if (*where != addr)
|
if (*where != addr)
|
||||||
*where = addr;
|
*where = addr;
|
||||||
@ -222,7 +222,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
case R_386_PC32: /* S + A - P */
|
case R_386_PC32: /* S + A - P */
|
||||||
error = lookup(lf, symidx, 1, &addr);
|
error = lookup(lf, symidx, 1, &addr);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return -1;
|
return (-1);
|
||||||
addr += addend - (Elf_Addr)where;
|
addr += addend - (Elf_Addr)where;
|
||||||
if (*where != addr)
|
if (*where != addr)
|
||||||
*where = addr;
|
*where = addr;
|
||||||
@ -233,14 +233,15 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
* There shouldn't be copy relocations in kernel
|
* There shouldn't be copy relocations in kernel
|
||||||
* objects.
|
* objects.
|
||||||
*/
|
*/
|
||||||
printf("kldload: unexpected R_COPY relocation\n");
|
printf("kldload: unexpected R_COPY relocation, "
|
||||||
return -1;
|
"symbol index %d\n", symidx);
|
||||||
|
return (-1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R_386_GLOB_DAT: /* S */
|
case R_386_GLOB_DAT: /* S */
|
||||||
error = lookup(lf, symidx, 1, &addr);
|
error = lookup(lf, symidx, 1, &addr);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return -1;
|
return (-1);
|
||||||
if (*where != addr)
|
if (*where != addr)
|
||||||
*where = addr;
|
*where = addr;
|
||||||
break;
|
break;
|
||||||
@ -255,9 +256,9 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
*where = addr;
|
*where = addr;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("kldload: unexpected relocation type %d\n",
|
printf("kldload: unexpected relocation type %d, "
|
||||||
rtype);
|
"symbol index %d\n", rtype, symidx);
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
@ -454,12 +454,12 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("kldload: unexpected relocation type %d\n",
|
printf("kldload: unexpected relocation type %d, "
|
||||||
rtype);
|
"symbol index %d\n", rtype, symidx);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -262,14 +262,14 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
case R_PPC_ADDR32: /* word32 S + A */
|
case R_PPC_ADDR32: /* word32 S + A */
|
||||||
error = lookup(lf, symidx, 1, &addr);
|
error = lookup(lf, symidx, 1, &addr);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return -1;
|
return (-1);
|
||||||
*where = elf_relocaddr(lf, addr + addend);
|
*where = elf_relocaddr(lf, addr + addend);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R_PPC_ADDR16_LO: /* #lo(S) */
|
case R_PPC_ADDR16_LO: /* #lo(S) */
|
||||||
error = lookup(lf, symidx, 1, &addr);
|
error = lookup(lf, symidx, 1, &addr);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return -1;
|
return (-1);
|
||||||
/*
|
/*
|
||||||
* addend values are sometimes relative to sections
|
* addend values are sometimes relative to sections
|
||||||
* (i.e. .rodata) in rela, where in reality they
|
* (i.e. .rodata) in rela, where in reality they
|
||||||
@ -284,7 +284,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
case R_PPC_ADDR16_HA: /* #ha(S) */
|
case R_PPC_ADDR16_HA: /* #ha(S) */
|
||||||
error = lookup(lf, symidx, 1, &addr);
|
error = lookup(lf, symidx, 1, &addr);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return -1;
|
return (-1);
|
||||||
/*
|
/*
|
||||||
* addend values are sometimes relative to sections
|
* addend values are sometimes relative to sections
|
||||||
* (i.e. .rodata) in rela, where in reality they
|
* (i.e. .rodata) in rela, where in reality they
|
||||||
@ -311,7 +311,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
*/
|
*/
|
||||||
error = lookup(lf, symidx, 1, &addr);
|
error = lookup(lf, symidx, 1, &addr);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return -1;
|
return (-1);
|
||||||
*where = elf_relocaddr(lf, addr + addend);
|
*where = elf_relocaddr(lf, addr + addend);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -323,11 +323,11 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("kldload: unexpected relocation type %d\n",
|
printf("kldload: unexpected relocation type %d, "
|
||||||
(int) rtype);
|
"symbol index %d\n", (int)rtype, symidx);
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -342,7 +342,7 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
case R_PPC64_ADDR64: /* doubleword64 S + A */
|
case R_PPC64_ADDR64: /* doubleword64 S + A */
|
||||||
error = lookup(lf, symidx, 1, &addr);
|
error = lookup(lf, symidx, 1, &addr);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
return -1;
|
return (-1);
|
||||||
addr += addend;
|
addr += addend;
|
||||||
*where = addr;
|
*where = addr;
|
||||||
break;
|
break;
|
||||||
@ -369,11 +369,11 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("kldload: unexpected relocation type %d\n",
|
printf("kldload: unexpected relocation type %d, "
|
||||||
(int) rtype);
|
"symbol index %d\n", (int)rtype, symidx);
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -479,7 +479,8 @@ elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("kldload: unexpected relocation type %ld\n", rtype);
|
printf("kldload: unexpected relocation type %ld, "
|
||||||
|
"symbol index %ld\n", rtype, symidx);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user