linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [RFT PATCH] arm64: add support for building the KASLR kernel with LLVM lld
@ 2018-12-01 13:57 Ard Biesheuvel
  2018-12-01 23:11 ` Nick Desaulniers
  2018-12-03 16:58 ` Will Deacon
  0 siblings, 2 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2018-12-01 13:57 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: catalin.marinas, Peter Smith, Nick Desaulniers, will.deacon,
	Ard Biesheuvel

Work around some differences in the behavior of ld.lld as compared
to lb.bfd:
- pass the -z notext and -z norelro options to convince the linker to
  permit text relocations, and relro sections that are non-adjacent
  (both of which are irrelevant for bare metal executables such as the
  kernel)
- move the definition of some __efistub_ decorated section markers to
  the linker script, which permits us to assign them as relative
  quantities (since using an intermediate assignment loses the section
  relative property when using ld.lld)
- handle .eh_frame and .gnu.hash sections to avoid them from being
  emitted between .head.text and .text, screwing up the section layout.

Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Peter Smith <peter.smith@linaro.org>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---

With this patch and [0] applied on top of today's arm64/for-next/core [1],
I can create a working KASLR kernel using ld.lld (using LLD 6 from
Debian Buster)

[0] https://marc.info/?l=linux-arm-kernel&m=154366528003912
[1] https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/log/?h=for-next/core

 arch/arm64/Makefile             |  2 +-
 arch/arm64/kernel/image.h       |  5 -----
 arch/arm64/kernel/vmlinux.lds.S | 10 ++++++++++
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 7221494bcf60..8978f60779c4 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -18,7 +18,7 @@ ifeq ($(CONFIG_RELOCATABLE), y)
 # Pass --no-apply-dynamic-relocs to restore pre-binutils-2.27 behaviour
 # for relative relocs, since this leads to better Image compression
 # with the relocation offsets always being zero.
-LDFLAGS_vmlinux		+= -shared -Bsymbolic \
+LDFLAGS_vmlinux		+= -shared -Bsymbolic -z notext -z norelro \
 			$(call ld-option, --no-apply-dynamic-relocs)
 endif
 
diff --git a/arch/arm64/kernel/image.h b/arch/arm64/kernel/image.h
index 8da289dc843a..628c2fbf8939 100644
--- a/arch/arm64/kernel/image.h
+++ b/arch/arm64/kernel/image.h
@@ -73,8 +73,6 @@
 
 #ifdef CONFIG_EFI
 
-__efistub_stext_offset = stext - _text;
-
 /*
  * The EFI stub has its own symbol namespace prefixed by __efistub_, to
  * isolate it from the kernel proper. The following symbols are legally
@@ -102,9 +100,6 @@ __efistub___memmove		= __pi_memmove;
 __efistub___memset		= __pi_memset;
 #endif
 
-__efistub__text			= _text;
-__efistub__end			= _end;
-__efistub__edata		= _edata;
 __efistub_screen_info		= screen_info;
 
 #endif
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index 9ba4016090b1..cf3ad76f339f 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -98,12 +98,15 @@ SECTIONS
 		EXIT_CALL
 		*(.discard)
 		*(.discard.*)
+		*(.eh_frame)
 	}
 
 	. = KIMAGE_VADDR + TEXT_OFFSET;
 
 	.head.text : {
 		_text = .;
+		PROVIDE(__efistub__text = .);
+
 		HEAD_TEXT
 	}
 	.text : {			/* Real text segment		*/
@@ -206,6 +209,9 @@ SECTIONS
 	.hash : {
 		*(.hash)
 	}
+	.gnu.hash : {
+		*(.gnu.hash)
+	}
 	__rela_offset	= ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR);
 	__rela_size	= SIZEOF(.rela.dyn);
 #endif
@@ -239,6 +245,7 @@ SECTIONS
 	PECOFF_EDATA_PADDING
 	__pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin);
 	_edata = .;
+	PROVIDE(__efistub__edata = .);
 
 	BSS_SECTION(0, 0, 0)
 
@@ -249,12 +256,15 @@ SECTIONS
 
 	__pecoff_data_size = ABSOLUTE(. - __initdata_begin);
 	_end = .;
+	PROVIDE(__efistub__end = .);
 
 	STABS_DEBUG
 
 	HEAD_SYMBOLS
 }
 
+PROVIDE(__efistub_stext_offset = stext - _text);
+
 #ifdef CONFIG_RELOCATABLE
 VERSION {
 	/* mark all symbols as local so they are not listed in .dynsym */
-- 
2.19.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-12-03 18:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-01 13:57 [RFT PATCH] arm64: add support for building the KASLR kernel with LLVM lld Ard Biesheuvel
2018-12-01 23:11 ` Nick Desaulniers
2018-12-03 16:58 ` Will Deacon
2018-12-03 18:33   ` Nick Desaulniers
2018-12-03 18:54     ` Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).