drm-kmod icon indicating copy to clipboard operation
drm-kmod copied to clipboard

drm-kmod: Export symbols

Open emaste opened this issue 1 year ago • 8 comments

We currently rely on the kernel linker resolving undefined references against local symbols from other kernel modules. Be explicit about the symbols to export, in advance of changing that behaviour.

PR: 207898 Sponsored by: The FreeBSD Foundation

emaste avatar Dec 08 '24 02:12 emaste

Wouldn't this be a pain to keep track of ?

evadot avatar Dec 08 '24 10:12 evadot

It'll be a bit of a pain, but it's not too bad. I generated these largely with a sed expression: sed -E -n 's/^.*EXPORT_SYMBOL[A-Z_]*\((.*)\).*$/EXPORT_SYMS+= \1/p.

We could take the same approach as Linux and use EXPORT_SYMBOL to control this (e.g. output the symbols to a special section similar to linker sets, then process those into the export list for linking).

The alternative is to just set EXPORT_SYMS=YES but it really is a bug that we're linking against local symbols from other modules.

emaste avatar Dec 08 '24 13:12 emaste

Also linuxkpi_video currently has EXPORT_SYMS=YES.

In my tree I've changed it to:

# drivers/video/aperture.c
EXPORT_SYMS+=  __aperture_remove_legacy_vga_devices
EXPORT_SYMS+=  aperture_remove_conflicting_devices
EXPORT_SYMS+=  aperture_remove_conflicting_pci_devices
EXPORT_SYMS+=  devm_aperture_acquire_for_platform_device

# drivers/video/hdmi.c
EXPORT_SYMS+=  hdmi_audio_infoframe_check
EXPORT_SYMS+=  hdmi_audio_infoframe_init
EXPORT_SYMS+=  hdmi_audio_infoframe_pack
EXPORT_SYMS+=  hdmi_audio_infoframe_pack_for_dp
EXPORT_SYMS+=  hdmi_audio_infoframe_pack_only
EXPORT_SYMS+=  hdmi_avi_infoframe_check
EXPORT_SYMS+=  hdmi_avi_infoframe_init
EXPORT_SYMS+=  hdmi_avi_infoframe_pack
EXPORT_SYMS+=  hdmi_avi_infoframe_pack_only
EXPORT_SYMS+=  hdmi_drm_infoframe_check
EXPORT_SYMS+=  hdmi_drm_infoframe_init
EXPORT_SYMS+=  hdmi_drm_infoframe_pack
EXPORT_SYMS+=  hdmi_drm_infoframe_pack_only
EXPORT_SYMS+=  hdmi_drm_infoframe_unpack_only
EXPORT_SYMS+=  hdmi_infoframe_check
EXPORT_SYMS+=  hdmi_infoframe_log
EXPORT_SYMS+=  hdmi_infoframe_pack
EXPORT_SYMS+=  hdmi_infoframe_pack_only
EXPORT_SYMS+=  hdmi_infoframe_unpack
EXPORT_SYMS+=  hdmi_spd_infoframe_check
EXPORT_SYMS+=  hdmi_spd_infoframe_init
EXPORT_SYMS+=  hdmi_spd_infoframe_pack
EXPORT_SYMS+=  hdmi_spd_infoframe_pack_only
EXPORT_SYMS+=  hdmi_vendor_infoframe_check
EXPORT_SYMS+=  hdmi_vendor_infoframe_init
EXPORT_SYMS+=  hdmi_vendor_infoframe_pack
EXPORT_SYMS+=  hdmi_vendor_infoframe_pack_only

emaste avatar Dec 08 '24 14:12 emaste

I would prefer a script in the scripts directory that can generate this and put the result in a submakefile that the main ones include.

evadot avatar Dec 08 '24 15:12 evadot

#338 is a short-term workaround to avoid relying on kernel misbehaviour

emaste avatar Mar 12 '25 16:03 emaste

After applying https://bugs.freebsd.org/bugzilla/attachment.cgi?id=258740&action=diff, I'm still unable to load amdgpu on powerpc64le:

root@talos-powerpc64le:~ # kldload amdgpu
link_elf: symbol drm_helper_connector_dpms undefined
kldload: can't load amdgpu: No such file or directory
root@talos-powerpc64le:~ # kldload drm
link_elf: symbol dma_fence_wait undefined
kldload: can't load drm: No such file or directory
root@talos-powerpc64le:$/boot/modules$ nm dmabuf.ko | grep dma_fence_wait                                                                                                                                      
0000000000009210 T dma_fence_wait
0000000000008380 T dma_fence_wait_any_timeout
0000000000007660 T dma_fence_wait_timeout
root@talos-powerpc64le:$/boot/modules$ nm drm.ko | grep dma_fence_wait    
                 U dma_fence_wait

That is on 6.1.128.1402000_2.

pkubaj avatar Mar 17 '25 10:03 pkubaj

This patch isn't ready yet, please test with #338 instead.

emaste avatar Mar 17 '25 12:03 emaste

That's what I did, the pkg version is 6.1.128.1402000_2, which includes that change. I just posted here, because the discussion is relevant to the issue (symbols not exported).

pkubaj avatar Mar 17 '25 12:03 pkubaj