Bug 250897 - linux_common fails to load as a module after r367395: link_elf_obj: symbol sdt_provider_linuxulator undefined
Summary: linux_common fails to load as a module after r367395: link_elf_obj: symbol sd...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Conrad Meyer
URL: https://reviews.freebsd.org/D27124
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-06 06:42 UTC by Oleg Sidorkin
Modified: 2021-06-10 09:31 UTC (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oleg Sidorkin 2020-11-06 06:42:37 UTC
After r367395 linux_common.ko uses linux_dummy.c that uses
LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE);

However 
LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE);
is compiled in linux_misc.c, that build with linux64.ko.
But linux64.ko depends on linux_misc, so it cannot be loaded before linux_common.ko

dmesg log:
link_elf_obj: symbol sdt_provider_linuxulator undefined                                                                              linker_load_file: /boot/kernel/linux_common.ko - unsupported file type                                                               KLD linux.ko: depends on linux_common - not available or version mismatch                                                            linker_load_file: /boot/kernel/linux.ko - unsupported file type                                                                      link_elf_obj: symbol sdt_provider_linuxulator undefined                                                                              linker_load_file: /boot/kernel/linux_common.ko - unsupported file type                                                               KLD linux64.ko: depends on linux_common - not available or version mismatch                                                          linker_load_file: /boot/kernel/linux64.ko - unsupported file type
Comment 1 Oleg Sidorkin 2020-11-06 07:11:48 UTC
(In reply to Oleg Sidorkin from comment #0)
Correction (failed to read before posting, sorry):

linux_common.ko uses linux_dummy.c uses
LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE);

However 
LIN_SDT_PROVIDER_DEFINE(LINUX_DTRACE);
is compiled in linux_misc.c, that build with linux64.ko.

But linux64.ko depends on linux_common.ko, so it cannot be loaded before linux_common.ko
Comment 2 John Kennedy 2020-11-06 19:17:32 UTC
I've tried Conrad Meyer's patch, and it fixes some issues (linux_common loads), but there are still some other issues:

# kldload -v linux
kldload: an error occurred while loading module linux. Please check dmesg(8) for more details.

Looking at /var/log/messages:

kernel: link_elf_obj: symbol linux_vhangup undefined
kernel: linker_load_file: /boot/kernel/linux.ko - unsupported file type
Comment 3 Conrad Meyer freebsd_committer 2020-11-06 19:26:54 UTC
Huh, I do not have issue loading linux.ko with that patch.
Comment 4 Conrad Meyer freebsd_committer 2020-11-06 19:52:11 UTC
Maybe I was testing an older version of the patch.  Please try the new patch at the same phabricator link above.
Comment 5 John Kennedy 2020-11-06 20:02:29 UTC
I've got WITH_PIE=YES and WITH_BIND_NOW=YES set up, and that'll definitely find issues with normal libraries.

It's undefined in linux.ko (+linux.ko.debug, linux.ko.full) and linux32_sysent.o (looking at files in /usr/obj/usr/src/amd64.amd64/sys/GENERIC/modules/usr/src/sys/modules/linux).

I really haven't wrapped my head around the DUMMY() macros.
Comment 6 John Kennedy 2020-11-06 20:04:54 UTC
The version of the patch I was using was quite different...  you'd just moved linux_dummy.c from the Makefile in linux_common to linux64.  I'll try with your new patch.
Comment 7 Conrad Meyer freebsd_committer 2020-11-06 20:05:46 UTC
These src.conf settings shouldn't have any effect on kernel modules.

Are you looking at the earlier patch or the latest version?

In the latest version, it is expected that linux.ko and linux64.ko have undefined references to e.g., linux_vhangup.  The symbol is defined in linux_common.ko, which is required by both.
Comment 8 John Kennedy 2020-11-06 20:19:12 UTC
I'm recompiling with (just) diff2 now (when I grabbed your patch initially, there was just diff1).  Does diff2 supersede diff1, or should I apply them both?
Comment 9 Conrad Meyer freebsd_committer 2020-11-06 20:23:32 UTC
Thanks!  Latest patch in phabricator supersedes.
Comment 10 Oleg Sidorkin 2020-11-06 21:08:30 UTC
Second version of the patch works for me
Comment 11 John Kennedy 2020-11-06 21:20:35 UTC
Works for me, works for Yasuhiro KIMURA (non-list email).

The Nvidia driver depended on linux so it's fixed, and poudriere works again.
Comment 12 Conrad Meyer freebsd_committer 2020-11-06 22:00:39 UTC
Thanks!
Comment 13 commit-hook freebsd_committer 2020-11-06 22:05:21 UTC
A commit references this bug:

Author: cem
Date: Fri Nov  6 22:04:58 UTC 2020
New revision: 367433
URL: https://svnweb.freebsd.org/changeset/base/367433

Log:
  linux(4): Fix loadable modules after r367395

  Move dtrace SDT definitions into linux_common module code.  Also, build
  linux_dummy.c into the linux_common kld -- we don't need separate
  versions of these stubs for 32- and 64-bit emulation.

  Reported by:	several
  PR:		250897
  Discussed with:	emaste, trasz
  Tested by:	John Kennedy, Yasuhiro KIMURA, Oleg Sidorkin
  X-MFC-With:	r367395
  Differential Revision:	https://reviews.freebsd.org/D27124

Changes:
  head/sys/compat/linux/linux_common.c
  head/sys/compat/linux/linux_dummy.c
  head/sys/compat/linux/linux_misc.c
  head/sys/conf/files.i386
Comment 14 commit-hook freebsd_committer 2021-06-10 09:31:44 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=a2760a540fbf38584798a057d43adb659e0bb50e

commit a2760a540fbf38584798a057d43adb659e0bb50e
Author:     Conrad Meyer <cem@FreeBSD.org>
AuthorDate: 2020-11-06 22:04:57 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2021-06-10 09:23:48 +0000

    linux(4): Fix loadable modules after r367395

    Move dtrace SDT definitions into linux_common module code.  Also, build
    linux_dummy.c into the linux_common kld -- we don't need separate
    versions of these stubs for 32- and 64-bit emulation.

    Reported by:    several
    PR:             250897
    Discussed with: emaste, trasz
    Tested by:      John Kennedy, Yasuhiro KIMURA, Oleg Sidorkin
    X-MFC-With:     r367395
    Differential Revision:  https://reviews.freebsd.org/D27124

    (cherry picked from commit 76b2bfeda42bbb686c74d3608dbc9b84b8e22e29)

 sys/compat/linux/linux_common.c | 15 +++++++++++++++
 sys/compat/linux/linux_dummy.c  | 12 +++++-------
 sys/compat/linux/linux_misc.c   | 13 -------------
 sys/conf/files.i386             |  1 +
 4 files changed, 21 insertions(+), 20 deletions(-)