You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Linux kernel cannot be linked with the wrapped lld #242244
0.kind: bugSomething is broken2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md
Since upstream kernel already support built with llvm toolchains(clang, lld, ...), I also expect this will work on NixOS. However, It seems that link the kernel with wrapped lld would fail:
ld.lld: error: section .bsdata file range overlaps with .header
>>> .bsdata range is [0x1092, 0x122B]
>>> .header range is [0x11EF, 0x126B]
ld.lld: error: section .bsdata virtual address range overlaps with .header
>>> .bsdata range is [0x92, 0x22B]
>>> .header range is [0x1EF, 0x26B]
ld.lld: error: section .bsdata load address range overlaps with .header
>>> .bsdata range is [0x92, 0x22B]
>>> .header range is [0x1EF, 0x26B]
make[1]: *** [/nix/store/rrs90d2s51c5wmpj613l88ghvm1mf478-linux-6.4.2-dev/lib/modules/6.4.2/source/arch/x86/boot/Makefile:109: arch/x86/boot/setup.elf] Error 1
make: *** [/nix/store/rrs90d2s51c5wmpj613l88ghvm1mf478-linux-6.4.2-dev/lib/modules/6.4.2/source/arch/x86/Makefile:283: bzImage] Error 2
make: *** Waiting for unfinished jobs....
Background perspective from upstream kernel maintainer for LLVM support:
Once in a while we get issues reported that aren't reproducible for us on our machines; some Linux distros make changes to the implicit default values of their toolchains when configuring the builds of their toolchains. Unless the kernel's build system is explicit in setting these flags, we can get build failures (such as what's reported above) that appear to be specific to one distro's toolchain distribution.
Personally, I'm curious if NixOS makes changes to ld.lld or wraps it in a script that implicitly sets other flags?
It appears that the wrapper sets the dynamic linker and causes the linking to fail.
A workaround I found is to set sharedLibraryLoader to null in bintools like so:
Interesting and good find! I wonder if we set -dynamic-linker /dev/null in upstream Kbuild (Linux kernel build system) if that would work, or if the wrapper will put -dynamic-linker after that (which would take precendence)? Maybe that's the distinction between extraBefore vs extraAfter?
If it's possible in Kbuild, I wouldn't mind a patch that says something to the effect of:
NixOS' distribution of ld.lld wraps it to add -dynamic-linker <path/to/loader/>. When this is set, linking will fail with error messages like:
ld.lld: error: section .bsdata file range overlaps with .header
.bsdata range is [0x1092, 0x122B]
.header range is [0x11EF, 0x126B]
ld.lld: error: section .bsdata virtual address range overlaps with .header
.bsdata range is [0x92, 0x22B]
.header range is [0x1EF, 0x26B]
ld.lld: error: section .bsdata load address range overlaps with .header
.bsdata range is [0x92, 0x22B]
.header range is [0x1EF, 0x26B]
Avoid this by explicitly setting the -dynamic-linker to /dev/null to avoid this.
Note: it's not clear to my why setting the path to the dynamic loader explicitly would result in those error messages.
it has hard coded addresses for sections. lld putting an .interp section at the start would mess up the addresses.
the cause is ld.lld adds .interp in cases ld.bfd doesn't. I think the fix is either add --no-dynamic-linker to kernel LDFLAGS (--dynamic-linker /dev/null won't work btw); or make ld.lld behave the same as ld.bfd (llvm/llvm-project#78873). I don't know which one's the better solution.
Probably, the last thing to check is that all supported versions (according to process.rst) for both toolchains support that flag, then it can be added unconditionally. Otherwise ld-option make macro should be used.
hello, I've submitted a kernel patch to address this problem. since my nix knowledge is limited, i need some help convincing kernel devs that this is the right solution, or if someone from nix thinks there is a better solution, what would be good too.
#344665 should have already included the workaround for this issue by using the unwrapped linker when building with LLVM. I can get the kernel to build without having to unset the dynamic linker; doing so would make the build segfault very early on.. I'm not quite sure why, but I digress.
0.kind: bugSomething is broken2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md
Activity
SaltyKitkat commentedon Jul 8, 2023
Related: ClangBuiltLinux/linux#1877
nickdesaulniers commentedon Jul 10, 2023
Background perspective from upstream kernel maintainer for LLVM support:
Once in a while we get issues reported that aren't reproducible for us on our machines; some Linux distros make changes to the implicit default values of their toolchains when configuring the builds of their toolchains. Unless the kernel's build system is explicit in setting these flags, we can get build failures (such as what's reported above) that appear to be specific to one distro's toolchain distribution.
Personally, I'm curious if NixOS makes changes to ld.lld or wraps it in a script that implicitly sets other flags?
cillynder commentedon Aug 26, 2023
It appears that the wrapper sets the dynamic linker and causes the linking to fail.
A workaround I found is to set
sharedLibraryLoaderto null in bintools like so:I'm not sure what the implications of this are, if any, but my kernel seems to boot and work fine :D
[-]Linux kernel cannot be liinked with the wrapped lld[/-][+]Linux kernel cannot be linked with the wrapped lld[/+]nickdesaulniers commentedon Aug 28, 2023
Interesting and good find! I wonder if we set
-dynamic-linker /dev/nullin upstream Kbuild (Linux kernel build system) if that would work, or if the wrapper will put-dynamic-linkerafter that (which would take precendence)? Maybe that's the distinction betweenextraBeforevsextraAfter?If it's possible in Kbuild, I wouldn't mind a patch that says something to the effect of:
Note: it's not clear to my why setting the path to the dynamic loader explicitly would result in those error messages.
yshui commentedon Jan 21, 2024
@nickdesaulniers
take a look at this kernel linker script:
it has hard coded addresses for sections. lld putting an
.interpsection at the start would mess up the addresses.the cause is
ld.lldadds.interpin casesld.bfddoesn't. I think the fix is either add--no-dynamic-linkerto kernel LDFLAGS (--dynamic-linker /dev/nullwon't work btw); or makeld.lldbehave the same asld.bfd(llvm/llvm-project#78873). I don't know which one's the better solution.nickdesaulniers commentedon Jan 21, 2024
Does nixos wrap the invocation of the kernel's build system (i.e. the invocation of
make)? If so, then maybe it's appropriate for that build config to set amakecommand line var like KLDFLAGS. Oh, kbuild doesn't have KLDFLAGS like it does KCFLAGS according to https://docs.kernel.org/kbuild/kbuild.html. ARGHBased on @MaskRay's input, then a kernel patch adding
--no-dynamic-linkerwhen$(LD) == lldis appropriate.yshui commentedon Jan 22, 2024
@nickdesaulniers can't we add
--no-dynamic-linkerunconditionally?ld.bfdunderstands it too.nickdesaulniers commentedon Jan 22, 2024
Probably, the last thing to check is that all supported versions (according to process.rst) for both toolchains support that flag, then it can be added unconditionally. Otherwise
ld-optionmake macro should be used.yshui commentedon Feb 13, 2024
hello, I've submitted a kernel patch to address this problem. since my nix knowledge is limited, i need some help convincing kernel devs that this is the right solution, or if someone from nix thinks there is a better solution, what would be good too.
that said, this is the mailing list thread: https://lore.kernel.org/llvm/[email protected]/T/#u would appreciate if someone can chime in.
cc: (lld) @dtzWill @Ericson2314 @lovek323 @alyssais @RaitoBezarius @rrbutani @sternenseemann (kernel) @TredwellGit @Ma27 @NeQuissimus @thoughtpolice
cillynder commentedon Mar 14, 2025
#344665 should have already included the workaround for this issue by using the unwrapped linker when building with LLVM. I can get the kernel to build without having to unset the dynamic linker; doing so would make the build segfault very early on.. I'm not quite sure why, but I digress.