-
Notifications
You must be signed in to change notification settings - Fork 15
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
ld.lld: error: section: .exit.data is not contiguous with other relro sections #1189
Comments
ppc has a similar problem http://lore.kernel.org/r/CAFP8O3+Mg6B4WnDzAnT43132JTbtKgkK7JFwm8Sqhc1m0CzY1g@mail.gmail.com "[PATCH] powerpc/boot: move the .got section to after the .dynamic section" @gwelymernans RELRO sections need to be contiguous. For arm,
If an input section |
@ardbiesheuvel pointed out on the list that relro isn't used in the kernel, at least for aarch64; not sure if that applies for all other arches as well? |
RELRO is essentially a program header that describes a memory range that may be remapped read-only after the relocations have been applied. We don't use program headers to begin with in Linux, and we don't use PIC code generation or PIE linking for ARM at all, so we prefer text relocations over GOT indirections |
@ardbiesheuvel There is more to that. It is probably true that the kernel does not need PT_GNU_RELRO. I thought about: (1) whether the kernel can pick PT_GNU_RELRO as a hardening feature in the future It is probable that the kernel does not care about the problems, though. |
As I explained, we don't use ELF program headers at all. The vmlinux ELF file is converted to a binary image using objcopy, and the program headers are not even captured there, and we rely strictly on linker emitted symbols that delineate the various segments, in order to decide which part of the image should be mapped with which attributes. Currently, we even have an ASSERT() that .data.rel.ro be empty, and so we currently cannot build with -fpie, we can only link with -pie (and on the AArch64 small code model, that has worked fine so far, although I suggested multiple times now that we should perhaps introduce a special AArch64 code model for Linux) Note that .exit.data is dead code in the core kernel: anything that is builtin cannot be unloaded, and so the code is never used. Therefore we map it in the .init segment, which gets unmapped and freed entirely after boot. So moving this section into a place where it could be covered by a PT_GNU_RELRO program header would force us to retain code that we know we will never need. |
Let's discuss more in #275. I have a list of links, but it might be worthwhile for us to chat more there. In particular, it looks like @MaskRay has already implemented at least one of the ideas there. |
Commit 3bbd3db ("arm64: relocatable: fix inconsistencies in linker script and options") added '-z norelro' to the arm64 Makefile when CONFIG_RELOCATABLE was set to help support ld.lld because ld.lld defaults to '-z relro' but the kernel does not use program headers or adhere to the section layout that is required for RELRO to work. Commit 3b92fa7 ("arm64: link with -z norelro regardless of CONFIG_RELOCATABLE") unconditionally added it to LDFLAGS_vmlinux because an error occurs with CONFIG_KASAN set even when CONFIG_RELOCATABLE is unset. As it turns out, ARM experiences the same error after CONFIG_KASAN was implemented, meaning that '-z norelro' needs to be added to that Makefile as well (multi_v7_defconfig + CONFIG_KASAN=y + LD=ld.lld): $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- LLVM=1 zImage ld.lld: error: section: .exit.data is not contiguous with other relro sections To avoid playing whack-a-mole with different architectures over time, hoist '-z norelro' into the main Makefile. This does not affect ld.bfd because '-z norelro' is the default for it. Link: ClangBuiltLinux#1189 Suggested-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
bumping @nathanchance to submit v1 to Russel's patch tracker. |
Yes, sorry, have not had time to reply to your email. I can submit to Russell's tracker tomorrow or Saturday I think, I was waiting for feedback on whether just doing it in |
Submitted to RMK's patch system: https://www.armlinux.org.uk/developer/patches/viewpatch.php?id=9038/1 |
When linking a multi_v7_defconfig + CONFIG_KASAN=y kernel with LD=ld.lld, the following error occurs: $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- LLVM=1 zImage ld.lld: error: section: .exit.data is not contiguous with other relro sections LLD defaults to '-z relro', which is unneeded for the kernel because program headers are not used nor is there any position independent code generation or linking for ARM. Add '-z norelro' to LDFLAGS_vmlinux to avoid this error. Link: ClangBuiltLinux#1189 Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Tested-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
When linking a multi_v7_defconfig + CONFIG_KASAN=y kernel with LD=ld.lld, the following error occurs: $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- LLVM=1 zImage ld.lld: error: section: .exit.data is not contiguous with other relro sections LLD defaults to '-z relro', which is unneeded for the kernel because program headers are not used nor is there any position independent code generation or linking for ARM. Add '-z norelro' to LDFLAGS_vmlinux to avoid this error. Link: ClangBuiltLinux/linux#1189 Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Tested-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
When linking a multi_v7_defconfig + CONFIG_KASAN=y kernel with LD=ld.lld, the following error occurs: $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- LLVM=1 zImage ld.lld: error: section: .exit.data is not contiguous with other relro sections LLD defaults to '-z relro', which is unneeded for the kernel because program headers are not used nor is there any position independent code generation or linking for ARM. Add '-z norelro' to LDFLAGS_vmlinux to avoid this error. Link: ClangBuiltLinux/linux#1189 Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Tested-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
When linking a multi_v7_defconfig + CONFIG_KASAN=y kernel with LD=ld.lld, the following error occurs: $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- LLVM=1 zImage ld.lld: error: section: .exit.data is not contiguous with other relro sections LLD defaults to '-z relro', which is unneeded for the kernel because program headers are not used nor is there any position independent code generation or linking for ARM. Add '-z norelro' to LDFLAGS_vmlinux to avoid this error. Link: ClangBuiltLinux/linux#1189 Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Tested-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
After the series to enable KASan for ARM was applied,
ld.lld
errors when linking anallyesconfig
kernel:I have reported this upstream: https://lore.kernel.org/linux-arm-kernel/20201030002900.GA2248731@ubuntu-m3-large-x86/
cc @MaskRay
The text was updated successfully, but these errors were encountered: