diff mbox series

ARM: Link with '-z norelro'

Message ID 20201110015632.2509254-1-natechancellor@gmail.com (mailing list archive)
State New, archived
Headers show
Series ARM: Link with '-z norelro' | expand

Commit Message

Nathan Chancellor Nov. 10, 2020, 1:56 a.m. UTC
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: https://github.com/ClangBuiltLinux/linux/issues/1189
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
 arch/arm/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


base-commit: a0796429c6abecf8afaeb65b1db286af1fb579d1

Comments

Nick Desaulniers Nov. 10, 2020, 2:05 a.m. UTC | #1
On Mon, Nov 9, 2020 at 5:56 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> 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: https://github.com/ClangBuiltLinux/linux/issues/1189
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>

Thanks for the patch!
See also: https://lore.kernel.org/linux-arm-kernel/20201016175339.2429280-1-ndesaulniers@google.com/
where we just did the same thing for aarch64.

> ---
>  arch/arm/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm/Makefile b/arch/arm/Makefile
> index 4d76eab2b22d..3c0a64cefe52 100644
> --- a/arch/arm/Makefile
> +++ b/arch/arm/Makefile
> @@ -10,7 +10,7 @@
>  #
>  # Copyright (C) 1995-2001 by Russell King
>
> -LDFLAGS_vmlinux        := --no-undefined -X --pic-veneer
> +LDFLAGS_vmlinux        := --no-undefined -X --pic-veneer -z norelro
>  ifeq ($(CONFIG_CPU_ENDIAN_BE8),y)
>  LDFLAGS_vmlinux        += --be8
>  KBUILD_LDFLAGS_MODULE  += --be8
>
> base-commit: a0796429c6abecf8afaeb65b1db286af1fb579d1
> --
> 2.29.2
Nick Desaulniers Nov. 10, 2020, 6:49 p.m. UTC | #2
On Mon, Nov 9, 2020 at 6:05 PM Nick Desaulniers <ndesaulniers@google.com> wrote:
>
> On Mon, Nov 9, 2020 at 5:56 PM Nathan Chancellor
> <natechancellor@gmail.com> wrote:
> >
> > 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: https://github.com/ClangBuiltLinux/linux/issues/1189
> > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
>
> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> Tested-by: Nick Desaulniers <ndesaulniers@google.com>
>
> Thanks for the patch!
> See also: https://lore.kernel.org/linux-arm-kernel/20201016175339.2429280-1-ndesaulniers@google.com/
> where we just did the same thing for aarch64.

I was thinking more about this last night.  If we're going to be
playing whack-a-mole for each architecture with this, would it be
worthwhile for us to raise this up to the top level Makefile?
Nathan Chancellor Nov. 12, 2020, 2:52 a.m. UTC | #3
On Tue, Nov 10, 2020 at 10:49:32AM -0800, Nick Desaulniers wrote:
> On Mon, Nov 9, 2020 at 6:05 PM Nick Desaulniers <ndesaulniers@google.com> wrote:
> >
> > On Mon, Nov 9, 2020 at 5:56 PM Nathan Chancellor
> > <natechancellor@gmail.com> wrote:
> > >
> > > 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: https://github.com/ClangBuiltLinux/linux/issues/1189
> > > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> >
> > Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> > Tested-by: Nick Desaulniers <ndesaulniers@google.com>
> >
> > Thanks for the patch!
> > See also: https://lore.kernel.org/linux-arm-kernel/20201016175339.2429280-1-ndesaulniers@google.com/
> > where we just did the same thing for aarch64.
> 
> I was thinking more about this last night.  If we're going to be
> playing whack-a-mole for each architecture with this, would it be
> worthwhile for us to raise this up to the top level Makefile?

Sure, I can send a patch along tomorrow that adds '-z norelro' to
LDFLAGS_vmlinux in the top level Makefile.

Cheers,
Nathan
Nick Desaulniers Dec. 2, 2020, 11:05 p.m. UTC | #4
Does this need to get submitted to
https://www.armlinux.org.uk/developer/patches/section.php?section=0
since `-z norelro` will produce warnings in ld.bfd for architectures
that don't support that (the results of the thread on adding it
globally)?

On Wed, Nov 11, 2020 at 6:52 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> On Tue, Nov 10, 2020 at 10:49:32AM -0800, Nick Desaulniers wrote:
> > On Mon, Nov 9, 2020 at 6:05 PM Nick Desaulniers <ndesaulniers@google.com> wrote:
> > >
> > > On Mon, Nov 9, 2020 at 5:56 PM Nathan Chancellor
> > > <natechancellor@gmail.com> wrote:
> > > >
> > > > 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: https://github.com/ClangBuiltLinux/linux/issues/1189
> > > > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> > >
> > > Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> > > Tested-by: Nick Desaulniers <ndesaulniers@google.com>
> > >
> > > Thanks for the patch!
> > > See also: https://lore.kernel.org/linux-arm-kernel/20201016175339.2429280-1-ndesaulniers@google.com/
> > > where we just did the same thing for aarch64.
> >
> > I was thinking more about this last night.  If we're going to be
> > playing whack-a-mole for each architecture with this, would it be
> > worthwhile for us to raise this up to the top level Makefile?
>
> Sure, I can send a patch along tomorrow that adds '-z norelro' to
> LDFLAGS_vmlinux in the top level Makefile.
>
> Cheers,
> Nathan
diff mbox series

Patch

diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 4d76eab2b22d..3c0a64cefe52 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -10,7 +10,7 @@ 
 #
 # Copyright (C) 1995-2001 by Russell King
 
-LDFLAGS_vmlinux	:= --no-undefined -X --pic-veneer
+LDFLAGS_vmlinux	:= --no-undefined -X --pic-veneer -z norelro
 ifeq ($(CONFIG_CPU_ENDIAN_BE8),y)
 LDFLAGS_vmlinux	+= --be8
 KBUILD_LDFLAGS_MODULE	+= --be8