Bug 280432 - <sys/linker.h> needs <sys/param.h> and <sys/types.h> but does not include them
Summary: <sys/linker.h> needs <sys/param.h> and <sys/types.h> but does not include them
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.3-RELEASE
Hardware: Any Any
: --- Affects Many People
Assignee: Mark Johnston
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-07-24 19:38 UTC by Matt Jacobson
Modified: 2024-10-26 14:40 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Jacobson 2024-07-24 19:38:25 UTC
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.
Comment 1 Mark Johnston freebsd_committer freebsd_triage 2024-07-26 17:33:24 UTC
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.
Comment 2 commit-hook freebsd_committer freebsd_triage 2024-10-26 14:37:10 UTC
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(-)