-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lld discards sections that start with ".gnu.linkonce." preventing kernel modules from being loaded #329
Comments
Fixed: https://reviews.llvm.org/rL352302 Need to request it gets cherry picked into the lld-8 release. |
Redirecting to URL 'https://llvm.org/svn/llvm-project/lld/trunk': ------------------------------------------------------------------------ r352302 | nickdesaulniers | 2019-01-27 03:54:23 +0100 (Sun, 27 Jan 2019) | 33 lines lld: elf: discard more specific .gnu.linkonce section Summary: lld discards .gnu.linonce.* sections work around a bug in glibc. https://sourceware.org/bugzilla/show_bug.cgi?id=20543 Unfortunately, the Linux kernel uses a section named .gnu.linkonce.this_module to store infomation about kernel modules. The kernel reads data from this section when loading kernel modules, and errors if it fails to find this section. The current behavior of lld discards this section when kernel modules are linked, so kernel modules linked with lld are unloadable by the linux kernel. The Linux kernel should use a comdat section instead of .gnu.linkonce. The minimum version of binutils supported by the kernel supports comdat sections. The kernel is also not relying on the old linkonce behavior; it seems to have chosen a name that contains a deprecated GNU feature. Changing the section name now in the kernel would require all kernel modules to be recompiled to make use of the new section name. Instead, rather than discarding .gnu.linkonce.*, let's discard the more specific section name to continue working around the glibc issue while supporting linking Linux kernel modules. Link: ClangBuiltLinux/linux#329 Reviewers: pcc, espindola Reviewed By: pcc Subscribers: nathanchance, emaste, arichardson, void, srhines Differential Revision: https://reviews.llvm.org/D57294 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/lld/branches/release_80@352355 91177308-0d34-0410-b5e6-96231b3b80d8
Redirecting to URL 'https://llvm.org/svn/llvm-project/lld/trunk': ------------------------------------------------------------------------ r352302 | nickdesaulniers | 2019-01-27 03:54:23 +0100 (Sun, 27 Jan 2019) | 33 lines lld: elf: discard more specific .gnu.linkonce section Summary: lld discards .gnu.linonce.* sections work around a bug in glibc. https://sourceware.org/bugzilla/show_bug.cgi?id=20543 Unfortunately, the Linux kernel uses a section named .gnu.linkonce.this_module to store infomation about kernel modules. The kernel reads data from this section when loading kernel modules, and errors if it fails to find this section. The current behavior of lld discards this section when kernel modules are linked, so kernel modules linked with lld are unloadable by the linux kernel. The Linux kernel should use a comdat section instead of .gnu.linkonce. The minimum version of binutils supported by the kernel supports comdat sections. The kernel is also not relying on the old linkonce behavior; it seems to have chosen a name that contains a deprecated GNU feature. Changing the section name now in the kernel would require all kernel modules to be recompiled to make use of the new section name. Instead, rather than discarding .gnu.linkonce.*, let's discard the more specific section name to continue working around the glibc issue while supporting linking Linux kernel modules. Link: ClangBuiltLinux/linux#329 Reviewers: pcc, espindola Reviewed By: pcc Subscribers: nathanchance, emaste, arichardson, void, srhines Differential Revision: https://reviews.llvm.org/D57294 ------------------------------------------------------------------------ llvm-svn: 352355
Summary: lld discards .gnu.linonce.* sections work around a bug in glibc. https://sourceware.org/bugzilla/show_bug.cgi?id=20543 Unfortunately, the Linux kernel uses a section named .gnu.linkonce.this_module to store infomation about kernel modules. The kernel reads data from this section when loading kernel modules, and errors if it fails to find this section. The current behavior of lld discards this section when kernel modules are linked, so kernel modules linked with lld are unloadable by the linux kernel. The Linux kernel should use a comdat section instead of .gnu.linkonce. The minimum version of binutils supported by the kernel supports comdat sections. The kernel is also not relying on the old linkonce behavior; it seems to have chosen a name that contains a deprecated GNU feature. Changing the section name now in the kernel would require all kernel modules to be recompiled to make use of the new section name. Instead, rather than discarding .gnu.linkonce.*, let's discard the more specific section name to continue working around the glibc issue while supporting linking Linux kernel modules. Link: ClangBuiltLinux/linux#329 Reviewers: pcc, espindola Reviewed By: pcc Subscribers: nathanchance, emaste, arichardson, void, srhines Differential Revision: https://reviews.llvm.org/D57294 llvm-svn: 352302
Have we brought this up with the kernel maintainers? We can fix the module section name issue with something like this:
I happen to share an office with the author of the module loader and they said: this is the reason the module loader is in the kernel, so we can make arbitrary changes and not worry about an external tool depending on them. You're right that it was just an arbitrary string, however it does follow the semantics of linkonce (each module needs one of these descriptions, but only one of them). I did some more digging and I wasn't sure where you read that the linkonce section was deprecated? Secondly, a grep for .gnu.linkonce shows that most arches use this in their vdso linker scripts, so the vdso might have been broken with clang in addition to modules.
|
Most of that wording is from pcc, who does a lot of work on LLD. I start an email thread with all of us. |
Oh! Thank you for pointing this out. How can you check from userspace that this exists correctly? Doesn't it show up under /proc//maps IIRC? |
Fixed in lld-9, but the patch was cherry picked to the lld-8 release branch (so will be available in lld-8). |
Redirecting to URL 'https://llvm.org/svn/llvm-project/lld/trunk': ------------------------------------------------------------------------ r352302 | nickdesaulniers | 2019-01-27 03:54:23 +0100 (Sun, 27 Jan 2019) | 33 lines lld: elf: discard more specific .gnu.linkonce section Summary: lld discards .gnu.linonce.* sections work around a bug in glibc. https://sourceware.org/bugzilla/show_bug.cgi?id=20543 Unfortunately, the Linux kernel uses a section named .gnu.linkonce.this_module to store infomation about kernel modules. The kernel reads data from this section when loading kernel modules, and errors if it fails to find this section. The current behavior of lld discards this section when kernel modules are linked, so kernel modules linked with lld are unloadable by the linux kernel. The Linux kernel should use a comdat section instead of .gnu.linkonce. The minimum version of binutils supported by the kernel supports comdat sections. The kernel is also not relying on the old linkonce behavior; it seems to have chosen a name that contains a deprecated GNU feature. Changing the section name now in the kernel would require all kernel modules to be recompiled to make use of the new section name. Instead, rather than discarding .gnu.linkonce.*, let's discard the more specific section name to continue working around the glibc issue while supporting linking Linux kernel modules. Link: ClangBuiltLinux/linux#329 Reviewers: pcc, espindola Reviewed By: pcc Subscribers: nathanchance, emaste, arichardson, void, srhines Differential Revision: https://reviews.llvm.org/D57294 ------------------------------------------------------------------------ llvm-svn: 352355
Filing a copy of this internal bug I stumbled upon yesterday at work, so that it's visible for others looking to use LLD:
Hmmm...looks like there's a problem loading kernel modules.
I'll probably need to dig into how the kernel load modules to see what's going wrong.
kernel/module.c:
__this_module is a D (public data) symbol with bfd but U (undefined reference) with lld.
.gnu.linkonce.this_module is listed as a section with readelf with bfd, but is missing with lld.
Now to see if lld is accidentally or intentionally omitting this data/symbol/section, or if the linker script is malformed.
https://reviews.llvm.org/D28430 looks like it might be problematic. Looks like it purposely discards any section name that starts with ".gnu.linkonce.". Seems like that code is still in lld.
May I present, my most significant contribution to mankind to date:
https://sourceware.org/bugzilla/show_bug.cgi?id=20543
Will post patch to phabricator upstream Monday, assuming I can figure out arcanist+the new github monorepo (and remember my svn password, if those are still in use).
The text was updated successfully, but these errors were encountered: