From: Ard Biesheuvel <ardb@xxxxxxxxxx> In order to be able to use the ELF vmlinux image as the [zboot compressed] boot image, populate the program headers explicitly to describe text+rodata+inittext as R-X and initdata+data+bss as RW-. Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx> --- arch/arm64/kernel/vmlinux.lds.S | 33 +++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index f84c71f04d9e..33d9c683e434 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -59,6 +59,7 @@ #define RO_EXCEPTION_TABLE_ALIGN 4 #define RUNTIME_DISCARD_EXIT +#define LOAD_OFFSET KIMAGE_VADDR #include <asm-generic/vmlinux.lds.h> #include <asm/cache.h> @@ -70,7 +71,9 @@ #include "image.h" OUTPUT_ARCH(aarch64) -ENTRY(_text) +ENTRY(elf_entry) + +elf_entry = ABSOLUTE(primary_entry - KIMAGE_VADDR); jiffies = jiffies_64; @@ -150,6 +153,11 @@ PECOFF_FILE_ALIGNMENT = 0x200; #define PECOFF_EDATA_PADDING #endif +PHDRS { + text PT_LOAD FLAGS(5); /* R_X */ + data PT_LOAD FLAGS(6); /* RW_ */ +} + SECTIONS { /* @@ -166,10 +174,10 @@ SECTIONS . = KIMAGE_VADDR; - .head.text : { + .head.text : AT (0x0) { _text = .; HEAD_TEXT - } + } :text .text : ALIGN(SEGMENT_ALIGN) { /* Real text segment */ _stext = .; /* Text and read-only data */ IRQENTRY_TEXT @@ -248,10 +256,6 @@ SECTIONS __inittext_end = .; __initdata_begin = .; - init_idmap_pg_dir = .; - . += INIT_IDMAP_DIR_SIZE; - init_idmap_pg_end = .; - .init.data : { INIT_DATA INIT_SETUP(16) @@ -259,13 +263,18 @@ SECTIONS CON_INITCALL INIT_RAM_FS *(.init.altinstructions .init.bss) /* from the EFI stub */ - } + } :data .exit.data : { EXIT_DATA } RUNTIME_CONST_VARIABLES + . = ALIGN(PAGE_SIZE); + init_idmap_pg_dir = .; + . += INIT_IDMAP_DIR_SIZE; + init_idmap_pg_end = .; + PERCPU_SECTION(L1_CACHE_BYTES) HYPERVISOR_PERCPU_SECTION @@ -325,10 +334,12 @@ SECTIONS init_pg_end = .; /* end of zero-init region */ - . += SZ_4K; /* stack for the early C runtime */ - early_init_stack = .; + .early_init_stack : { + . += SZ_4K; /* stack for the early C runtime */ + early_init_stack = .; - . = ALIGN(SEGMENT_ALIGN); + . = ALIGN(SEGMENT_ALIGN); + } __pecoff_data_size = ABSOLUTE(. - __initdata_begin); _end = .; -- 2.47.1.613.gc27f4b7a9f-goog