tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: How to build a custom module under NetBSD--9.x and newer?



On Mon, 30 Jan 2023, Brian Buhrow wrote:

[...]  but when I try to perform a modload on the
final .kmod file, I get the following output:

DEBUG: module: Loading module from /stand/amd64/9.99.77/modules/zaptel/zaptel.kmod
DEBUG: module: Loading plist from /stand/amd64/9.99.77/modules/zaptel/zaptel.plist
DEBUG: module: plist load returned error 2 for `/stand/amd64/9.99.77/modules/zaptel/zaptel.kmod'
WARNING: module error: `link_set_modules' section wrong size (got 16, wanted 8)
WARNING: module error: cannot fetch info for `zaptel', error 8


Yeah, I chased this down some time back: I wanted to load the DRMKMS
modules on the command-line like you can with Linux/FreeBSD, but,
coudn't because of this error.

What's happening here is that the .kmod file ends up with a
`link_set_modules' of size 16 instead of 8 because the module is
compiled from sources which have more than 1
	MODULE(MODULE_CLASS_FOO, "name", "deps")
defined in them.

Only 3 .kmod files in /stand have this double-definition issue:

```
$ for f in $(find /stand/amd64/10.99.2/ -name *.kmod);
  do readelf -Wa $f | grep 'link_set_modules .*000010 ' && echo $f;
  done
  [11] link_set_modules  PROGBITS        0000000000000000 00db20 000010 00   A  0   0  8
/stand/amd64/10.99.2/modules/coda5/coda5.kmod
  [12] link_set_modules  PROGBITS        0000000000000988 04fc00 000010 00   A  0   0  8
/stand/amd64/10.99.2/modules/drmkms/drmkms.kmod
  [ 9] link_set_modules  PROGBITS        0000000000000000 003f20 000010 00   A  0   0  8
/stand/amd64/10.99.2/modules/drmkms_pci/drmkms_pci.kmod
$
```

For coda5.kmod:
```
$ fgrep -r 'MODULE(' /usr/src/sys/coda/
/usr/src/sys/coda/coda_psdev.c:MODULE(MODULE_CLASS_DRIVER, vcoda, NULL);
/usr/src/sys/coda/coda_vfsops.c:MODULE(MODULE_CLASS_VFS, coda, "vcoda");
$ ident /stand/amd64/10.99.2/modules/coda5/coda5.kmod
/stand/amd64/10.99.2/modules/coda5/coda5.kmod:
     $NetBSD: coda_namecache.c,v 1.28 2022/05/20 19:34:22 andvar Exp $
     $NetBSD: coda_psdev.c,v 1.62 2022/05/03 20:52:31 andvar Exp $
     $NetBSD: coda_subr.c,v 1.32 2020/04/13 19:23:17 ad Exp $
     $NetBSD: coda_venus.c,v 1.30 2013/10/17 20:56:02 christos Exp $
     $NetBSD: coda_vfsops.c,v 1.90 2022/03/28 12:37:46 riastradh Exp $
     $NetBSD: coda_vnops.c,v 1.118 2022/03/27 16:24:58 christos Exp $
$
```

For drmkms.kmod the 2 MODULE(...) definitions are:
```
$ fgrep -r 'MODULE(' /usr/src/sys/external/bsd/drm2/ | tee xxx.txt
/usr/src/sys/external/bsd/drm2/amdgpu/amdgpu_module.c:MODULE(MODULE_CLASS_DRIVER, amdgpu, "drmkms,drmkms_pci,drmkms_sched,drmkms_ttm"); /* XXX drmkms_i2c */
/usr/src/sys/external/bsd/drm2/dist/drm/drm_agpsupport.c:MODULE(MODULE_CLASS_MISC, drmkms_agp, "drmkms"); /* XXX agp */
/usr/src/sys/external/bsd/drm2/dist/drm/radeon/r600d.h:#       define AUDIO_DTO_MODULE(x)        (((x) & 0xffff) << 16)
/usr/src/sys/external/bsd/drm2/dist/drm/scheduler/sched_fence.c:MODULE(MODULE_CLASS_MISC, drmkms_sched, "drmkms,drmkms_linux");
/usr/src/sys/external/bsd/drm2/drm/drm_module.c:MODULE(MODULE_CLASS_DRIVER, drmkms, "drmkms_linux,sysmon_power");
/usr/src/sys/external/bsd/drm2/i915drm/i915_module.c:MODULE(MODULE_CLASS_DRIVER, i915drmkms, "acpivga,drmkms,drmkms_pci"); /* XXX drmkms_i2c */
/usr/src/sys/external/bsd/drm2/linux/linux_module.c:MODULE(MODULE_CLASS_MISC, drmkms_linux, "i2cexec");
/usr/src/sys/external/bsd/drm2/nouveau/nouveau_module.c:MODULE(MODULE_CLASS_DRIVER, nouveau, "drmkms,drmkms_ttm"); /* XXX drmkms_i2c */
/usr/src/sys/external/bsd/drm2/nouveau/nouveau_pci.c:MODULE(MODULE_CLASS_DRIVER, nouveau_pci, "nouveau,drmkms_pci");
/usr/src/sys/external/bsd/drm2/pci/drm_pci_module.c:MODULE(MODULE_CLASS_MISC, drmkms_pci, "drmkms,pci");
/usr/src/sys/external/bsd/drm2/radeon/radeon_module.c:MODULE(MODULE_CLASS_DRIVER, radeon, "drmkms,drmkms_pci,drmkms_ttm"); /* XXX drmkms_i2c */
/usr/src/sys/external/bsd/drm2/ttm/ttm_module.c:MODULE(MODULE_CLASS_DRIVER, drmkms_ttm, "drmkms");
/usr/src/sys/external/bsd/drm2/via/via_module.c:MODULE(MODULE_CLASS_DRIVER, viadrmums, "drmkms,drmkms_pci");
/usr/src/sys/external/bsd/drm2/vmwgfx/vmwgfx_module.c:MODULE(MODULE_CLASS_DRIVER, vmwgfx, "drmkms,drmkms_pci,drmkms_ttm"); /* XXX drmkms_i2c */
$ cut -d: -f1 xxx.txt | while read line; do echo ${line##*/}; done > drm.txt
$ ident /stand/amd64/10.99.2/modules/drmkms/drmkms.kmod | fgrep -f drm.txt
     $NetBSD: drm_module.c,v 1.31 2022/07/19 22:24:47 riastradh Exp $
     $NetBSD: sched_fence.c,v 1.7 2022/07/28 10:44:46 riastradh Exp $
$
```

For drmkms_pci.kmod, the 2 MODULE(...) definitions are in:
```
$ ident /stand/amd64/10.99.2/modules/drmkms_pci/drmkms_pci.kmod | fgrep -f drm.txt
     $NetBSD: drm_agpsupport.c,v 1.13 2022/07/19 22:24:33 riastradh Exp $
     $NetBSD: drm_pci_module.c,v 1.7 2018/08/28 03:41:39 riastradh Exp $
$
```

You might have a similar situation with two MODULE(...) in the sources
comprising your module.

Dunno how to fix this though...

-RVP


Home | Main Index | Thread Index | Old Index