Improve the output of kldload(8) to show which module can't be loaded.
Was: kldload: Unsupported file type Is now: kldload: /boot/modules/test.ko: Unsupported file type PR: kern/121276 Submitted by: Edwin Groothuis <edwin@mavetju.org> Approved by: bde (mentor) MFC after: 1 week
This commit is contained in:
parent
8136b7265f
commit
552f9f63c1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=180374
@ -232,9 +232,12 @@ Elf_Addr link_elf_get_gp(linker_file_t);
|
||||
extern struct _dynamic _DYNAMIC;
|
||||
|
||||
static void
|
||||
link_elf_error(const char *s)
|
||||
link_elf_error(const char *filename, const char *s)
|
||||
{
|
||||
printf("kldload: %s\n", s);
|
||||
if (filename == NULL)
|
||||
printf("kldload: %s\n", s);
|
||||
else
|
||||
printf("kldload: %s: %s\n", filename, s);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -624,23 +627,23 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
|
||||
if (hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS
|
||||
|| hdr->e_ident[EI_DATA] != ELF_TARG_DATA) {
|
||||
link_elf_error("Unsupported file layout");
|
||||
link_elf_error(filename, "Unsupported file layout");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
}
|
||||
if (hdr->e_ident[EI_VERSION] != EV_CURRENT
|
||||
|| hdr->e_version != EV_CURRENT) {
|
||||
link_elf_error("Unsupported file version");
|
||||
link_elf_error(filename, "Unsupported file version");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
}
|
||||
if (hdr->e_type != ET_EXEC && hdr->e_type != ET_DYN) {
|
||||
link_elf_error("Unsupported file type");
|
||||
link_elf_error(filename, "Unsupported file type");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
}
|
||||
if (hdr->e_machine != ELF_TARG_MACH) {
|
||||
link_elf_error("Unsupported machine");
|
||||
link_elf_error(filename, "Unsupported machine");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
}
|
||||
@ -653,7 +656,7 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
if (!((hdr->e_phentsize == sizeof(Elf_Phdr)) &&
|
||||
(hdr->e_phoff + hdr->e_phnum*sizeof(Elf_Phdr) <= PAGE_SIZE) &&
|
||||
(hdr->e_phoff + hdr->e_phnum*sizeof(Elf_Phdr) <= nbytes)))
|
||||
link_elf_error("Unreadable program headers");
|
||||
link_elf_error(filename, "Unreadable program headers");
|
||||
|
||||
/*
|
||||
* Scan the program header entries, and save key information.
|
||||
@ -671,7 +674,7 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
|
||||
case PT_LOAD:
|
||||
if (nsegs == MAXSEGS) {
|
||||
link_elf_error("Too many sections");
|
||||
link_elf_error(filename, "Too many sections");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
}
|
||||
@ -691,7 +694,7 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
break;
|
||||
|
||||
case PT_INTERP:
|
||||
link_elf_error("Unsupported file type");
|
||||
link_elf_error(filename, "Unsupported file type");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
}
|
||||
@ -699,12 +702,12 @@ link_elf_load_file(linker_class_t cls, const char* filename,
|
||||
++phdr;
|
||||
}
|
||||
if (phdyn == NULL) {
|
||||
link_elf_error("Object is not dynamically-linked");
|
||||
link_elf_error(filename, "Object is not dynamically-linked");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
}
|
||||
if (nsegs == 0) {
|
||||
link_elf_error("No sections");
|
||||
link_elf_error(filename, "No sections");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
}
|
||||
|
@ -170,9 +170,12 @@ static struct linker_class link_elf_class = {
|
||||
static int relocate_file(elf_file_t ef);
|
||||
|
||||
static void
|
||||
link_elf_error(const char *s)
|
||||
link_elf_error(const char *filename, const char *s)
|
||||
{
|
||||
printf("kldload: %s\n", s);
|
||||
if (filename == NULL)
|
||||
printf("kldload: %s\n", s);
|
||||
else
|
||||
printf("kldload: %s: %s\n", filename, s);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -460,23 +463,23 @@ link_elf_load_file(linker_class_t cls, const char *filename,
|
||||
|
||||
if (hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS
|
||||
|| hdr->e_ident[EI_DATA] != ELF_TARG_DATA) {
|
||||
link_elf_error("Unsupported file layout");
|
||||
link_elf_error(filename, "Unsupported file layout");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
}
|
||||
if (hdr->e_ident[EI_VERSION] != EV_CURRENT
|
||||
|| hdr->e_version != EV_CURRENT) {
|
||||
link_elf_error("Unsupported file version");
|
||||
link_elf_error(filename, "Unsupported file version");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
}
|
||||
if (hdr->e_type != ET_REL) {
|
||||
link_elf_error("Unsupported file type");
|
||||
link_elf_error(filename, "Unsupported file type");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
}
|
||||
if (hdr->e_machine != ELF_TARG_MACH) {
|
||||
link_elf_error("Unsupported machine");
|
||||
link_elf_error(filename, "Unsupported machine");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
}
|
||||
@ -540,19 +543,19 @@ link_elf_load_file(linker_class_t cls, const char *filename,
|
||||
}
|
||||
}
|
||||
if (ef->nprogtab == 0) {
|
||||
link_elf_error("file has no contents");
|
||||
link_elf_error(filename, "file has no contents");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
}
|
||||
if (nsym != 1) {
|
||||
/* Only allow one symbol table for now */
|
||||
link_elf_error("file has no valid symbol table");
|
||||
link_elf_error(filename, "file has no valid symbol table");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
}
|
||||
if (symstrindex < 0 || symstrindex > hdr->e_shnum ||
|
||||
shdr[symstrindex].sh_type != SHT_STRTAB) {
|
||||
link_elf_error("file has invalid symbol strings");
|
||||
link_elf_error(filename, "file has invalid symbol strings");
|
||||
error = ENOEXEC;
|
||||
goto out;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user