Including <sys/linker.h> from userland fails unless you've previously included <sys/types.h> and <sys/param.h>. (<sys/param.h> brings in <sys/types.h>.) <sys/linker.h> should include the headers for the types and macros it references so that it can be independently included. $ freebsd-version -k 13.3-RELEASE $ cc -c -x c - #include <sys/linker.h> ^D In file included from <stdin>:1: /usr/include/sys/linker.h:347:22: error: use of undeclared identifier 'MAXPATHLEN' 347 | char name[MAXPATHLEN]; | ^ /usr/include/sys/linker.h:350:5: error: unknown type name 'caddr_t' 350 | caddr_t address; /* load address */ | ^ /usr/include/sys/linker.h:351:5: error: unknown type name 'size_t' 351 | size_t size; /* size in bytes */ | ^ /usr/include/sys/linker.h:352:26: error: use of undeclared identifier 'MAXPATHLEN' 352 | char pathname[MAXPATHLEN]; | ^ /usr/include/sys/linker.h:358:5: error: unknown type name 'u_long'; did you mean 'long'? 358 | u_long symvalue; | ^ /usr/include/sys/linker.h:359:5: error: unknown type name 'size_t' 359 | size_t symsize; | ^ 6 errors generated.
This is reasonable, but the dependency is at least documented in the kldstat(2) and related man pages. Including just sys/param.h is sufficient.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=f44029e322446469f116bbd26d51ba857083bacb commit f44029e322446469f116bbd26d51ba857083bacb Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2024-10-26 14:05:56 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2024-10-26 14:05:56 +0000 linker: Make linker.h more self-contained struct kld_file_stat embeds a reference to MAXPATHLEN, defined in param.h. PR: 280432 MFC after: 2 weeks lib/libsys/kldfind.2 | 1 - lib/libsys/kldfirstmod.2 | 1 - lib/libsys/kldload.2 | 1 - lib/libsys/kldnext.2 | 1 - lib/libsys/kldstat.2 | 1 - lib/libsys/kldsym.2 | 1 - lib/libsys/kldunload.2 | 1 - sys/sys/linker.h | 2 ++ 8 files changed, 2 insertions(+), 7 deletions(-)
A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=da80e62f965c56d4f3d2b91be2b33960ada46854 commit da80e62f965c56d4f3d2b91be2b33960ada46854 Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2024-10-26 14:05:56 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2024-11-09 01:10:14 +0000 linker: Make linker.h more self-contained struct kld_file_stat embeds a reference to MAXPATHLEN, defined in param.h. PR: 280432 MFC after: 2 weeks (cherry picked from commit f44029e322446469f116bbd26d51ba857083bacb) lib/libc/sys/kldfind.2 | 1 - lib/libc/sys/kldfirstmod.2 | 1 - lib/libc/sys/kldload.2 | 1 - lib/libc/sys/kldnext.2 | 1 - lib/libc/sys/kldstat.2 | 1 - lib/libc/sys/kldsym.2 | 1 - lib/libc/sys/kldunload.2 | 1 - sys/sys/linker.h | 2 ++ 8 files changed, 2 insertions(+), 7 deletions(-)