Noticed this while repeating https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=274375 . Steps to repeat: ``` # kldload virtio.ko kldload: an error occurred while loading module virtio.ko. Please check dmesg(8) for more details. # dmesg | tail -n 2 interface virtio.1 already present in the KLD 'kernel'! linker_load_file: /boot/kernel/virtio.ko - unsupported file type ``` The error code should be EEXIST (the same with `kldload virtio`).
Proposed fix https://reviews.freebsd.org/D42474 .
To get the error code: ``` # truss kldload virtio.ko ... kldload("virtio.ko") ERR#8 'Exec format error' ... ```
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=ecf710f0e04e3314a492747124166ccb7cf4019e commit ecf710f0e04e3314a492747124166ccb7cf4019e Author: Zhenlei Huang <zlei@FreeBSD.org> AuthorDate: 2023-11-07 04:45:25 +0000 Commit: Zhenlei Huang <zlei@FreeBSD.org> CommitDate: 2023-11-07 04:45:25 +0000 kern linker: Do not retry loading modules on EEXIST LINKER_LOAD_FILE() calls linker_load_dependencies() which will return EEXIST in case the module to be loaded has already been compiled into the kernel. Since the format of the module is now recognized then there is no need to retry loading with a different linker, otherwise the userland will get misleading error number ENOEXEC. PR: 274936 Reviewed by: dfr MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D42474 sys/kern/kern_linker.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
This affects amd64 hardware only. Other architectures do not have 'sys/kern/link_elf_obj.c' compiled into kernel.
^Triage: FreeBSD 12 is now out of support.
A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=e7fd435d3d4e888d9894d8c212c29ae6e2768f74 commit e7fd435d3d4e888d9894d8c212c29ae6e2768f74 Author: Zhenlei Huang <zlei@FreeBSD.org> AuthorDate: 2023-11-07 04:45:25 +0000 Commit: Zhenlei Huang <zlei@FreeBSD.org> CommitDate: 2024-01-15 10:28:25 +0000 kern linker: Do not retry loading modules on EEXIST LINKER_LOAD_FILE() calls linker_load_dependencies() which will return EEXIST in case the module to be loaded has already been compiled into the kernel. Since the format of the module is now recognized then there is no need to retry loading with a different linker, otherwise the userland will get misleading error number ENOEXEC. PR: 274936 Reviewed by: dfr MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D42474 (cherry picked from commit ecf710f0e04e3314a492747124166ccb7cf4019e) sys/kern/kern_linker.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=d18326a7cf14804086550c7463be9721e8d28b64 commit d18326a7cf14804086550c7463be9721e8d28b64 Author: Zhenlei Huang <zlei@FreeBSD.org> AuthorDate: 2023-11-07 04:45:25 +0000 Commit: Zhenlei Huang <zlei@FreeBSD.org> CommitDate: 2024-01-15 10:30:02 +0000 kern linker: Do not retry loading modules on EEXIST LINKER_LOAD_FILE() calls linker_load_dependencies() which will return EEXIST in case the module to be loaded has already been compiled into the kernel. Since the format of the module is now recognized then there is no need to retry loading with a different linker, otherwise the userland will get misleading error number ENOEXEC. PR: 274936 Reviewed by: dfr MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D42474 (cherry picked from commit ecf710f0e04e3314a492747124166ccb7cf4019e) (cherry picked from commit e7fd435d3d4e888d9894d8c212c29ae6e2768f74) sys/kern/kern_linker.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
A commit in branch stable/12 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=445eb90240ecbd095d8cf865af6773022e8dd750 commit 445eb90240ecbd095d8cf865af6773022e8dd750 Author: Zhenlei Huang <zlei@FreeBSD.org> AuthorDate: 2023-11-07 04:45:25 +0000 Commit: Zhenlei Huang <zlei@FreeBSD.org> CommitDate: 2024-01-15 10:31:01 +0000 kern linker: Do not retry loading modules on EEXIST LINKER_LOAD_FILE() calls linker_load_dependencies() which will return EEXIST in case the module to be loaded has already been compiled into the kernel. Since the format of the module is now recognized then there is no need to retry loading with a different linker, otherwise the userland will get misleading error number ENOEXEC. PR: 274936 Reviewed by: dfr MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D42474 (cherry picked from commit ecf710f0e04e3314a492747124166ccb7cf4019e) (cherry picked from commit e7fd435d3d4e888d9894d8c212c29ae6e2768f74) (cherry picked from commit d18326a7cf14804086550c7463be9721e8d28b64) sys/kern/kern_linker.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Fixed in stable branches. (In reply to Mark Linimon from comment #5) I planned to MFC to stable/12, at that time FreeBSD 12 is not out of support.